The information in this article applies to:
SUMMARYThis article contains the complete text of the PERFORM.TXT file distributed with the Standard and Professional Editions of Visual Basic version 3.0 for Windows. MORE INFORMATION
PERFORM.TXT
Version 3.00 (C) Copyright Microsoft Corporation, 1993This document contains performance tuning tips for Microsoft Visual Basic for Windows version 3.0 and Microsoft Access (TM) Relational Database Systems for Windows version 1.1. How to Use This DocumentTo view PERFORM.TXT on screen in Windows Notepad, maximize the Notepad window.To print PERFORM.TXT, open it in Windows Write, Microsoft Word, or another word processor. Then select the entire document and format the text in 10-point Courier before printing. Contents
Part 1: Running Multiple Data Access ApplicationsVisual Basic and Microsoft Access both use the same database engine to perform their database-related operations. When these applications are run at the same time on the same machine, it is important to coordinate use of the database engine, since it is only initialized by the first program accessing a data access operation. Re-initialization does not take place until all programs using the database engine are ended and another started.Proper database initialization is especially important when accessing external databases like dBASE, FoxPro, Paradox, or Btrieve. All of these require special notations in the initialization file. Note that data access applications can take the form of one or more instances of:
To ensure that all applications using the database engine function as intended, you must ensure that all initialization parameters pertaining to external databases are identified in various .INI files under section headings (such as [Installable ISAM], [Paradox Isam], [Btrieve ISAM]) and are copied into each of the .INI files pertaining to each data access application that can potentially be running at the same time. The list below shows where each program looks for its initialization information: Program .INI fileMicrosoft Access MSACCESS.INIAll of these .INI files are located in your Windows directory. During development, your Visual Basic application defaults to VB.INI unless your application uses the SetDataAccessOption statement to indicate a specific .INI file location. Once you create an executable program with Visual Basic, the initialization file will default to <APPNAME>.INI unless you use SetDataAccessOption. If you want to coordinate operations between an instance of a Visual Basic application (or .EXE), you will want to force Visual Basic to indicate the same initialization file that a second instance of your program or an instance of Microsoft Access will use. This way, regardless of which application starts (and initializes) the database engine, both applications will be using the same initialization parameters. Part 2: Manipulating Secured Microsoft Access DatabasesFor Visual Basic to manipulate secured Microsoft Access databases, you must provide Visual Basic with the location of the SYSTEM.MDA file associated with that Microsoft Access database, a valid user name, and password. This can be accomplished in three steps:
Part 3: Tuning [ISAM] Entries in VB.INI or <APPNAME>.INIYou can enhance the database access performance of Visual Basic by:
Setup automatically installs <APPNAME>.INI in your Windows directory. These [ISAM] entries determine the sizes of data page and read-ahead caches in memory, the amount of time data is held in a page cache, and the number of times Visual Basic will retry a lock operation. WARNINGDetermining the best settings for your system configuration or application can be time-consuming and difficult, usually involving much trial and error. In addition, settings that seem optimal for one situation may not be optimal for others. Casual users should not try to edit these entries.Visual Basic automatically includes a PageTimeout entry in the [ISAM] section of the VB.INI or <APPNAME>.INI file. This entry sets the amount of time Visual Basic holds a data page in memory. For additional performance tuning, you can add MaxBufferSize, ReadAheadPages, LockRetry, and CommitLockRetry entries to this section. Visual Basic reads these initialization settings at startup time. They can be changed while Visual Basic is running, but the changes won't take effect until you restart Visual Basic or your application. As with all .INI settings that affect the database engine, these settings are fixed once the engine is initialized just before the first data access operation. PageTimeout Entry (Shared Data Only)The PageTimeout entry sets the amount of time, in tenths of a second, that Visual Basic holds a data page in a memory "page cache" if the database has been opened for shared access. Visual Basic reads data in 2K blocks of records, or "pages."For example, when Visual Basic reads a data page, it places the data in the page cache. If Visual Basic receives another read request for the same data page during the timeout period, it reads the data directly from the page cache rather than from disk. NoteAccess Basic ignores the PageTimeout setting unless your code allows background processing by periodically calling the DoEvents statement or function.PageTimeOut SettingsMaximum: 2147483647 (max Long integer)Minimum: 0 Default: 300 If you remove the PageTimeout entry, Visual Basic uses a default PageTimeout setting of 5. For example: PageTimeout=20 ; This example sets PageTimeout to 2 seconds. MaxBufferSize EntryThe MaxBufferSize entry sets the amount of memory, in kilobytes, reserved for use as a page cache. Visual Basic reads data in 2K pages, placing the data in the page cache. Once the data is placed in the cache, Visual Basic can use it wherever it is needed -- in tables, queries, forms, or reports.When Visual Basic receives a read request, it first checks the data pages in the page cache. If the page isn't in the cache, Visual Basic reads the data page from disk and then places it in the page cache. Visual Basic uses physical memory and if necessary virtual memory to create the cache. All pages stay in the cache until it is full and pages need to be flushed to make room for new reads. MaxBufferSize SettingsMaximum: 4096Minimum: 18 Default: If there is no MaxBufferSize entry in your VB.INI or <APPNAME>.INI file, Visual Basic uses a default setting of 512. NoteBecause Visual Basic reads data in 2-kilobyte pages, it always uses an even MaxBufferSize setting. If you type an odd number, Visual Basic uses a MaxBufferSize setting of one less than the number. For example:MaxBufferSize=4096 ; This example sets MaxBufferSize to 4 MB. ReadAheadPages EntryThe ReadAheadPages entry sets the size, in data pages, of a "read-ahead" cache used by Visual Basic for sequential page reads. A sequential page read occurs when Visual Basic detects that data in a current read request is on a data page adjacent on physical disk to the data page of the previous request. Visual Basic uses the "read-ahead" cache only when it detects that a sequential read is taking place.
ReadAheadPages SettingsMaximum: 31Minimum: 0 Default: If there is no ReadAheadPages entry in your VB.INI or <APPNAME>.IN file, Visual Basic uses a default setting of 8. For example: ReadAheadPages = 16 NoteVisual Basic creates a separate read-ahead cache for each database open on your computer. Each library database has its own read-ahead cache.LockRetry EntryThe LockRetry entry sets the number of times Visual Basic retries a page- locking operation before it reports an error. For example, if a user tries to lock a data page that is already locked by another user, the attempt will fail. Visual Basic will try to lock the page N more times, where N is the LockRetry setting. If the attempt to lock the page still fails on the Nth retry, Visual Basic reports an error.LockRetry SettingsMaximum: 2147483647 (max Long integer)Minimum: 0 Default: If there is no LockRetry entry in your VB.INI or <APPNAME>.INI file, Visual Basic uses a default setting of 20. For example: LockRetry = 6 CommitLockRetry EntryThe CommitLockRetry entry is used with the LockRetry entry to set the number of retries that Visual Basic attempts when a user tries to lock a record on a data page already locked by a transaction. If a user tries to lock a data page that is already locked by a transaction, Visual Basic will try to lock the page N more times, where N is the product of the LockRetry setting and the CommitLockRetry setting. For example, if the LockRetry setting is 5 and the CommitLockRetry is 6, Visual Basic will try to lock the page 30 more times.CommitLockRetry SettingsMaximum: 2147483647 (max Long integer)Minimum: 0 Default: If there is no CommitLockRetry entry in your VB.INI or <APPNAME>.INI file, Visual Basic uses a default setting of 20. For example:
Part 4: Using Transactions to Maximize Data ThroughputIn a multi-user environment, you can further tune the performance of Visual Basic by using transactions for operations that update data. A transaction is a series of operations that must execute as a whole or not at all. You mark the beginning of a transaction with the BeginTrans statement. You use the Rollback or CommitTrans statement to end a transaction.You can usually increase the record updates per second (throughput) of an application by placing operations that update data within an Access Basic transaction. TipBecause Visual Basic locks data pages used in a transaction until the transaction ends, using transactions will prevent access to those data pages while the transaction is pending. If you use transactions, try to find a balance between data throughput and data access.Part 5: Minimizing Keyset Overhead When Working with Large RecordsetsWhen a query selects a large number of records from the database, Visual Basic only fetches the first row of that Dynaset or Snapshot and places the key to re-fetch that row in memory. Once a record is fetched or visited, it becomes a member of the recordset. As you "visit" additional rows of the recordset, the keys are stored in workstation memory (in a temporary table), and in the case of Snapshots, so is the data. If you move back to previously fetched rows, Visual Basic re-fetches the rows using the old key fetched from the temporary key table.
Moving to the end of the Dynaset or Snapshot does at least two things: First, it forces Visual Basic to visit all of the records in your recordset. Hence, all keys will be saved on the workstation. If this is a few hundred rows, this may not take long or take up more space than the workstation can handle. However, for larger recordsets, a MoveLast operation may be far more than the workstation can save. When working with Snapshots, not only are the keys fetched, but the data for all records is also brought into local memory. Generally, you should avoid operations that fetch more rows than your user or workstation can deal with. Operations that must touch each record in a recordset may best be performed with an action query that consumes less system resources. In any case, your performance will not be severely degraded, either as you move forward until you have to swap, or hardly at all if you move backwards in the recordset -- even to the first record. NoteThe Dynaset or Snapshot membership is not set until the record is actually fetched for the first time. Since this can take from seconds to days depending on how fast you fetch the records (moving down through the recordset with MoveNext or with MoveLast), no Dynaset or Snapshot is really a frozen subset of the data at a point in time. The only way to ensure that no changes are made while the recordset is built is to get exclusive access to the table or database before fetching -- which essentially locks out all other users until the recordset (or database) is closed.Part 6: Performance tips for Visual Basic Data AccessThe following tips are suggested for operations involving more than just a few records to increase the overall performance of your system.
Additional query words:
Keywords : kbprg APrgDataAcc vbwin |
Last Reviewed: October 11, 1999 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |