unicorn 1.1.7 - major fixes to minor components
[unicorn.git] / HACKING
blob781c4cafe01ef65130d37a1c9bb9403ced9ef717
1 = Unicorn Hacker's Guide
3 == Polyglot Infrastructure
5 Like Mongrel, we use Ruby where it makes sense, and Ragel with C where
6 it helps performance.  All of the code that actually runs your Rack
7 application is written Ruby, Ragel or C.
9 As far as tests and documentation goes, we're not afraid to embrace Unix
10 and use traditional Unix tools where they make sense and get the job
11 done.
13 === Tests
15 Tests are good, but slow tests make development slow, so we make tests
16 faster (in parallel) with GNU make (instead of Rake) and avoiding
17 RubyGems.
19 Users of GNU-based systems (such as GNU/Linux) usually have GNU make
20 installed as "make" instead of "gmake".
22 Since we don't load RubyGems by default, loading Rack properly requires
23 setting up RUBYLIB to point to where Rack is located.  Not loading
24 RubyGems drastically lowers the time to run the full test suite.  You
25 may setup a "local.mk" file in the top-level working directory to setup
26 your RUBYLIB and any other environment variables.  A "local.mk.sample"
27 file is provided for reference.
29 Running the entire test suite with 4 tests in parallel:
31   gmake -j4 test
33 Running just one unit test:
35   gmake test/unit/test_http_parser.rb
37 Running just one test case in a unit test:
39   gmake test/unit/test_http_parser.rb--test_parse_simple.n
41 === HttpServer
43 We strive to write as little code as possible while still maintaining
44 readability.  However, readability and flexibility may be sacrificed for
45 performance in hot code paths.  For Ruby, less code generally means
46 faster code.
48 Memory allocation should be minimized as much as practically possible.
49 Buffers for IO#readpartial are preallocated in the hot paths to avoid
50 building up garbage.  Hash assignments use frozen strings to avoid the
51 duplication behind-the-scenes.
53 We spend as little time as possible inside signal handlers and instead
54 defer handling them for predictability and robustness.  Most of the
55 Unix-specific things are in the Unicorn::HttpServer class.  Unix systems
56 programming experience will come in handy (or be learned) here.
58 === Documentation
60 We use RDoc 2.5.x with Darkfish for documentation as much as possible,
61 if you're on Ruby 1.8 you want to install the latest "rdoc" gem.  Due to
62 the lack of RDoc-to-manpage converters we know about, we're writing
63 manpages in Markdown and converting to troff/HTML with Pandoc.
65 Please wrap documentation at 72 characters-per-line or less (long URLs
66 are exempt) so it is comfortably readable from terminals.
68 When referencing mailing list posts, use
69 "http://mid.gmane.org/$MESSAGE_ID" if possible since the Message-ID
70 remains searchable even if Gmane becomes unavailable.
72 === Ruby/C Compatibility
74 We target Ruby 1.8.6+, 1.9 and will target Rubinius as it becomes
75 production-ready.  We need the Ruby implementation to support fork,
76 exec, pipe, UNIX signals, access to integer file descriptors and
77 ability to use unlinked files.
79 All of our C code is OS-independent and should run on compilers
80 supported by the versions of Ruby we target.
82 === Ragel Compatibility
84 We target the latest released version of Ragel and will update our code
85 to keep up with new releases.  Packaged tarballs and gems include the
86 generated source code so they will remain usable if compatibility is
87 broken.
89 == Contributing
91 Contributions are welcome in the form of patches, pull requests, code
92 review, testing, documentation, user support or any other feedback is
93 welcome.  The mailing list is the central coordination point for all
94 user and developer feedback and bug reports.
96 === Submitting Patches
98 Follow conventions already established in the code and do not exceed 80
99 characters per line.
101 Inline patches (from "git format-patch -M") to the mailing list are
102 preferred because they allow code review and comments in the reply to
103 the patch.
105 We will adhere to mostly the same conventions for patch submissions as
106 git itself.  See the Documentation/SubmittingPatches document
107 distributed with git on on patch submission guidelines to follow.  Just
108 don't email the git mailing list or maintainer with Unicorn patches :)
110 == Running Development Versions
112 It is easy to install the contents of your git working directory:
114 Via RubyGems (RubyGems 1.3.5+ recommended for prerelease versions):
116   gmake install-gem
118 Without RubyGems (via setup.rb):
120   gmake install
122 It is not at all recommended to mix a RubyGems installation with an
123 installation done without RubyGems, however.