diff options
author | Urban Müller | 2017-08-15 14:12:45 +0200 |
---|---|---|
committer | Urban Müller | 2017-08-15 14:12:45 +0200 |
commit | c1f2423a7f294737129b913b1367a7e43a491089 (patch) | |
tree | b35e8e3597a52b5be75397f629d31ebefaf1b587 /it_dbi.class | |
parent | 8cec6105e76488e64024f5d174704417525e1e0e (diff) | |
download | itools-c1f2423a7f294737129b913b1367a7e43a491089.tar.gz itools-c1f2423a7f294737129b913b1367a7e43a491089.tar.bz2 itools-c1f2423a7f294737129b913b1367a7e43a491089.zip |
permit throttling of database operations
Diffstat (limited to 'it_dbi.class')
-rw-r--r-- | it_dbi.class | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/it_dbi.class b/it_dbi.class index ee6d268..ab132ff 100644 --- a/it_dbi.class +++ b/it_dbi.class @@ -38,6 +38,7 @@ class it_dbi 'classprefix' => "", 'getfieldinfo' => true, # do not read schema. only select() allowed 'localized_defaultlanguage' => "de", # Localize fields with this suffix, e.g. copy title_de to title on read + 'throttle_writes' => 0, # sleep for 'throttle_writes' multiplied by the execution time after every write 'unbuffered' => false, # use MYSQLI_USE_RESULT (WARNING this is not at all equivalent to normal it_dbi WARNING) ); @@ -489,7 +490,7 @@ function query($query, $p = array()) $p += $this->_p; $start = gettimeofday(true); - if (!it::match('^(EXPLAIN|SELECT|SHOW)', $query, array('utf8' => false))) + if (($writing = !it::match('^(EXPLAIN|SELECT|SHOW)', $query, array('utf8' => false)))) { if ($p['server_update']) { @@ -529,6 +530,8 @@ function query($query, $p = array()) it_dbi::_state_purgeshared($dbid); } + if ($writing && $this->_p['throttle_writes']) + usleep(1000000 * (gettimeofday(true) - $start) * $this->_p['throttle_writes']); $msec = round(1000 * (gettimeofday(true) - $start)); $slow = $msec >= 2000; |