From c1f2423a7f294737129b913b1367a7e43a491089 Mon Sep 17 00:00:00 2001 From: Urban Müller Date: Tue, 15 Aug 2017 14:12:45 +0200 Subject: permit throttling of database operations --- it_dbi.class | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'it_dbi.class') 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; -- cgit v1.2.3