CARVIEW |
Select Language
HTTP/2 302
server: nginx
date: Tue, 19 Aug 2025 12:30:53 GMT
content-type: text/plain; charset=utf-8
content-length: 0
x-archive-redirect-reason: found capture at 20090302180934
location: https://web.archive.org/web/20090302180934/https://github.com/tra/spawn/tree
server-timing: captures_list;dur=0.999063, exclusion.robots;dur=0.032404, exclusion.robots.policy;dur=0.014257, esindex;dur=0.016019, cdx.remote;dur=39.560148, LoadShardBlock;dur=333.572675, PetaboxLoader3.datanode;dur=77.602444, PetaboxLoader3.resolve;dur=207.580430
x-app-server: wwwb-app217
x-ts: 302
x-tr: 432
server-timing: TR;dur=0,Tw;dur=0,Tc;dur=0
set-cookie: wb-p-SERVER=wwwb-app217; path=/
x-location: All
x-rl: 0
x-na: 0
x-page-cache: MISS
server-timing: MISS
x-nid: DigitalOcean
referrer-policy: no-referrer-when-downgrade
permissions-policy: interest-cohort=()
HTTP/2 301
server: nginx
date: Tue, 19 Aug 2025 12:30:54 GMT
content-type: text/html; charset=utf-8
content-length: 105
x-archive-orig-server: nginx/0.6.26
x-archive-orig-date: Mon, 02 Mar 2009 18:09:33 GMT
x-archive-orig-connection: close
x-archive-orig-set-cookie: _github_ses=BAh7BiIKZmxhc2hJQzonQWN0aW9uQ29udHJvbGxlcjo6Rmxhc2g6OkZsYXNoSGFzaHsABjoKQHVzZWR7AA%3D%3D--884981fc5aa85daf318eeff084d98e2cff92578f; path=/; expires=Wed, 01 Jan 2020 08:00:00 GMT; HttpOnly
x-archive-orig-status: 301 Moved Permanently
location: https://web.archive.org/web/20090302180934/https://github.com/tra/spawn/tree/master
x-archive-orig-x-runtime: 6ms
x-archive-orig-cache-control: no-cache
x-archive-orig-content-length: 105
cache-control: max-age=1800
memento-datetime: Mon, 02 Mar 2009 18:09:34 GMT
link: ; rel="original", ; rel="timemap"; type="application/link-format", ; rel="timegate", ; rel="first memento"; datetime="Sat, 20 Sep 2008 04:12:54 GMT", ; rel="prev memento"; datetime="Fri, 02 Jan 2009 09:09:26 GMT", ; rel="memento"; datetime="Mon, 02 Mar 2009 18:09:34 GMT", ; rel="next memento"; datetime="Mon, 25 May 2009 16:41:26 GMT", ; rel="last memento"; datetime="Fri, 18 Dec 2009 09:59:13 GMT"
content-security-policy: default-src 'self' 'unsafe-eval' 'unsafe-inline' data: blob: archive.org web.archive.org web-static.archive.org wayback-api.archive.org athena.archive.org analytics.archive.org pragma.archivelab.org wwwb-events.archive.org
x-archive-src: 52_8_20090302142605_crawl102-c/52_8_20090302180856_crawl101.arc.gz
server-timing: captures_list;dur=0.704505, exclusion.robots;dur=0.024809, exclusion.robots.policy;dur=0.010451, esindex;dur=0.014776, cdx.remote;dur=42.392056, LoadShardBlock;dur=342.273079, PetaboxLoader3.resolve;dur=359.928042, PetaboxLoader3.datanode;dur=88.389758, load_resource;dur=202.434177
x-app-server: wwwb-app217
x-ts: 301
x-tr: 616
server-timing: TR;dur=0,Tw;dur=0,Tc;dur=0
x-location: All
x-rl: 0
x-na: 0
x-page-cache: MISS
server-timing: MISS
x-nid: DigitalOcean
referrer-policy: no-referrer-when-downgrade
permissions-policy: interest-cohort=()
HTTP/2 200
server: nginx
date: Tue, 19 Aug 2025 12:30:55 GMT
content-type: text/html; charset=utf-8
x-archive-orig-server: nginx/0.6.31
x-archive-orig-date: Mon, 02 Mar 2009 18:09:34 GMT
x-archive-orig-connection: close
x-archive-orig-set-cookie: _github_ses=BAh7BiIKZmxhc2hJQzonQWN0aW9uQ29udHJvbGxlcjo6Rmxhc2g6OkZsYXNoSGFzaHsABjoKQHVzZWR7AA%3D%3D--884981fc5aa85daf318eeff084d98e2cff92578f; path=/; expires=Wed, 01 Jan 2020 08:00:00 GMT; HttpOnly
x-archive-orig-status: 200 OK
x-archive-orig-x-runtime: 749ms
x-archive-orig-etag: "baf452a88b4aa81fd772ea05b608ec69"
x-archive-orig-cache-control: private, max-age=0, must-revalidate
x-archive-orig-content-length: 21847
x-archive-guessed-content-type: text/html
x-archive-guessed-charset: utf-8
memento-datetime: Mon, 02 Mar 2009 18:09:34 GMT
link: ; rel="original", ; rel="timemap"; type="application/link-format", ; rel="timegate", ; rel="first memento"; datetime="Sat, 20 Sep 2008 04:12:54 GMT", ; rel="prev memento"; datetime="Wed, 04 Feb 2009 11:46:16 GMT", ; rel="memento"; datetime="Mon, 02 Mar 2009 18:09:34 GMT", ; rel="next memento"; datetime="Sun, 08 Mar 2009 15:31:17 GMT", ; rel="last memento"; datetime="Thu, 02 Mar 2017 06:15:12 GMT"
content-security-policy: default-src 'self' 'unsafe-eval' 'unsafe-inline' data: blob: archive.org web.archive.org web-static.archive.org wayback-api.archive.org athena.archive.org analytics.archive.org pragma.archivelab.org wwwb-events.archive.org
x-archive-src: 52_8_20090302142605_crawl102-c/52_8_20090302180856_crawl101.arc.gz
server-timing: captures_list;dur=0.712676, exclusion.robots;dur=0.024443, exclusion.robots.policy;dur=0.012891, esindex;dur=0.014760, cdx.remote;dur=10.053316, LoadShardBlock;dur=321.769830, PetaboxLoader3.datanode;dur=148.916168, PetaboxLoader3.resolve;dur=425.829718, load_resource;dur=392.091097
x-app-server: wwwb-app217
x-ts: 200
x-tr: 779
server-timing: TR;dur=0,Tw;dur=0,Tc;dur=0
x-location: All
x-rl: 0
x-na: 0
x-page-cache: MISS
server-timing: MISS
x-nid: DigitalOcean
referrer-policy: no-referrer-when-downgrade
permissions-policy: interest-cohort=()
content-encoding: gzip
tra's spawn at master - GitHub
This repository is private.
All pages are served over SSL and all pushing and pulling is done over SSH.
No one may fork, clone, or view it unless they are added as a member.
Every repository with this icon (
) is private.
Every repository with this icon (

This repository is public.
Anyone may fork, clone, or view it.
Every repository with this icon (
) is public.
Every repository with this icon (

Description: | spawn plugin for Rails to easily fork or thread long-running code blocks |
Homepage: | https://rubyforge.org/projects/spawn |
Clone URL: |
git://github.com/tra/spawn.git
Give this clone URL to anyone.
git clone git://github.com/tra/spawn.git
|
spawn /
name | age | message | |
---|---|---|---|
![]() |
.gitignore | Sat Feb 21 23:03:13 -0800 2009 | avoid memory leak in passenger [tra] |
![]() |
CHANGELOG | Sun May 11 12:38:13 -0700 2008 | added :nice option git-svn-id: svn+ssh://ruby... [tra] |
![]() |
LICENSE | Mon Oct 15 23:28:21 -0700 2007 | move everything to spawn subdir to make it easy... [tra] |
![]() |
README | Sat Feb 21 23:05:20 -0800 2009 | avoid memory leak in passenger [tra] |
![]() |
init.rb | Sun Dec 28 21:18:31 -0800 2008 | allow observers to spawn as well git-svn-id: ... [tra] |
![]() |
lib/ | Sun Feb 22 09:35:56 -0800 2009 | clear resources in the child in case somebody s... [tra] |
Spawn ===== This plugin provides a 'spawn' method to easily fork OR thread long-running sections of code so that your application can return results to your users more quickly. This plugin works by creating new database connections in ActiveRecord::Base for the spawned block. The plugin also patches ActiveRecord::Base to handle some known bugs when using threads (see lib/patches.rb). Usage ----- Here's a simple example of how to demonstrate the spawn plugin. In one of your controllers, insert this code (after installing the plugin of course): spawn do logger.info("I feel sleepy...") sleep 11 logger.info("Time to wake up!") end If everything is working correctly, your controller should finish quickly then you'll see the last log message several seconds later. If you need to wait for the spawned processes/threads, then pass the objects returned by spawn to Spawn::wait(), like this: N.times do |i| # spawn N blocks of code spawn_ids[i] = spawn do something(i) end end # wait for all N blocks of code to finish running wait(spawn_ids) If you want your forked child to run at a lower priority than the parent process, pass in the :nice option like this: spawn(:nice => 7) do do_something_nicely end By default, spawn will use the fork to spawn child processes. You can configure it to do threading either by telling the spawn method when you call it or by configuring your environment. For example, this is how you can tell spawn to use threading on the call, spawn(:method => :thread) do something end When using the :thread setting, spawn will check to make sure that you have set allow_concurrency=true in your configuration. If you want this setting then put this line in one of your environment config files: config.active_record.allow_concurrency = true If it is not set, then spawn will raise an exception. To (optionally) configure the spawn method in your configuration, add a line to your configuration file(s) like this: Spawn::method :thread If you don't set any configuration, the :method will default to :fork. To specify different values for different environments, pass the environment as the 2nd argument: Spawn::method :fork, 'production' Spawn::method :yield, 'test' This allows you to set your production and development environments to use different methods according to your needs. Forking vs. Threading --------------------- There are several tradeoffs for using threading vs. forking. Forking was chosen as the default primarily because it requires no configuration to get it working out of the box. Forking advantages: - more reliable? - the ActiveRecord code is generally not deemed to be thread-safe. Even though spawn attempts to patch known problems with the threaded implementation, there are no guarantees. Forking is heavier but should be fairly reliable. - keep running - this could also be a disadvantage, but you may find you want to fork off a process that could have a life longer than its parent. For example, maybe you want to restart your server without killing the spawned processes. We don't necessarily condone this (i.e. haven't tried it) but it's technically possible. - easier - forking works out of the box with spawn, threading requires you set allow_concurrency=true. Also, beware of automatic reloading of classes in development mode (config.cache_classes = false). Threading advantages: - less filling - threads take less resources... how much less? it depends. Some flavors of Unix are pretty efficient at forking so the threading advantage may not be as big as you think... but then again, maybe it's more than you think. ;-) - debugging - you can set breakpoints in your threads Acknowledgements ---------------- This plugin was initially inspired by Scott Persinger's blog post on how to use fork in rails for background processing. https://geekblog.vodpod.com/?p=26 Further inspiration for the threading implementation came from Jonathon Rochkind's blog post on threading in rails. https://bibwild.wordpress.com/2007/08/28/threading-in-rails/ Also thanks to all who have helped debug problems and suggest improvements including: Ahmed Adam, Tristan Schneiter, Scott Haug, Andrew Garfield, Eugene Otto, Dan Sharp, Olivier Ruffin Garry Tan, Matt Jankowski (2.2.x fixes) Tim Kadom, Mauricio Marcon Zaffari, Danial Pearce, Hongli Lai (passenger fixes) <your name here> Copyright (c) 2007-present Tom Anderson (tom@squeat.com), see LICENSE
This feature is coming soon. Sit tight!