3

I am using nghttp2 to implement a RESTful API server. I have defined two GET APIs: /api/ping and /api/wait. While the response to the former is sent immediately, the server does some processing before responding to the latter. I allotted 4 threads to the server.

From a client (also implemented using nghttp2), I made a connection to the server and made the API calls one by one, /api/wait first followed by /api/ping. I observed using Wireshark that the two GET requests are sent over two different TCP packets. However, until the server completes processing of the /api/wait, it does not not process /api/ping, although it has other threads available.

I established two TCP connections from the client and made the two API calls on the different connections and the server processed those in parallel.

Does this mean that nghttp2 processes one TCP connection exclusively on one thread and requests from one TCP connection are processed sequentially by design? Is there any setting in nghttp2 to circumvent this? This may be a good feature for a web application (processing requests sequentially) but not an API server where APIs are independent of each other.

Soumya Kanti
  • 1,429
  • 1
  • 17
  • 28
  • is your code available somewhere? – Frederik Deweerdt Apr 10 '18 at 02:55
  • https://gist.github.com/soumyakantiroychowdhury/d7104c4c83ad2da19c22416460582dc1 – Soumya Kanti Apr 10 '18 at 06:31
  • 1
    Thanks, spawning a thread from the wait handler should work, something like the following: https://gist.github.com/deweerdt/37bfe15569b8eb96c5799692e0b376a0 – Frederik Deweerdt Apr 11 '18 at 04:29
  • Thanks, your solution works. But won't it have performance issues for creating and destroying threads? Moreover, this method would require me to know which APIs are slower in order to delegate the task to a different thread. – Soumya Kanti Apr 13 '18 at 01:03
  • > But won't it have performance issues for creating and destroying threads? Yes, you would need a thread pool to avoid those. > Moreover, this method would require me to know which APIs are slower in order to delegate the task to a different thread That is true. However, the trade off is done for performance, if streams were handled by different threads, you would have to add locking to synchronize the different threads writing to the same underlying TCP connection. – Frederik Deweerdt Apr 13 '18 at 02:16
  • Agreed with your points. Thanks again. – Soumya Kanti Apr 15 '18 at 11:50

0 Answers0