celluloid / celluloid-io

UNMAINTAINED: See celluloid/celluloid#779 - Evented sockets for Celluloid actors
https://celluloid.io
MIT License
879 stars 93 forks source link

Evaluate `exception: false` *_nonblock APIs #139

Open tarcieri opened 9 years ago

tarcieri commented 9 years ago

Ruby 2.1 added APIs to perform asynchronous I/O without using exceptions:

io.read_nonblock(n, exception: false)

I've seen reports of this affording a 2x speedup in async I/O performance, at least on MRI.

I do not know the status of this API on JRuby et al (cc @headius)

HoneyryderChuck commented 8 years ago

@tarcieri I'm having the issue that nonblocking reads with exception: false are not returning anything meaningful. The documentation states that it will return :wait_readable , but nothing about eof's. Should one assume that if the buffer is empty, it is an EOFError ?

tarcieri commented 8 years ago

I believe it returns nil on EOF.

You might take a look at the way I did this in http.rb. I was able to eliminate a lot of the redundancy that exists in the implementation in this PR:

https://github.com/httprb/http/blob/master/lib/http/timeout/global.rb#L84

HoneyryderChuck commented 8 years ago

It worked :+1: adapted/copy-pasted your perform_io method to the stream class. Will try to do something similar for the UDPSocket case. But this one seemed to do the trick. Fancy a review when you have the time? (not a lot changed, I guess).