architecture.asciidoc 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. [[architecture]]
  2. == Architecture
  3. Cowboy is a lightweight HTTP server.
  4. It is built on top of Ranch. Please see the Ranch guide for more
  5. information.
  6. === One process per connection
  7. It uses only one process per connection. The process where your
  8. code runs is the process controlling the socket. Using one process
  9. instead of two allows for lower memory usage.
  10. Because there can be more than one request per connection with the
  11. keepalive feature of HTTP/1.1, that means the same process will be
  12. used to handle many requests.
  13. Because of this, you are expected to make sure your process cleans
  14. up before terminating the handling of the current request. This may
  15. include cleaning up the process dictionary, timers, monitoring and
  16. more.
  17. === Binaries
  18. It uses binaries. Binaries are more efficient than lists for
  19. representing strings because they take less memory space. Processing
  20. performance can vary depending on the operation. Binaries are known
  21. for generally getting a great boost if the code is compiled natively.
  22. Please see the HiPE documentation for more details.
  23. === Date header
  24. Because querying for the current date and time can be expensive,
  25. Cowboy generates one `Date` header value every second, shares it
  26. to all other processes, which then simply copy it in the response.
  27. This allows compliance with HTTP/1.1 with no actual performance loss.
  28. === Max connections
  29. By default the maximum number of active connections is set to a
  30. generally accepted big enough number. This is meant to prevent having
  31. too many processes performing potentially heavy work and slowing
  32. everything else down, or taking up all the memory.
  33. Disabling this feature, by setting the `{max_connections, infinity}`
  34. protocol option, would give you greater performance when you are
  35. only processing short-lived requests.