vibe-d / vibe.d

Official vibe.d development
MIT License
1.15k stars 284 forks source link

benchmark HTTP parser #1025

Open MartinNowak opened 9 years ago

MartinNowak commented 9 years ago

The node.js HTTP parser is a small self-contained project. https://github.com/joyent/http-parser It would be interesting to compare vibe.d's current parser against this, both for performance and correctness.

etcimon commented 9 years ago

This is the new HTTP parser: https://github.com/etcimon/libhttp2/blob/315178a19dbaee98dab6ac9a950ec361f56fb84f/source/libhttp2/huffman.d#L345

^^

MartinNowak commented 9 years ago

Looks like a DFA? Interesting.

Tip: To get a permalink to a line in a file, press y. https://help.github.com/articles/getting-permanent-links-to-files/

etcimon commented 9 years ago

Tip: To get a permalink to a line in a file, press y.

And I'll remember that =)

Looks like a DFA? Interesting.

They're generated through a python script from nghttp2: https://github.com/tatsuhiro-t/nghttp2/blob/948d4d43d5f10240d991f70489fea89b62958381/mkstatichdtbl.py

That table is standard protocol so I didn't need to include the python.

edit: everything is standard protocol now ^^

s-ludwig commented 9 years ago

Tip: To get a permalink to a line in a file, press y.

And I'll remember that =)

Ditto! That's really helpful.

BTW, I still have some beginnings of a HTTP/2 implementation lying around that I started back in October. It's far from being a complete implementation, but integrates nicely with the API. Do you have started anything w.r.t. vibe.d integration, yet? I'd have to take a closer look and think about an optimal design if we are going to use the nghttp2/libhttp2 code.

etcimon commented 9 years ago

Do you have started anything w.r.t. vibe.d integration, yet?

This is the current file: https://github.com/etcimon/vibe.d/blob/7303c350048ea544932b167ffecea5aacd72a124/source/vibe/http/http2.d

Basically, an HTTP2Session is created and its internal event loop started when the TLS ALPN extension has the supported protocol or when the Upgrade: h2c header field is detected. The underlying stream (bodyWriter, etc.) is implemented as HTTP2Stream and instantiated by calling HTTP2Session.startRequest() and a new HTTPServerRequest or HTTPClientRequest is created like usual.

Basically, the HTTP2Stream is a ConnectionStream that supports readHeader and writeHeader, where header is a struct HTTPHeader and contains InetHeaderMap and URL. The HTTP2Session is like the Kernel event loop, with a task that loops for read and another task that loops for write. The HTTP2Stream is like the TCPConnection but without the TCP features, with an integrated blocking header parser/receiver, and some options to adjust the circular buffer size (Window Size).

I plan on having setHeader and writeBody in the stream directly as well so that internally you can atomically send the request using the libhttp2.session.submitRequest or response using libhttp2.session.submitResponse along with the END_STREAM flag.

The close() function just pipes through to a RstStream frame otherwise. Same for errors.

I think I can have this done within a few days, but obviously I could be wrong again about the timeline :) What do you have on your end btw

jadbox commented 8 years ago

+1: It would be awesome to get a parsing benchmark out there comparing the latest Vibe parser against Node.

wilzbach commented 8 years ago

There is also https://github.com/bithavoc/http-parser.d from @bithavoc How about adding it to the benchmark and comparing all four?