home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume30 / oraperl-v2 / part04 / Row_cache < prev    next >
Encoding:
Text File  |  1992-07-06  |  2.1 KB  |  66 lines

  1.  
  2. Oraperl version 2 supports a multi-row cache for SELECT statements.
  3. The user interface is not changed, except that the user may (but is
  4. not required to) specify the size of the cache in the &ora_open()
  5. call. It is not possible to go back to an entry which has already been
  6. returned, even if it is still in the cache.
  7.  
  8. I timed the caching code using the following Oraperl script:
  9.  
  10.     $lda = &ora_login('ipl', 'name', 'pass') || die $ora_errstr;
  11.     $query = "select * from ipl where modelnum like 'F%001'";
  12.  
  13.     if ($ora_verno >= 2)
  14.     {
  15.         $ora_cache = (shift || 0);
  16.     }
  17.  
  18.     $csr = &ora_open($lda, $query) || die ora_errstr;
  19.  
  20.     while (@data = &ora_fetch($csr))
  21.     {
  22.         ++$count;
  23.     }
  24.     warn "($ora_errno) $ora_errstr" if $ora_errno;
  25.  
  26.     print "Selected $count lines\n";
  27.  
  28.     &ora_close($csr);
  29.     &ora_logoff($lda);
  30.  
  31. (I do not claim that this is a good test; it was simply a convenient one!)
  32.  
  33. The select statement matched 360 rows of 22 fields out a database of 43000
  34. records. The script was run ten times with Oraperl version 1, and ten times
  35. each using cache sizes of 1, 2, 3, 4, 5, 10, 20, 100, 200, 300 and 400. Note
  36. that the size of 400 is greater than the number of rows selected, so they
  37. were all collected in a single fetch. Totaling the figures for each group,
  38. I got the following results:
  39.  
  40.              percentage speedup
  41.     cache           compared to v1
  42.      size        real    user    sys
  43.  
  44.        1          0     -2      1
  45.        2          8      6     24
  46.        3         10      8     24
  47.        4         12     12     27
  48.        5         15     12     36
  49.       10         16     13     37
  50.       20         18     13     39
  51.      100         25     16     40
  52.      200         26     16     40
  53.      300         26     16     40
  54.      400         25     14     40
  55.  
  56. Obviously, the larger the cache, the more memory is required. Considering
  57. the relatively small performance improvement obtained by using a large cache
  58. compared with a small one, the default cache size is set to 5 rows.
  59.  
  60. If you want a different cache size, you can modify the default at compile
  61. time, you can set $ora_cache to the default for your program, or you can
  62. specify the cache size to apply to a particular &ora_open() call by
  63. supplying the number of rows to cache as the third parameter.
  64.  
  65. For information on caching, see OFEN in the OCI manual.
  66.