summaryrefslogtreecommitdiff
path: root/lib/iomaster.php
diff options
context:
space:
mode:
authorBrion Vibber <brion@pobox.com>2010-01-21 16:42:50 -0800
committerBrion Vibber <brion@pobox.com>2010-01-21 22:40:35 -0800
commit0e852def6ae5aa529cca0aef1187152fb5a880be (patch)
tree5b4b49327c5d7224c0c05ce08c1ddf72f1e44f13 /lib/iomaster.php
parent0bb23e6fd724a12bba6766949cd3294b288d8a43 (diff)
XMPP queued output & initial retooling of DB queue manager to support non-Notice objects.
Queue handlers for XMPP individual & firehose output now send their XML stanzas to another output queue instead of connecting directly to the chat server. This lets us have as many general processing threads as we need, while all actual XMPP input and output go through a single daemon with a single connection open. This avoids problems with multiple connected resources: * multiple windows shown in some chat clients (psi, gajim, kopete) * extra load on server * incoming message delivery forwarding issues Database changes: * queue_item drops 'notice_id' in favor of a 'frame' blob. This is based on Craig Andrews' work branch to generalize queues to take any object, but conservatively leaving out the serialization for now. Table updater (preserves any existing queued items) in db/rc3to09.sql Code changes to watch out for: * Queue handlers should now define a handle() method instead of handle_notice() * QueueDaemon and XmppDaemon now share common i/o (IoMaster) and respawning thread management (RespawningDaemon) infrastructure. * The polling XmppConfirmManager has been dropped, as the message is queued directly when saving IM settings. * Enable $config['queue']['debug_memory'] to output current memory usage at each run through the event loop to watch for memory leaks To do: * Adapt XMPP i/o to component connection mode for multi-site support. * XMPP input can also be broken out to a queue, which would allow the actual notice save etc to be handled by general queue threads. * Make sure there are no problems with simply pushing serialized Notice objects to queues. * Find a way to improve interactive performance of the database-backed queue handler; polling is pretty painful to XMPP. * Possibly redo the way QueueHandlers are injected into a QueueManager. The grouping used to split out the XMPP output queue is a bit awkward.
Diffstat (limited to 'lib/iomaster.php')
-rw-r--r--lib/iomaster.php39
1 files changed, 18 insertions, 21 deletions
diff --git a/lib/iomaster.php b/lib/iomaster.php
index ce77b53b2..004e92b3e 100644
--- a/lib/iomaster.php
+++ b/lib/iomaster.php
@@ -27,7 +27,7 @@
* @link http://status.net/
*/
-class IoMaster
+abstract class IoMaster
{
public $id;
@@ -66,24 +66,19 @@ class IoMaster
if ($site != common_config('site', 'server')) {
StatusNet::init($site);
}
-
- $classes = array();
- if (Event::handle('StartIoManagerClasses', array(&$classes))) {
- $classes[] = 'QueueManager';
- if (common_config('xmpp', 'enabled') && !defined('XMPP_EMERGENCY_FLAG')) {
- $classes[] = 'XmppManager'; // handles pings/reconnects
- $classes[] = 'XmppConfirmManager'; // polls for outgoing confirmations
- }
- }
- Event::handle('EndIoManagerClasses', array(&$classes));
-
- foreach ($classes as $class) {
- $this->instantiate($class);
- }
+ $this->initManagers();
}
}
/**
+ * Initialize IoManagers for the currently configured site
+ * which are appropriate to this instance.
+ *
+ * Pass class names into $this->instantiate()
+ */
+ abstract function initManagers();
+
+ /**
* Pull all local sites from status_network table.
* @return array of hostnames
*/
@@ -170,7 +165,7 @@ class IoMaster
$write = array();
$except = array();
$this->logState('listening');
- common_log(LOG_INFO, "Waiting up to $timeout seconds for socket data...");
+ common_log(LOG_DEBUG, "Waiting up to $timeout seconds for socket data...");
$ready = stream_select($read, $write, $except, $timeout, 0);
if ($ready === false) {
@@ -190,7 +185,7 @@ class IoMaster
if ($timeout > 0 && empty($sockets)) {
// If we had no listeners, sleep until the pollers' next requested wakeup.
- common_log(LOG_INFO, "Sleeping $timeout seconds until next poll cycle...");
+ common_log(LOG_DEBUG, "Sleeping $timeout seconds until next poll cycle...");
$this->logState('sleep');
sleep($timeout);
}
@@ -207,6 +202,8 @@ class IoMaster
if ($usage > $memoryLimit) {
common_log(LOG_INFO, "Queue thread hit soft memory limit ($usage > $memoryLimit); gracefully restarting.");
break;
+ } else if (common_config('queue', 'debug_memory')) {
+ common_log(LOG_DEBUG, "Memory usage $usage");
}
}
}
@@ -223,8 +220,7 @@ class IoMaster
{
$softLimit = trim(common_config('queue', 'softlimit'));
if (substr($softLimit, -1) == '%') {
- $limit = trim(ini_get('memory_limit'));
- $limit = $this->parseMemoryLimit($limit);
+ $limit = $this->parseMemoryLimit(ini_get('memory_limit'));
if ($limit > 0) {
return intval(substr($softLimit, 0, -1) * $limit / 100);
} else {
@@ -242,9 +238,10 @@ class IoMaster
* @param string $mem
* @return int
*/
- protected function parseMemoryLimit($mem)
+ public function parseMemoryLimit($mem)
{
// http://www.php.net/manual/en/faq.using.php#faq.using.shorthandbytes
+ $mem = strtolower(trim($mem));
$size = array('k' => 1024,
'm' => 1024*1024,
'g' => 1024*1024*1024);
@@ -253,7 +250,7 @@ class IoMaster
} else if (is_numeric($mem)) {
return intval($mem);
} else {
- $mult = strtolower(substr($mem, -1));
+ $mult = substr($mem, -1);
if (isset($size[$mult])) {
return substr($mem, 0, -1) * $size[$mult];
} else {