XMPP output fix for StatusNet

January 21st, 2010

Yay, it’s big commit time!

I’ve landed my XMPP output queuing work in 0.9.x, running on my public test site.  Do let me know if XMPP subscription or i/o is flaky on it!

Should be ready to merge to testing & master and deploy when we’re content to do so… there is a database change necessary for the DB-based queueing system, so I want to confirm that’s not a problem before pushing out.

Big thanks to Craig Andrews for his work on generalizing the DB queues which I’ve started integrating; we should be able to land the rest including the IM pluginization for 1.0.

Commit summary:

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.

RTL language requirements for StatusNet

January 13th, 2010

There’s a few tricks to properly supporting right-to-left languages like Arabic and Hebrew in web applications, which we currently have a few issues with in StatusNet.

I’ve written up some notes on the wiki… link on for the fun!

StatusNet queue refactoring landed

January 12th, 2010

Woohoo! After a couple months off and on adjusting the architecture to something that seems to meet our needs, I’ve merged my refactoring of StatusNet’s background queue processing to 0.9.x.

Some of my design notes are up on the wiki, with a couple updates based on tweaks I made from my original plans.

Key items from the commit summary:

Major refactoring of queue handlers to support running multiple sites in one daemon.

Key changes:

  • Initialization code moved from common.php to StatusNet class; can now switch configurations during runtime.
  • As a consequence, configuration files must now be idempotent… Be careful with constant, function or class definitions.
  • Control structure for daemons/QueueManager/QueueHandler has been refactored; the run loop is now managed by IoMaster run via scripts/queuedaemon.php IoManager subclasses are woken to handle socket input or polling, and may cover multiple sites.
  • Plugins can implement notice queue handlers more easily by registering a QueueHandler class; no more need to add a daemon.

The new QueueDaemon runs from scripts/queuedaemon.php:

  • This replaces most of the old *handler.php scripts; they’ve been refactored to the bare handler classes.
  • Spawns multiple child processes to spread load; defaults to CPU count on Linux and Mac OS X systems, or override with –threads=N
  • When multithreaded, child processes are automatically respawned on failure.
  • Threads gracefully shut down and restart when passing a soft memory limit (defaults to 90% of memory_limit), limiting damage from memory leaks.
  • Support for UDP-based monitoring: http://www.gitorious.org/snqmon

Rough control flow diagram:

QueueDaemon -> IoMaster -> IoManager
QueueManager [listen or poll] ->  QueueHandler
XmppManager [ping&  keepalive]
XmppConfirmManager [poll updates]

Todo:

  • Respawning features not currently available running single-threaded.
  • When running single-site, configuration changes aren’t picked up.
  • New sites or config changes affecting queue subscriptions are not yet handled without a daemon restart.
  • SNMP monitoring output to integrate with general tools (nagios, ganglia)
  • Convert XMPP confirmation message sends to use stomp queue instead of polling
  • Convert xmppdaemon.php to IoManager?
  • Convert Twitter status, friends import polling daemons to IoManager
  • Clean up some error reporting and failure modes
  • May need to adjust queue priorities for best perf in backlog/flood cases

Detailed code history available in my daemon-work branch.

Time zones: do we really need them?

December 29th, 2009

While looking at StatusNet’s preferences dialog, I noticed we have a fairly generic but unfriendly timezone selector, done as a drop-down box with a raw list of zone names — this makes you find and select something like “America/Los_Angeles” or “Asia/Tokyo”:

Not only is the list very long and confusingly sorted, but the names are all either English or acronyms, making it hard to internationalize.

It occurs to me that we very rarely actually output formatted dates in the web interface anyway… most of the time we output relative times like “a few seconds ago” or “3 months ago”.

In fact, about the only place I can see that we’re outputting a fully formatted date is on an individual notice like this:

“Brion Vibber (brionv) ’s status on Friday, 27-Nov-09 19:19:11 UTC”
“Brion Vibber (brionv) ’s status on Friday, 27-Nov-09 11:19:11 PST”
etc

though we also have tooltips on the approximation eg “about a month ago”: “2009-11-27T11:19:11-08:00″

My own inclination would be to drop the timezone preferences entirely; in the rare cases where we output a formatted local date we can let client-side JavaScript do the actual date formatting with the client system’s actual time zone and language settings, with a UTC/GMT fallback for clients with JS disabled.

This drops an unnecessary and hard-to-select option field from preferences and site administration panels, and avoids inconsistencies when you travel or move and forget to update the timezone.

Any objections or suggestions for further refinement?

Welcome to the lower middle class?

December 24th, 2009

Hehe... I'm not actually in a trailer park... accurate geonames for inaccurate locations are fun. :D [A few seconds ago from web at Rail-A-Way Trailer Park, Browning, California, US ]

Location fuzzing in StatusNet

