unicorn 1.0.2
[unicorn.git] / HACKING
blob6a05d4b1f60ca639003bde527fedba63eebaf45e
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 installed
20 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.4.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 === Ruby/C Compatibility
67 We target Ruby 1.8.6+, 1.9 and will target Rubinius as it becomes
68 production-ready.  We need the Ruby implementation to support fork,
69 exec, pipe, UNIX signals, access to integer file descriptors and
70 ability to use unlinked files.
72 All of our C code is OS-independent and should run on compilers
73 supported by the versions of Ruby we target.
75 === Ragel Compatibility
77 We target the latest released version of Ragel and will update our code
78 to keep up with new releases.  Packaged tarballs and gems include the
79 generated source code so they will remain usable if compatibility is
80 broken.
82 == Contributing
84 Contributions are welcome in the form of patches, pull requests, code
85 review, testing, documentation, user support or any other feedback is
86 welcome.  The mailing list is the central coordination point for all
87 user and developer feedback and bug reports.
89 === Submitting Patches
91 Follow conventions already established in the code and do not exceed 80
92 characters per line.
94 Inline patches (from "git format-patch -M") to the mailing list are
95 preferred because they allow code review and comments in the reply to
96 the patch.
98 We will adhere to mostly the same conventions for patch submissions as
99 git itself.  See the Documentation/SubmittingPatches document
100 distributed with git on on patch submission guidelines to follow.  Just
101 don't email the git mailing list or maintainer with Unicorn patches :)
103 == Running Development Versions
105 It is easy to install the contents of your git working directory:
107 Via RubyGems (RubyGems 1.3.5+ recommended for prerelease versions):
109   gmake install-gem
111 Without RubyGems (via setup.rb):
113   gmake install
115 It is not at all recommended to mix a RubyGems installation with an
116 installation done without RubyGems, however.