DEV Community

Discussion on: How profiling my slow Ruby code led me to publish my first gem!

Collapse
 
rhymes profile image
rhymes

Very interesting André, thanks for the walkthrough!

So cool that you're writing a HTTP/2 server from scratch and with a C extension as well! My C is probably useless as of late.

Regarding the protocol implementation, do you know about this project?

GitHub logo igrigorik / http-2

Pure Ruby implementation of HTTP/2 protocol

HTTP-2

Gem Version Build Status Coverage Status Analytics

Pure Ruby, framework and transport agnostic, implementation of HTTP/2 protocol and HPACK header compression with support for:

Protocol specifications:

Getting started

$> gem install http-2

This implementation makes no assumptions as how the data is delivered: it could be a regular Ruby TCP socket, your custom eventloop, or whatever other transport you wish to use - e.g. ZeroMQ, avian carriers, etc.

Your code is responsible for feeding data into the parser, which performs all of the necessary HTTP/2 decoding, state management and the rest, and vice versa, the parser will emit bytes (encoded HTTP/2 frames) that you can then route to the destination. Roughly, this…

I took a quick look and I think it's using pack/unpack as well so the implementation probably has the same problem you've highlighted but it might contain ideas for other features

Collapse
 
andrepiske profile image
André Diego Piske

It definitively took me more time than it should have taken to answer you.

Well when I started the project I wasn't aware of the one you pointed. However later on I went to search github for "http/2" and I saw it existed :) In fact it seems quite a few people are making that stuff, just for fun (and for learning as well, probably).

I haven't looked how they solved their problems though. But looking at it now, seems that he is using a similar technique, but with strings instead of arrays. That is probably much more efficient as there is then no need to use pack/unpack: github.com/igrigorik/http-2/blob/m...
Now I wonder how well that performs