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
27 * Setting "preload_app true" can allow copy-on-write-friendly GC to
28 be used to save memory. It will probably not work out of the box with
29 applications that open sockets or perform random I/O on files.
30 Databases like TokyoCabinet use concurrency-safe pread()/pwrite()
31 functions for safe sharing of database file descriptors across
34 * On POSIX-compliant filesystems, it is safe for multiple threads or
35 processes to append to one log file as long as all the processes are
36 have them unbuffered (File#sync = true) or they are
37 record(line)-buffered in userspace.
39 * worker_processes should be scaled to the number of processes your
40 backend system(s) can support. DO NOT scale it to the number of
41 external network clients your application expects to be serving.
42 Unicorn is NOT for serving slow clients, that is the job of nginx.
44 == Kernel Parameters (Linux sysctl)
46 WARNING: Do not change system parameters unless you know what you're doing!
48 * net.core.rmem_max and net.core.wmem_max can increase the allowed
49 size of :rcvbuf and :sndbuf respectively. This is mostly only useful
50 for UNIX domain sockets which do not have auto-tuning buffer sizes.
52 * For load testing/benchmarking with UNIX domain sockets, you should
53 consider increasing net.core.somaxconn or else nginx will start
54 failing to connect under heavy load. You may also consider setting
55 a higher :backlog to listen on as noted earlier.
57 * If you're running out of local ports, consider lowering
58 net.ipv4.tcp_fin_timeout to 20-30 (default: 60 seconds). Also
59 consider widening the usable port range by changing
60 net.ipv4.ip_local_port_range.
62 * Setting net.ipv4.tcp_timestamps=1 will also allow setting
63 net.ipv4.tcp_tw_reuse=1 and net.ipv4.tcp_tw_recycle=1, which along
64 with the above settings can slow down port exhaustion. Not all
65 networks are compatible with these settings, check with your friendly
66 network administrator before changing these.
68 * Increasing the MTU size can reduce framing overhead for larger
69 transfers. One often-overlooked detail is that the loopback
70 device (usually "lo") can have its MTU increased, too.