ptg10805159
782 ADatabase Library Chapter 20
- Writenrecrecords to the database.
- Read thenrecrecords back by key value.
- Perform the following loopnrec× 5 times.
a. Readarandom record.
b. Every 37 times through the loop, delete a random record.
c. Every11 times through the loop, insert a new recordand read the record
back.
d. Every 17 times through the loop, replace a random recordwith a new
record. Every other one of these replacements is a recordwith the same size
data; the alternate is a recordwith a longer data portion. - Delete all the records that this child wrote. Every time a record is deleted, ten
random records arelooked up.
The number of operations performed on the database is counted by thecnt_xxx
variables in theDBstructure, which wereincremented in the functions. The number of
operations differs from one child to the next, since the random-number generator used
to select records is initialized in each child to the child’s process ID.Atypical count of
the operations performed in each child is shown in Figure20.6.
Calls tofcntl
(per operation)
Coarse-grained Fine-grained
locking locking
Operation
Operation
count
(nrec=2,000)
db_store,DB_INSERT, no empty record, appended 28 2,920
db_store,DB_INSERT,empty recordreused 2 4468
db_store,DB_REPLACE,different data length, appended 28405
db_store,DB_REPLACE,equal data length 22416
db_store,recordnot found 22 71
db_fetch,recordfound 2 23 2,873
db_fetch,recordnot found 22 2,966
db_delete,recordfound 2 43 ,388
db_delete,recordnot found 22422
Figure 20.6 Typical count of operations performed by each child
We performed about ten times morefetches than stores or deletions, which is probably
typical of many database applications.
Each child is performing these operations (fetching, storing, and deleting) only with
the records that the child wrote. The concurrency controls arebeing exercised because
all the children areoperating on the same database (albeit different records in the same
database). The total number of records in the database increases in proportion to the
number of children. (With one child,nrecrecords areoriginally written to the database.
With two children,nrec× 2 records areoriginally written, and so on.)
To test the concurrency provided by coarse-grained locking versus fine-grained
locking and to comparethe three types of locking (no locking, advisory locking, and