| [85] | 1 | Rebuild Queue |
|---|
| [171] | 2 | Version 1.04 |
|---|
| [85] | 3 | |
|---|
| 4 | |
|---|
| 5 | Summary |
|---|
| 6 | ======= |
|---|
| 7 | |
|---|
| 8 | The Rebuild Queue plugin is designed to let you shift the rebuilding |
|---|
| 9 | operations typically done by Movable Type to one or more "offline" |
|---|
| 10 | processes. |
|---|
| 11 | |
|---|
| 12 | With this plugin, you can fine-tune your building operations so they |
|---|
| 13 | are distributed and distribute the built pages across any number of |
|---|
| 14 | servers. |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | Requirements |
|---|
| 18 | ============ |
|---|
| 19 | |
|---|
| [89] | 20 | Movable Type version 3.3 or later (or Movable Type Enterprise). |
|---|
| 21 | |
|---|
| [164] | 22 | The 'rsync' command if using remote server synchronization. (see: http://samba.anu.edu.au/rsync/) |
|---|
| [85] | 23 | |
|---|
| [164] | 24 | Time::HiRes (see: http://search.cpan.org/dist/Time-HiRes/) |
|---|
| [85] | 25 | |
|---|
| 26 | Installation |
|---|
| 27 | ============ |
|---|
| 28 | |
|---|
| 29 | To install, place the "RebuildQueue" directory in this distribution |
|---|
| 30 | underneath your Movable Type "plugins" directory. Once the files are |
|---|
| 31 | physically installed, accessing Movable Type will trigger an upgrade |
|---|
| 32 | procedure which will install the plugin's table into your database. |
|---|
| 33 | |
|---|
| 34 | The plugin files, once installed should match that shown below: |
|---|
| 35 | |
|---|
| 36 | MT_DIR/ |
|---|
| [86] | 37 | mt-static/ |
|---|
| 38 | RebuildQueue/ |
|---|
| 39 | rebuildq.gif |
|---|
| [85] | 40 | plugins/ |
|---|
| 41 | RebuildQueue/ |
|---|
| 42 | lib/ |
|---|
| 43 | RebuildQueue/ |
|---|
| 44 | Daemon.pm |
|---|
| 45 | File.pm |
|---|
| 46 | Plugin.pm |
|---|
| 47 | Publisher.pm |
|---|
| 48 | RebuildQueue.pl |
|---|
| 49 | |
|---|
| 50 | |
|---|
| 51 | All files should have permission that make them readable by the |
|---|
| 52 | web server and/or account being used to invoke the offline |
|---|
| 53 | RebuildQueue.pl script (644 permissions); the RebuildQueue.pl |
|---|
| 54 | script should be executable (755 permissions). |
|---|
| 55 | |
|---|
| 56 | Once the installation is complete, you are ready to configure the |
|---|
| 57 | plugin. |
|---|
| 58 | |
|---|
| 59 | |
|---|
| 60 | Configuration |
|---|
| 61 | ============= |
|---|
| 62 | |
|---|
| 63 | Global Configuration Options |
|---|
| 64 | ---------------------------- |
|---|
| 65 | |
|---|
| 66 | Navigate to the Plugin listing from the MT System Overview menu. There you |
|---|
| 67 | will find an entry for the Rebuild Queue plugin. Click the "Show Settings" |
|---|
| 68 | link to reveal the global configuration settings. |
|---|
| 69 | |
|---|
| 70 | "Number of Workers": This setting lets you define how many rebuild "worker" |
|---|
| 71 | processes you plan to run. The default number is 1, but you can increase |
|---|
| 72 | this number if you wish. When the Rebuild Queue schedules a page to be |
|---|
| 73 | rebuilt, it can randomly assign the task to one of the worker processes. This |
|---|
| 74 | helps distribute the rebuilding load across multiple processes or servers. |
|---|
| 75 | |
|---|
| 76 | Weblog Configuration Options |
|---|
| 77 | ---------------------------- |
|---|
| 78 | |
|---|
| 79 | To enable the Rebuild Queue, you must go to the weblog(s) you wish it to |
|---|
| 80 | manage and enable it for each of them. From the Weblog Settings page, go |
|---|
| 81 | to the "Plugins" tab and click the "Show Settings" link for the Rebuild Queue |
|---|
| 82 | entry listed there. The following settings are available at the weblog level: |
|---|
| 83 | |
|---|
| 84 | "Enable for this Weblog?": Check this option to enable the Rebuild Queue to |
|---|
| 85 | manage rebuilding for that weblog. |
|---|
| 86 | |
|---|
| 87 | "Force Building to Worker": If you have configured (at the global level) 2 |
|---|
| 88 | or more worker processes, you will see this option. It lets you assign any |
|---|
| 89 | queued build operations for this weblog to a particular worker. This gives |
|---|
| 90 | you control over which worker process builds the weblog instead of it being |
|---|
| 91 | randomly distributed. |
|---|
| 92 | |
|---|
| 93 | Cron Jobs and Daemon Processes |
|---|
| 94 | ------------------------------ |
|---|
| 95 | |
|---|
| 96 | Since rebuilding is done separately, it's important to set up the |
|---|
| 97 | Rebuild Queue processes to do the actual rebuilding operations and |
|---|
| 98 | mirroring you may require. |
|---|
| 99 | |
|---|
| 100 | The RebuildQueue.pl script is used to run these processes. Running |
|---|
| 101 | RebuildQueue.pl without any options will show the command usage. |
|---|
| 102 | |
|---|
| 103 | A typical cron job for the RebuildQueue itself might be something like this: |
|---|
| 104 | |
|---|
| [162] | 105 | */15 * * * * cd /path/to/RebuildQueue; ./RebuildQueue.pl |
|---|
| [85] | 106 | |
|---|
| 107 | This will invoke the Rebuild Queue every 15 minutes to build any pages that |
|---|
| 108 | have been modified since the last execution. Of course, you can invoke it |
|---|
| 109 | more often than that if you prefer. |
|---|
| 110 | |
|---|
| [162] | 111 | */15 * * * * cd /path/to/RebuildQueue; ./RebuildQueue.pl -sync -to user@hostname: |
|---|
| 112 | |
|---|
| [85] | 113 | This cron job will handle the rsync job to copy content from the local |
|---|
| 114 | server to another. |
|---|
| 115 | |
|---|
| [162] | 116 | */15 * * * * cd /path/to/RebuildQueue; ./RebuildQueue.pl -daemonize |
|---|
| [85] | 117 | |
|---|
| 118 | This will invoke the Rebuild Queue process as a daemon; that is, it will |
|---|
| 119 | remain running until the process has been halted. This may be preferable |
|---|
| 120 | since it will see pending rebuild requests almost immediately and handle |
|---|
| 121 | them sooner. It only allows one daemon to run, so setting it up on a cron |
|---|
| 122 | job is a way to make sure the daemon process is always running, even if |
|---|
| 123 | it is killed for one reason or another. |
|---|
| 124 | |
|---|
| [162] | 125 | */15 * * * * cd /path/to/RebuildQueue; ./RebuildQueue.pl -daemonize -worker 2 |
|---|
| [85] | 126 | |
|---|
| 127 | This sets up a second worker daemon. I said only one daemon can run, but |
|---|
| 128 | that only applies by worker id (the default worker id is 1). So you can't |
|---|
| 129 | have multiple daemons running with the same worker id, but you may run as |
|---|
| 130 | many workers as you want. |
|---|
| 131 | |
|---|
| 132 | As long as the database is shared (or you can replicate to multiple |
|---|
| 133 | databases), the Rebuild Queue daemons can be running on totally different |
|---|
| 134 | servers and then syncing to the others in your web farm. |
|---|
| 135 | |
|---|
| 136 | You may also want to 'nice' these processes so they don't overpower the |
|---|
| 137 | server when they wake up to do some work. |
|---|
| 138 | |
|---|
| 139 | Throttling |
|---|
| 140 | ---------- |
|---|
| 141 | |
|---|
| 142 | You may also throttle the rebuilding of certain templates or types of |
|---|
| 143 | templates. That is, you may want to limit the rebuilding of category |
|---|
| 144 | archives to once per day. |
|---|
| 145 | |
|---|
| 146 | ./RebuildQueue.pl -throttle category=8640 |
|---|
| 147 | |
|---|
| 148 | Throttle times are given in seconds. |
|---|
| 149 | |
|---|
| 150 | Or perhaps you want to only build a given template once every hour, |
|---|
| 151 | regardless of how many times it is requested to rebuild through the MT |
|---|
| 152 | interface or comment system. The template's id is 10. |
|---|
| 153 | |
|---|
| 154 | ./RebuildQueue.pl -throttle 10=360 |
|---|
| 155 | |
|---|
| 156 | You may repeat the -throttle switch as many times as you require to |
|---|
| 157 | specify your rules. |
|---|
| 158 | |
|---|
| 159 | |
|---|
| 160 | Example |
|---|
| 161 | ======= |
|---|
| 162 | |
|---|
| 163 | Lets say you have a few weblogs that are used to publish a set of media |
|---|
| 164 | web sites. The pages published are fairly heavy with content and/or |
|---|
| 165 | comments and take time to process, so you want to shift that work to |
|---|
| 166 | the Rebuild Queue instead. You also have 3 web servers that handle visitor |
|---|
| 167 | traffic and 1 that is used by your bloggers to publish the content. |
|---|
| 168 | |
|---|
| 169 | mt.zine.com (MT installation) |
|---|
| 170 | www, www2, www3.zine.com (web farm for visitors; load balanced) |
|---|
| 171 | |
|---|
| 172 | On mt.zine.com, you'd have your typical MT installation plus the Rebuild |
|---|
| 173 | Queue plugin. |
|---|
| 174 | |
|---|
| 175 | You set up a cron job that runs the Rebuild Queue daemon. |
|---|
| 176 | |
|---|
| [163] | 177 | */15 * * * * cd /path/to/RebuildQueue; ./RebuildQueue.pl -daemonize |
|---|
| [85] | 178 | |
|---|
| 179 | You also set up a cron job that handles syncing to the web servers: |
|---|
| 180 | |
|---|
| 181 | 10,25,40,55 * * * * /path/to/RebuildSync.sh |
|---|
| 182 | |
|---|
| 183 | RebuildSync.sh is a custom script, containing: |
|---|
| 184 | |
|---|
| 185 | #!/bin/sh |
|---|
| 186 | cd /path/to/RebuildQueue |
|---|
| 187 | RSYNC_RSH=ssh |
|---|
| 188 | ./RebuildQueue.pl -sync -to user@www: -to user@www2: -to user@www3: |
|---|
| 189 | |
|---|
| 190 | The sync command takes all files that the Rebuild Queue daemon has rebuilt |
|---|
| 191 | and rsyncs them to the servers you specify. Note that the physical file |
|---|
| 192 | paths as they exist on the "mt.zine.com" server must be the same on the |
|---|
| 193 | other servers to match up. |
|---|
| 194 | |
|---|
| 195 | |
|---|
| 196 | Availability |
|---|
| 197 | ============ |
|---|
| 198 | |
|---|
| 199 | The latest release of this plugin can be found at this address: |
|---|
| 200 | |
|---|
| 201 | http://code.sixapart.com/ |
|---|
| 202 | |
|---|
| 203 | |
|---|
| 204 | License |
|---|
| 205 | ======= |
|---|
| 206 | |
|---|
| 207 | This plugin is released under the Artistic License. |
|---|
| 208 | |
|---|
| 209 | |
|---|
| 210 | Authors |
|---|
| 211 | ======= |
|---|
| 212 | |
|---|
| 213 | Brad Choate and Jay Allen of Six Apart |
|---|
| 214 | |
|---|