flow_diagram.asciidoc 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. [[flow_diagram]]
  2. == Flow diagram
  3. Cowboy is a lightweight HTTP server with support for HTTP/1.1,
  4. HTTP/2 and Websocket.
  5. It is built on top of Ranch. Please see the Ranch guide for more
  6. information about how the network connections are handled.
  7. === Overview
  8. Placeholder section.
  9. // @todo Make the diagram.
  10. === Number of processes per connection
  11. By default, Cowboy will use one process per connection,
  12. plus one process per set of request/response (called a
  13. stream, internally).
  14. The reason it creates a new process for every request is due
  15. to the requirements of HTTP/2 where requests are executed
  16. concurrently and independently from the connection. The
  17. frames from the different requests end up interleaved on
  18. the single TCP connection.
  19. The request processes are never reused. There is therefore
  20. no need to perform any cleanup after the response has been
  21. sent. The process will terminate and Erlang/OTP will reclaim
  22. all memory at once.
  23. Cowboy ultimately does not require more than one process
  24. per connection. It is possible to interact with the connection
  25. directly from a stream handler, a low level interface to Cowboy.
  26. They are executed from within the connection process, and can
  27. handle the incoming requests and send responses. This is however
  28. not recommended in normal circumstances, as a stream handler
  29. taking too long to execute could have a negative impact on
  30. concurrent requests or the state of the connection itself.
  31. === Date header
  32. Because querying for the current date and time can be expensive,
  33. Cowboy generates one 'Date' header value every second, shares it
  34. to all other processes, which then simply copy it in the response.
  35. This allows compliance with HTTP/1.1 with no actual performance loss.
  36. === Binaries
  37. Cowboy makes extensive use of binaries.
  38. Binaries are more efficient than lists for representing
  39. strings because they take less memory space. Processing
  40. performance can vary depending on the operation. Binaries
  41. are known for generally getting a great boost if the code
  42. is compiled natively. Please see the HiPE documentation
  43. for more details.
  44. Binaries may end up being shared between processes. This
  45. can lead to some large memory usage when one process keeps
  46. the binary data around forever without freeing it. If you
  47. see some weird memory usage in your application, this might
  48. be the cause.