Freigeben über


Optimizing Applications in Multiuser Environments

If you're writing applications for a multiuser environment, performance is particularly important, because inefficiencies are multiplied. In addition, if multiple users are accessing data, your application must handle issues of concurrency and network access.

To handle these issues, you can:

  • Adjust lock retry interval.
  • Use transaction processing efficiently.

You might also benefit from the suggestions for working with data stored on remote servers. For details, see Optimizing Access to Remote Data.

Adjusting Lock Retry Interval

If your application attempts to lock a record or table and is unsuccessful, you can have Visual FoxPro automatically retry the lock after a small interval. However, each lock attempt results in more network traffic. If network traffic is already heavy, sending repeated lock requests adds a burden to the network, and results in overall slowdown for all users.

To address this situation, you can adjust the interval between lock attempts. By using a larger interval (which results in fewer retries per second), you reduce network traffic and gain performance.

To adjust the lock retry interval

  • Call the SYS(3051) function, passing it the number of milliseconds to wait between each lock attempt.

Using Transaction Processing Efficiently

When using transaction processing, you must design transactions to minimize the impact that they have on other users. While a transaction is open, any locks set during the transaction remain locked until the transaction is committed or rolled back. Even if you issue an explicit UNLOCK command, locks are held until the END TRANSACTION or ROLLBACK command.

Furthermore, appending records to a table requires Visual FoxPro to lock the table header. The header remains locked for the duration of the transaction, preventing other users from also appending records.

To minimize the impact of transactions, design them so that they begin and end as close to the actual data update as possible; the ideal transaction contains only data update statements.

If you are adding transaction processing to data updates made in a form, don't open a transaction, run the form, and then commit the transaction when the form is closed. Instead, put the transaction processing statements in the event code for the Save button (for example):

* Save method from the cmdSave command button
BEGIN TRANSACTION
UPDATE PRODUCTS SET reorder_amt = 0 WHERE discontinued = .T.
END TRANSACTION

See Also

Optimization of ActiveX Controls | Optimizing Access to Remote Data | Optimizing Applications | Optimizing Your System | Optimization of International Applications