3 Unicorn performance is generally as good as a (mostly) Ruby web server
4 can provide. Most often the performance bottleneck is in the web
5 application running on Unicorn rather than Unicorn itself.
7 == Unicorn Configuration
9 See Unicorn::Configurator for details on the config file format.
11 * Setting a very low value for the :backlog parameter in "listen"
12 directives can allow failover to happen more quickly if your
13 cluster is configured for it.
15 * If you're doing extremely simple benchmarks and getting connection
16 errors under high request rates, increasing your :backlog parameter
17 above the already-generous default of 1024 can help avoid connection
18 errors. Keep in mind this is not recommended for real traffic if
19 you have another machine to failover to (see above).
21 * :rcvbuf and :sndbuf parameters generally do not need to be set for TCP
22 listeners under Linux 2.6 because auto-tuning is enabled. UNIX domain
23 sockets do not have auto-tuning buffer sizes; so increasing those will
24 allow syscalls and task switches to be saved for larger requests
25 and responses. If your app only generates small responses or expects
26 small requests, you may shrink the buffer sizes to save memory, too.
28 * Having socket buffers too large can also be detrimental or have
29 little effect. Huge buffers can put more pressure on the allocator
30 and may also thrash CPU caches, cancelling out performance gains
31 one would normally expect.
33 * Setting "preload_app true" can allow copy-on-write-friendly GC to
34 be used to save memory. It will probably not work out of the box with
35 applications that open sockets or perform random I/O on files.
36 Databases like TokyoCabinet use concurrency-safe pread()/pwrite()
37 functions for safe sharing of database file descriptors across
40 * On POSIX-compliant filesystems, it is safe for multiple threads or
41 processes to append to one log file as long as all the processes are
42 have them unbuffered (File#sync = true) or they are
43 record(line)-buffered in userspace.
45 * worker_processes should be scaled to the number of processes your
46 backend system(s) can support. DO NOT scale it to the number of
47 external network clients your application expects to be serving.
48 Unicorn is NOT for serving slow clients, that is the job of nginx.
50 == Kernel Parameters (Linux sysctl)
52 WARNING: Do not change system parameters unless you know what you're doing!
54 * net.core.rmem_max and net.core.wmem_max can increase the allowed
55 size of :rcvbuf and :sndbuf respectively. This is mostly only useful
56 for UNIX domain sockets which do not have auto-tuning buffer sizes.
58 * For load testing/benchmarking with UNIX domain sockets, you should
59 consider increasing net.core.somaxconn or else nginx will start
60 failing to connect under heavy load. You may also consider setting
61 a higher :backlog to listen on as noted earlier.
63 * If you're running out of local ports, consider lowering
64 net.ipv4.tcp_fin_timeout to 20-30 (default: 60 seconds). Also
65 consider widening the usable port range by changing
66 net.ipv4.ip_local_port_range.
68 * Setting net.ipv4.tcp_timestamps=1 will also allow setting
69 net.ipv4.tcp_tw_reuse=1 and net.ipv4.tcp_tw_recycle=1, which along
70 with the above settings can slow down port exhaustion. Not all
71 networks are compatible with these settings, check with your friendly
72 network administrator before changing these.
74 * Increasing the MTU size can reduce framing overhead for larger
75 transfers. One often-overlooked detail is that the loopback
76 device (usually "lo") can have its MTU increased, too.