rainbows.git  about / heads / tags
Unicorn for sleepy apps and slow clients
blob 67e42507976e80a8cda1814472f03f4df095a9ea 3033 bytes (raw)
$ git show v3.0.0:vs_Unicorn	# shows this blob on the CLI

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
 
= \Rainbows! is like Unicorn, but Different...

While \Rainbows! depends on Unicorn for its process/socket management,
HTTP parser and configuration language; \Rainbows! is more ambitious.

== Architectural Diagrams

=== Unicorn uses a 1:1 mapping of processes to clients

     unicorn master
     \_ unicorn worker[0]
     |  \_ client[0]
     \_ unicorn worker[1]
     |  \_ client[1]
     \_ unicorn worker[2]
     |  \_ client[2]
     ...
     \_ unicorn worker[M]
        \_ client[M]

=== \Rainbows! uses a M:N mapping of processes to clients

    rainbows master
     \_ rainbows worker[0]
     |  \_ client[0,0]
     |  \_ client[0,1]
     |  \_ client[0,2]
     |  ...
     |  \_ client[0,N]
     \_ rainbows worker[1]
     |  \_ client[1,0]
     |  \_ client[1,1]
     |  \_ client[1,2]
     |  \_ client[1,3]
     |  ...
     |  \_ client[1,N]
     \_ rainbows worker[2]
     |  \_ client[2,0]
     |  \_ client[2,1]
     |  \_ client[2,2]
     |  ...
     |  \_ client[2,N]
     ...
     \_ rainbows worker[M]
        \_ client[M,0]
        \_ client[M,1]
        \_ client[M,2]
        ...
        \_ client[M,N]

In both cases, workers share common listen sockets with the master and
pull connections off the listen queue only if the worker has resources
available.

== Differences from Unicorn

* log rotation is handled immediately in \Rainbows! whereas Unicorn has
  the luxury of delaying it until the current request is finished
  processing to prevent log entries for one request to be split across
  files.

* load balancing between workers is imperfect, certain worker processes
  may be servicing more requests than others so it is important to not
  set +worker_connections+ too high.  Unicorn worker processes can never
  be servicing more than one request at once.

* speculative, non-blocking accept() is not used, this is to help
  load balance between multiple worker processes.

* HTTP pipelining and keepalive may be used for GET and HEAD requests.

* Less heavily-tested and inherently more complex.


== Similarities with Unicorn

While some similarities are obvious (we depend on and subclass off
Unicorn code), some things are not:

* Does not attempt to accept() connections when pre-configured limits
  are hit (+worker_connections+).  This will first help balance load
  to different worker processes, and if your listen() +:backlog+ is
  overflowing: to other machines in your cluster.

* Accepts the same {signals}[http://unicorn.bogomips.org/SIGNALS.html]
  for process management, so you can share scripts to manage them (and
  nginx, too).

* supports per-process listeners, allowing an external load balancer
  like haproxy or nginx to be used to balance between multiple
  worker processes.

* Exposes a streaming "rack.input" to the Rack application that reads
  data off the socket as the application reads it (while retaining
  rewindable semantics as required by Rack).  This allows Rack-compliant
  apps/middleware to implement things such as real-time upload progress
  monitoring.

git clone https://yhbt.net/rainbows.git