News for hackers. Stuff that matters.
Re:Handling 1M websocket connections in Go by rdtsc on Wednesday February 13, 2019 @05:08PM (#19157581)
Very cool. Noticed they had to go down to epoll: https://github.com/eranyanay/1m-go-websockets/blob/master/3_... that seems a bit too low level. Why not spawn 1m goroutines is that not feasible?

This also reminds me of Erlang VM handling 2M for Whatsapp on a single server in 2012:

https://blog.whatsapp.com/196/1-million-is-so-2011

Re:Handling 1M websocket connections in Go by windlep on Wednesday February 13, 2019 @05:47PM (#19157889)
> Noticed they had to down to epoll: https://github.com/eranyanay/1m-go-websockets/blob/master/3_.... that seems a bit too low level.

Agreed, I'd be quite curious how many libraries in the Go ecosystem they can't use as a result. Either because the library spawns a goroutine, uses one under the hood, etc.

Having to drop to this level makes me wonder if it'd be better to just use a language better suited to this type of asynchronous networking (C/C++/Rust).

Re:Handling 1M websocket connections in Go by kjksf on Wednesday February 13, 2019 @06:03PM (#19158016)
Very few Go libraries start goroutines on their own. Concurrency is mostly an application level concern.

HTTP library is unusual in that sense.

At the same time, the beauty of how http library is designed and the solution he describes is that there are hooks that allow being even more efficient with very little code.

Or to put it differently: Go gives you excellent (compared to everything else out there except C++/Rust) networking performance out of the box and you can go even faster with a minimal amount of effort.

What you call "dropping to this level" is 80 lines of code (https://github.com/eranyanay/1m-go-websockets/blob/master/3_...) and now you don't even have to write them yourself.

Re:Handling 1M websocket connections in Go by windlep on Wednesday February 13, 2019 @08:56PM (#19159019)
To be more specific, lots of idiomatic Go patterns typically involve using channels. Working at this level means you can't do that per 'client' since that would imply at least one goroutine per client.

There's plenty of libraries that involve channels (and assume you have goroutines per connection/client), do those play well with the use of epoll in this manner? I would assume I can't use the stdlib time package to do a timeout for example, since that provides a channel to wait on, while in this setup I need objects that work with epoll. Obviously in that case I could use evio which abstracts over epoll/kqueue and provides a Tick...

So my comment was more that "dropping to this level" means dropping the use of the majority of standard Go concurrency idioms which revolve around goroutines and channels. It's not about the raw lines of code involved. Writing code in this style of async doesn't feel very Go-like and when you look at an example of some code using this style its exactly the thing Go was trying to avoid with goroutines (https://github.com/tidwall/evio/blob/master/examples/http-se...).

You end up with async event-based code, not the clean synchronous-appearing Go code that goroutines and channels provide.

Re:Handling 1M websocket connections in Go by e-r-a-n on Wednesday February 13, 2019 @05:10PM (#19157600)
The idea behind going all the way down to epoll is to reduce the memory footprint by around 30% otherwise, with every goroutine stack consuming 4-8KB, it's not feasible to go with 1goroutine-1websocket approach
Re:Handling 1M websocket connections in Go by cdoxsey on Wednesday February 13, 2019 @07:46PM (#19158671)
That's what, 8GB of ram? A lot for a laptop... but not too much for a server.
Re:Handling 1M websocket connections in Go by doublerebel on Wednesday February 13, 2019 @10:48PM (#19159466)
30% extra RAM is a very noticeable server expense.
Re:Handling 1M websocket connections in Go by ElijahLynn on Wednesday February 13, 2019 @05:13PM (#19157631)
Same. Reminded me of Erlang too!