News for hackers. Stuff that matters.
Re:"Ruby developers need to stop using EventMachine. It's th... by tptacek on Wednesday October 24, 2012 @10:20PM (#4696066)
There are times when you might reach for select() not to scale the whole program, but because for instance you're trying to hot potato data from a Reader to a Writer.

Obviously, the whole of Golang's concurrency model is lightweight threads scheduled on I/O events. But that's not exposed to the programmer; in fact, it's hermetically sealed away from the programmer from what I can tell.

So now you know what I meant by that statement.

Re:"Ruby developers need to stop using EventMachine. It's th... by zemo on Wednesday October 24, 2012 @10:46PM (#4696121)
every time you perform i/o, the current goroutine yields to the scheduler.

If you want to manually yield to the scheduler, you call runtime.Gosched() and the calling goroutine yields. If you want to lock a goroutine into a specific thread, you call runtime.LockOSThread(). Everything is single-threaded to start until you call runtime.GOMAXPROCS(), but that's intended to go away in the very near future. So... I'm not sure what you mean by sealed away; the Go runtime does the sensible things that it can do automatically, but you still have the ability to change the scheduling behavior if you really want to.

what do you mean by "doesn't offer a select primitive"? I'm not familiar with your definition of select, because Go has a select keyword for concurrency control, and I'm under the impression you're talking about select as its defined in EventMachine, could you elaborate?

Re:"Ruby developers need to stop using EventMachine. It's th... by tptacek on Thursday October 25, 2012 @12:13AM (#4696339)
I'm referring to the system call. Sorry, I can see how that would cause lots of confusion.
Re:"Ruby developers need to stop using EventMachine. It's th... by stock_toaster on Wednesday October 24, 2012 @11:25PM (#4696225)
Thanks. I think I understand a bit better now.

Go provides concurrency primitives (scheduler yielding i/o, channels, goroutines, etc) upon which you can build your own "events". I agree (and this seems to be your point) that Go doesn't provide a canned event mechanism that you can just hook into for callbacks on IO.

For example in the Go http server[1] a goroutine accepts in a loop and kicks off goroutines to process and handle new requests.

[1]: http://golang.org/src/pkg/net/http/server.go?s=30200:30241#L...

Re:"Ruby developers need to stop using EventMachine. It's th... by tptacek on Thursday October 25, 2012 @12:16AM (#4696347)
Sure, I'm using the Go http server.

Take the example of a simple proxy to see where I'm coming from. Sure, I'm happy to have Go manage all the connections and sockets and I'm happy to spawn new goroutines for each connection and all that. But a proxy accepts an inbound connection, makes an outbound connection, and then monitors the outbound and inbound sides for data. The loop to do this with sockets could be a simple two-descriptor read select(2) call. But instead, I have to spawn two more goroutines, one to "monitor" (really, read) from inbound, and one for outbound.

Re:"Ruby developers need to stop using EventMachine. It's th... by smegel on Thursday October 25, 2012 @03:05AM (#4696656)
> But instead, I have to spawn two more goroutines, one to "monitor" (really, read) from inbound, and one for outbound.

What does Golang's select/case not do that you want?

Re:"Ruby developers need to stop using EventMachine. It's th... by tptacek on Thursday October 25, 2012 @05:52PM (#4699739)
Is there some feature of the language or the libraries that I am missing that turns a socket (err, a TCPConn) into a channel that I can read with Golang's select construction? Seriously asking. That would be awesome.
Re:"Ruby developers need to stop using EventMachine. It's th... by smegel on Thursday October 25, 2012 @07:31PM (#4700119)
No, I think you would need to wrap the TCPConn in a goroutine that does the Read, handles any errors, then passes the bytes back to the consumer via a channel. At least it would be a very generic and small goroutine to do this.

I agree that would be a nice feature though.

Re:"Ruby developers need to stop using EventMachine. It's th... by tptacek on Thursday October 25, 2012 @09:46PM (#4700468)
You know what's happening in this thread? I made it sound like I was criticizing Go for needing to spawn goroutines to do this. I'm not! It makes sense, in the context of Go, to do it this way, even though as a C programmer by training that's not my first thought on how to do it.

I'm not criticizing Go for being anti-event; I'm just observing that it is. Idiomatic Go --- like, the code in the standard library --- has a strong bias towards straight-line code.

Re:"Ruby developers need to stop using EventMachine. It's th... by smegel on Thursday October 25, 2012 @10:41PM (#4700592)
> I'm not criticizing Go for being anti-event; I'm just observing that it is. Idiomatic Go --- like, the code in the standard library --- has a strong bias towards straight-line code.

I think I understand where you are coming from now - I think you are saying Go is "anti-event-based-callback-driven" rather than "anti-event-loop-implementation" - which is absolutely true. Go's concurrency model is build on CSP (Hoare's Communicating Sequential Processes)[1] which seems to advocate procedural threads rather than callbacks.

[1] http://golang.org/doc/go_faq.html#goroutines

Re:"Ruby developers need to stop using EventMachine. It's th... by drivebyacct2 on Thursday October 25, 2012 @01:30AM (#4696497)
Is there a large overhead for having to use a goroutine rather than the lower level? Do you think it's appropriate for Go to expose that, or do you just miss it?
Re:"Ruby developers need to stop using EventMachine. It's th... by cmccabe on Thursday October 25, 2012 @03:54AM (#4696724)
> Is there a large overhead for having to use a > goroutine rather than the lower level?

No.

Re:"Ruby developers need to stop using EventMachine. It's th... by aaronblohowiak on Thursday October 25, 2012 @01:04AM (#4696444)
Would you just select { case <- reader... case writer <- data..} ?

I know this isn't the same as posix select, but it does let you have one goroutine coordinate the hot potato..

Re:"Ruby developers need to stop using EventMachine. It's th... by tptacek on Thursday October 25, 2012 @07:20PM (#4700085)
That would require a goroutine for each socket to hot potato from the socket to a channel, right?
Re:"Ruby developers need to stop using EventMachine. It's th... by aaronblohowiak on Friday October 26, 2012 @03:44PM (#4703898)
Yes. This allows you to have the "when any of these socket's state changes" semantics in your controller/dispatcher function. I would like it if they had such an interface in stdlib...

If you really do just need to take data from one Reader and send it to a Writer, you can make a new Pipe.