Setting the Value of the BUFFERS Attribute

You can control the number of buffers used by the KEYEDIO library in processing an indexed file.

A program can indicate the number of buffers KEYEDIO is to use by setting the value of the BUFFERS attribute of the indexed file. The value of the BUFFERS attribute is used by the library to determine how many buffers to allocate for processing that indexed file.

Impact of Number of Buffers on Processor Time

Increasing the number of buffers used by KEYEDIO reduces the time needed to process an indexed file at the expense of increased usage of save memory. Reducing the number of buffers decreases save memory usage but increases processing time. In general, programs doing random accesses to the indexed file are more sensitive to the number of buffers than programs doing serial accesses.

The effect of changing the number of buffers on the time needed to process a file tends to be proportional to the reciprocal of the number of buffers; that is, reducing the number of buffers lengthens the processing time more than increasing the number of buffers by the same amount decreases the time. For this reason, decisions to decrease the number of buffers below the KEYEDIO default of 10 buffers should be the result of careful consideration and measurement.

Impact of Number of Buffers on Save Memory

Increasing the number of buffers increases the save memory usage of the KEYEDIO library; save memory is equal to the number of buffers multiplied by the actual block size and is explained later in this section. You should take into account the overall performance of the system, as well as the processing time of the specific application, when deciding to increase the number of buffers.

The value specified for the BUFFERS attribute at file creation time is especially important because this value becomes the permanent default number of buffers to be allocated whenever the file is used later. The time needed to create the file is usually not as strongly affected by the number of buffers as later uses of the file are. For this reason, specifying the proper number for the permanent default is generally of greatest importance when specifying the BUFFERS value to use for file creation.

Rules for Determining the Number of Buffers Used

KEYEDIO determines how many buffers to use for processing an indexed file according to the following rules:

  1. First, the value of the BUFFERS attribute specified when the file is created is stored permanently in the file itself. This value is used by the KEYEDIO library both when creating the file and as the default number of buffers to allocate each time the file is subsequently opened.

    If the value of the BUFFERS attribute is not specified at file creation time or the value specified for the BUFFERS attribute is 2 or less, KEYEDIO uses the default value 12 for the number of buffers both for file creation and as the default number of buffers when the file is subsequently opened for use by a single user.

    For files with a BUFFERS value greater than 2, KEYEDIO allocates 10 more buffers than the number of buffers specified in the creating program. For example, if program A sets the attribute BUFFERS of file F to 5, and then opens the file, HEADERBUFFERS is 13, and 15 buffers are allocated.

  2. Second, the value of the BUFFERS attribute specified when an existing indexed file is opened is used to indicate the number of buffers the KEYEDIO library should use in processing that file. KEYEDIO determines the number of buffers to use for an existing file in the following way:

    When the file is not being used by any other programs at the time it is opened, and if the number of buffers specified is 3 or greater, the number of buffers allocated is 2 more than specified by the opening program, or it is the number of buffers allocated when the file was created, whichever is greater.

    For example, if program A has closed file F and program B reopens the file with BUFFERS equal to 15, then 17 buffers are allocated.

When the file is being used by other programs at the time it is opened, either of the following can be true:

  • If the original number of buffers allocated at file creation is more than 2 greater than the number of buffers allocated by the additional opening program, then KEYEDIO allocates 2 additional buffers.

  • If the number of buffers allocated at file creation is more than 2 less than the number of buffers allocated by the additional opening program, then KEYEDIO allocates 4 more buffers than the difference between program-specified buffers and the original creation buffers.

  • In certain languages the number of buffers is a default value determined by the compiler (as described in the following).

    When there are multiple users of an indexed file, the buffers are allocated in a common pool by the KEYEDIO library and are shared by all users.

    For example, if program B has file F open with BUFFERS equal to 15, and program C sets F.BUFFERS to 20 and then opens the file, 9 more buffers (2 + 20 – 13) are allocated for a total of 26.

    If program A sets BUFFERS equal to 7, then HEADERBUFFERS becomes 15 and 17 buffers are allocated while A is running. If program B reopens the file with BUFFERS equal to 15, 17 buffers are allocated. If program C sets F.BUFFERS equal to 20 while B is still running, then 7 more buffers (2 + 20 – 15) are allocated, for a total of 24.

    Some compilers automatically set the value of BUFFERS even when the program has not specified a value for BUFFERS. In particular, the COBOL74 compiler sets BUFFERS to 2 if a value is not specified; the RPG compiler sets BUFFERS to 1 if a value is not specified for an indexed file.

    The compiler-set defaults do not interfere with the default assignment of 10 buffers at file creation time for an indexed file—because the compiler default is 2 or less—or with the assignment of 10 buffers by default when a single access is made to an already existing indexed file. The compiler default has an impact when many programs access an indexed file. Each new program accessing the indexed file increments the number of buffers in use by the compiler default setting.

The maximum value that can be set for the BUFFERS file attribute is 63. The maximum total number of buffers used by the KEYEDIO library is 255. Once this limit is reached, additional buffers are not allocated, regardless of the BUFFERS specifications of later users.

If the BUFFERS attribute of an indexed file is interrogated, the value returned is the value currently established for that file by the program, not the total number of BUFFERS that are actually being used by KEYEDIO at that time.