summaryrefslogtreecommitdiff
path: root/lib/iomaster.php
diff options
context:
space:
mode:
authorBrion Vibber <brion@pobox.com>2010-01-22 12:52:36 -0800
committerBrion Vibber <brion@pobox.com>2010-01-22 12:52:36 -0800
commitc7507e7e9dafa6d6e054978e720e4fce3abc9929 (patch)
treed756f2a2c7c9b487b6ef0f066a87f3cde40bc65d /lib/iomaster.php
parenta3e484a0e898bb94dd45cd7807bea1a931d7c6a9 (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. Conflicts: scripts/xmppdaemon.php
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 {