mirrored from git://git.bogomips.org/unicorn.git
-
Notifications
You must be signed in to change notification settings - Fork 260
/
HACKING
117 lines (78 loc) · 3.8 KB
/
HACKING
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
= Unicorn Hacker's Guide
== Polyglot Infrastructure
Like Mongrel, we use Ruby where it makes sense, and Ragel with C where
it helps performance. All of the code that actually runs your Rack
application is written Ruby, Ragel or C.
Ragel may be dropped in favor of a picohttpparser-based one in the future.
As far as tests and documentation goes, we're not afraid to embrace Unix
and use traditional Unix tools where they make sense and get the job
done.
=== Tests
Tests are good, but slow tests make development slow, so we make tests
faster (in parallel) with GNU make (instead of Rake) and avoiding
RubyGems.
New tests are written in Perl 5 and use TAP <https://testanything.org/>
to ensure stability and immunity from Ruby incompatibilities.
Users of GNU-based systems (such as GNU/Linux) usually have GNU make
installed as "make" instead of "gmake".
Running the entire test suite with 4 tests in parallel:
gmake -j4 check
Running just one unit test:
gmake test/unit/test_http_parser.rb
Running just one test case in a unit test:
gmake test/unit/test_http_parser.rb--test_parse_simple.n
=== HttpServer
We strive to write as little code as possible while still maintaining
readability. However, readability and flexibility may be sacrificed for
performance in hot code paths. For Ruby, less code generally means
faster code.
Memory allocation should be minimized as much as practically possible.
Buffers for IO#readpartial are preallocated in the hot paths to avoid
building up garbage. Hash assignments use frozen strings to avoid the
duplication behind-the-scenes.
We spend as little time as possible inside signal handlers and instead
defer handling them for predictability and robustness. Most of the
Unix-specific things are in the Unicorn::HttpServer class. Unix systems
programming experience will come in handy (or be learned) here.
=== Documentation
Please wrap documentation at 72 characters-per-line or less (long URLs
are exempt) so it is comfortably readable from terminals.
When referencing mailing list posts, use
<tt>https://yhbt.net/unicorn-public/$MESSAGE_ID/</tt> if possible
since the Message-ID remains searchable even if a particular site
becomes unavailable.
=== Ruby/C Compatibility
We target C Ruby 2.5 and later. We need the Ruby
implementation to support fork, exec, pipe, UNIX signals, access to
integer file descriptors and ability to use unlinked files.
All of our C code is OS-independent and should run on compilers
supported by the versions of Ruby we target.
=== Ragel Compatibility
We target the latest released version of Ragel in Debian and will update
our code to keep up with new releases. Packaged tarballs and gems
include the generated source code so they will remain usable if
compatibility is broken.
== Contributing
Contributions are welcome in the form of patches, pull requests, code
review, testing, documentation, user support or any other feedback is
welcome. The mailing list is the central coordination point for all
user and developer feedback and bug reports.
=== Submitting Patches
Follow conventions already established in the code and do not exceed 80
characters per line.
Inline patches (from "git format-patch -M") to the mailing list are
preferred because they allow code review and comments in the reply to
the patch.
We will adhere to mostly the same conventions for patch submissions as
git itself. See the
{SubmittingPatches}[https://git.kernel.org/cgit/git/git.git/tree/Documentation/SubmittingPatches]
document
distributed with git on on patch submission guidelines to follow. Just
don't email the git mailing list or maintainer with Unicorn patches :)
== Building a Gem
You can build the Unicorn gem with the following command:
gmake gem
== Running Development Versions
It is easy to install the contents of your git working directory:
Via RubyGems
gmake install-gem