December 19th, 2009

I had a chat today w/ Craig Andrews & Chris Vollick about StatusNet’s geolocation support and how we might be able to better present how location info will be used, to avoid freaking people out with unexpected maps to their homes. :)

Some notes and this mockup for expanded location setup in preferences are on the wiki.

The main points are:

  • provide context for the browser’s location lookup opt-in (don’t trigger it until you’re poking at your location options)
  • show a sample map in the prefs so you know what other people will see
  • provide a one-click way to disable browser location lookups entirely
  • provide a one-click way to reduce the accuracy to city-level, probably by default

Any thoughts?

PHP 5.3 issues in StatusNet 0.9

December 16th, 2009

I did a little testing on the plane yesterday to see what PHP 5.3 issues are still remaining in StatusNet 0.9; most of the problems are with upstream libraries, but they break a number of things.

Memory leaks and DB_DataObject

December 14th, 2009

As part of my work restructuring the background daemons, I’m starting to do memory profiling on StatusNet… I’d like to get it to the point where we can enable a debug mode that just snapshots out how much memory each class and global takes up while you’re running.

I’ve already found some low-hanging fruit in DB_DataObject. This is a “clever” library that likes to stash a lot of stuff into a global $_DB_DATAOBJECT array, including all your query result data.

Sure you’ve got a free() method, but nobody calls those consistently…

I found I could quite easily drop a destructor onto our Memcached_DataObject intermediate class which calls the free() method when the object is destroyed (explicitly with an unset(), or implicitly by falling out of scope and no longer being referenced).

My queue-handler daemon was able to get through an average of 595 notices on my stress test before croaking on a 32M memory_limit, but jumped up to get through 761 notices simply by adding this one-line destructor. (Average of 5 runs.)

Not bad for a start!

I’ve committed the destructor onto 0.9.x branch.

L10n for StatusNet plugins

December 7th, 2009

Now that we’ve got UI translations going pretty well for StatusNet core via TranslateWiki, I’d like to see if we can get things working for plugins as well before the 0.9 final release.

I’d like some quick feedback from folks before merging into 0.9.x; you can see my work branch here.

In core code, to make a string translatable we wrap it in one of the gettext functions like this, most often the _() shortcut:

 $this->text(_("You have a new message."));

If you’re a plugin though, you need to add your own translations into the mix, and gettext makes you tell it which “domain” you’re pulling from each time…

 // at init time
 bindtextdomain("AwesomePlugin",
                dirname(__FILE__) . "/locale");
 ...
 $this->text(dgettext("AwesomePlugin",
                         "You have a new message."));

Repeating your plugin name for every string gets old REAL fast!

In my work branch I’ve added a new gettext wrapper function _m() which knows if it’s been called from a plugin, and picks out the right domain for you based on the plugin directory.

So rather than playing around with bindtextdomain() and dgettext() manually, you can just add one character and not worry about the rest:

 $this->text(_m("You have a new message."));

It also knows how many parameters you passed to it, so instead of whipping out ngettext() or dngettext() (or god forbid dnpgettext!) you can just keep using the nice compact _m() when your needs get fancier:

Plurals:

 $this->text(sprintf(_m("You have a new message.",
                        "You have %d new messages.",
                        $messageCount),
                     $messageCount);

Contexts for disambiguation:

 // read vs delete
 $this->text(_m("message-action", "Read"));

 // read vs unread
 $this->text(_m("message-state", "Read"));

Plurals with contexts!

 $this->text(_m("message-state",
                "Read",
                "Read",
                $messageCount));

Plugins maintained in the main StatusNet repo shouldn’t need to worry about anything else — the .po file templates and updates via TranslateWiki will be handled through the same workflow as the core. (I’m working with Siebrand at TranslateWiki to make sure we can automate this as much as possible, including adding new plugins.)

scripts/update_po_translations.php can regenerate all (or just core, or just plugin) .po templates for those who want to push them in immediately, though.

As with core, the binary .mo files won’t be included in the git repository to simplify code maintenance. I’ve added a Makefile at the base level which’ll build all the .mo files for folks to test localization in their working copies (or to build a release!)

Confusing Twitter settings

December 3rd, 2009

I’ve been getting feedback for some time that this checkbox in StatusNet’s Twitter connect settings is confusing:

Subscribe to my Twitter friends here.

People tend to think this should mean that this’ll pull all your Twitter friends’ updates into your timeline on the SN site… which is actually a separate checkbox, when enabled (sorry, it’s still disabled on identi.ca):

Import my Friends Timeline.

I suspect we could come up with clearer wording for both of these… let’s start the bidding!

  [x] Subscribe to my Twitter friends’ accounts on %%site.name%% automatically.

  [x] Show my friends’ tweets here on %%site.name%%.

Any other ideas?


I love Wikipedia!