From 38877a49224dca841d548f5d43c0143dafb19050 Mon Sep 17 00:00:00 2001 From: Brion Date: Tue, 22 Dec 2009 15:08:44 -0800 Subject: Skip DB_DataObject's in-process cache for static gets on CLI processes. The local process cache would grow forever, keeping things stuck in memory and preventing GC. --- classes/Memcached_DataObject.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'classes') diff --git a/classes/Memcached_DataObject.php b/classes/Memcached_DataObject.php index 70e9e351d..af8e24090 100644 --- a/classes/Memcached_DataObject.php +++ b/classes/Memcached_DataObject.php @@ -37,6 +37,15 @@ class Memcached_DataObject extends DB_DataObject } } + /** + * Wrapper for DB_DataObject's static lookup using memcached + * as backing instead of an in-process cache array. + * + * @param string $cls classname of object type to load + * @param mixed $k key field name, or value for primary key + * @param mixed $v key field value, or leave out for primary key lookup + * @return mixed Memcached_DataObject subtype or false + */ function &staticGet($cls, $k, $v=null) { if (is_null($v)) { @@ -53,6 +62,13 @@ class Memcached_DataObject extends DB_DataObject } else { $i = DB_DataObject::staticGet($cls, $k, $v); if ($i) { + // DB_DataObject's in-process lookup cache interferes with GC + // to cause massive memory leaks in long-running processes. + if (php_sapi_name() == 'cli') { + $i->_clear_cache(); + } + + // Now store it into the shared memcached, if present... $i->encache(); } return $i; -- cgit v1.2.3-54-g00ecf From eab6d1c95450cf9b209a0961ac325f2f9ce87d80 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Tue, 22 Dec 2009 20:18:27 -0800 Subject: Fix for massively slow friends timeline query due to indexing bug introduced with repeats. Sorting on notice.id when our primary selector was notice_inbox.user_id caused a filesort and table scan of the notice table. Switchng to notice_inbox's notice_id means we can use our index, and everything comes right up. Before: mysql> explain SELECT notice.id AS id FROM notice JOIN notice_inbox ON notice.id = notice_inbox.notice_id WHERE notice_inbox.user_id = 18574 AND notice.repeat_of IS NULL ORDER BY notice.id DESC LIMIT 61 OFFSET 0; +----+-------------+--------------+--------+------------------------------------+---------+---------+-------------------------------+--------+----------------------------------------------+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | +----+-------------+--------------+--------+------------------------------------+---------+---------+-------------------------------+--------+----------------------------------------------+ | 1 | SIMPLE | notice_inbox | ref | PRIMARY,notice_inbox_notice_id_idx | PRIMARY | 4 | const | 102600 | Using index; Using temporary; Using filesort | | 1 | SIMPLE | notice | eq_ref | PRIMARY | PRIMARY | 4 | stoica.notice_inbox.notice_id | 1 | Using index | +----+-------------+--------------+--------+------------------------------------+---------+---------+-------------------------------+--------+----------------------------------------------+ After: mysql> explain SELECT notice.id AS id FROM notice JOIN notice_inbox ON notice.id = notice_inbox.notice_id WHERE notice_inbox.user_id = 18574 AND notice.repeat_of IS NULL ORDER BY notice_id DESC LIMIT 61 OFFSET 0; +----+-------------+--------------+--------+------------------------------------+---------+---------+-------------------------------+--------+--------------------------+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | +----+-------------+--------------+--------+------------------------------------+---------+---------+-------------------------------+--------+--------------------------+ | 1 | SIMPLE | notice_inbox | ref | PRIMARY,notice_inbox_notice_id_idx | PRIMARY | 4 | const | 102816 | Using where; Using index | | 1 | SIMPLE | notice | eq_ref | PRIMARY,notice_repeatof_idx | PRIMARY | 4 | stoica.notice_inbox.notice_id | 1 | Using where | +----+-------------+--------------+--------+------------------------------------+---------+---------+-------------------------------+--------+--------------------------+ --- classes/User.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'classes') diff --git a/classes/User.php b/classes/User.php index ae709b46b..484dc8c82 100644 --- a/classes/User.php +++ b/classes/User.php @@ -543,7 +543,7 @@ class User extends Memcached_DataObject // NOTE: we sort by fave time, not by notice time! - $qry .= 'ORDER BY notice.id DESC '; + $qry .= 'ORDER BY notice_id DESC '; if (!is_null($offset)) { $qry .= "LIMIT $limit OFFSET $offset"; -- cgit v1.2.3-54-g00ecf