celluloid / reel

UNMAINTAINED: See celluloid/celluloid#779 - Celluloid::IO-powered web server
https://celluloid.io
MIT License
596 stars 87 forks source link

handle: "Expect: 100-continue" #111

Open collin opened 10 years ago

collin commented 10 years ago

Low priority, but I was having a heart attack for a moment when doing some benchmarks vs node and learned something new about HTTP and curl.

Curl against ruby server:

time curl -i --data-binary "@4mb.zip" -H "Content-Type: application/zip" http://localhost:9292/
HTTP/1.1 200 OK
Connection: Keep-Alive
Content-Length: 34

GOT THIS MUCH 4443572 (272 chunks)
real    0m2.127s
user    0m0.012s
sys 0m0.025s

Curl against node server:

time curl -i --data-binary "@4mb.zip" -H "Content-Type: application/zip" http://localhost:9292/
HTTP/1.1 100 Continue

HTTP/1.1 200 OK
Content-Type: text/plain
Date: Mon, 14 Oct 2013 09:37:12 GMT
Connection: keep-alive
Transfer-Encoding: chunked

GOT THIS MUCH: 4443572 (70 chunks)
real    0m0.093s
user    0m0.012s
sys 0m0.025s

At first I was thinking, "Oh no! node is so much faster than ruby. What have I been doing wrong with my life."

Then I noticed the extra HTTP/1.1 100 Continue

I added that extra header to my request handler and SWEET GLORY! Ruby really is my friend.

real    0m0.115s
user    0m0.012s
sys 0m0.025s
def route_request(connection, request)
  if request.headers["Expect"] == "100-continue"
    connection.socket << "HTTP/1.1 100 Continue\r\n\r\n"
  end
  length = 0
  chunks = 0

  request.body.each do |chunk|
    chunks += 1
    length += chunk.length
  end
  connection.respond :ok, "GOT THIS MUCH #{length} (#{chunks} chunks)"
end

Not sure if this is in-scope for reel, but even some sort of log message pointing me in the right direction would have prevented much un-warranted soul searching and hair pulling. :D

digitalextremist commented 10 years ago

:+1: most awesome issue/comment/read in a while

tarcieri commented 10 years ago

Any idea where the extra Expect: 100-continue was coming from?

FYI, for benchmarking tools like ab, httperf, siege, and wrk are probably all better choices. wrk is presently my personal favorite.

collin commented 10 years ago

From curl, is that what you mean? Or does reel support this and I'm getting two of these?

Thanks for the suggestions, I'll have to check out wrk.

On Tue, Oct 15, 2013 at 12:41 PM, Tony Arcieri notifications@github.comwrote:

Any idea where the extra Expect: 100-continue was coming from?

FYI, for benchmarking tools like ab, httperf, siege, and wrk are probably all better choices. wrk is presently my personal favorite.

— Reply to this email directly or view it on GitHubhttps://github.com/celluloid/reel/issues/111#issuecomment-26355970 .

tarcieri commented 10 years ago

So the difference here is that node's HTTP server is handling it internally and Reel is not?

collin commented 10 years ago

Yes, the behavior for node is defined here: http://nodejs.org/api/http.html#http_event_checkcontinue

On Tue, Oct 15, 2013 at 12:48 PM, Tony Arcieri notifications@github.comwrote:

So the difference here is that node's HTTP server is handling it internally and Reel is not?

— Reply to this email directly or view it on GitHubhttps://github.com/celluloid/reel/issues/111#issuecomment-26356545 .

tmornini commented 10 years ago

This is very interesting. Thank you very much for brining this to my attention!

digitalextremist commented 9 years ago

@collin I'm assessing this for 0.7.0 and am wondering if you've progressed with this on your end at all? Any private code out there resolving this?

collin commented 9 years ago

No, I don't have anything for this.

On Thu, Jan 22, 2015 at 4:41 PM, digitalextremist notifications@github.com wrote:

@collin https://github.com/collin I'm assessing this for 0.7.0 and am wondering if you've progressed with this on your end at all? Any private code out there resolving this?

— Reply to this email directly or view it on GitHub https://github.com/celluloid/reel/issues/111#issuecomment-71114195.