News for hackers. Stuff that matters.
Re:Wangle – an asynchronous C++ networking and RPC library by pcwalton on Wednesday April 20, 2016 @12:58PM (#11535816)
Go uses synchronous I/O backed with an M:N implementation. Rust and D use synchronous I/O backed with a 1:1 implementation. Semantically, there is no difference between the two. The difference is in the implementation, and 1:1 threading is not as slow as you think on Linux.
Re:Wangle – an asynchronous C++ networking and RPC library by tptacek on Wednesday April 20, 2016 @01:00PM (#11535825)
Why are we talking about Go, Rust, and D on a thread about a new C++ library? I mean, I know the answer, but I wish we weren't.

I ordinarily wouldn't care, but I usually feel like I have something to learn from ambitious networking libraries even when they're written in languages I prefer not to use.

Re:Wangle – an asynchronous C++ networking and RPC library by pcwalton on Wednesday April 20, 2016 @01:03PM (#11535859)
For what it's worth, I try to not bring up Rust in threads about other languages; it just happens that most threads about Rust appear in threads about other languages.

I would rather talk about the implementation of async I/O too.

Re:Wangle – an asynchronous C++ networking and RPC library by thepumpkin1979 on Wednesday April 20, 2016 @01:07PM (#11535903)
I just wanted to point out the barriers a developer faces when trying to use C++. Sorry, I can't resist compare it to what I know, which happens to be other programming languages different to C++.
Re:Wangle – an asynchronous C++ networking and RPC library by dunkelheit on Wednesday April 20, 2016 @01:37PM (#11536160)
Does that mean that one can use system threads as frivolously as goroutines (e.g. spawning new thread for each incoming request)? Conventional C++ wisdom advices against it. But then it may be informed by some old and bad pthreads implementations.
Re:Wangle – an asynchronous C++ networking and RPC library by pcwalton on Wednesday April 20, 2016 @01:53PM (#11536304)
Usually memory usage ends up being the limiting factor, not thread spawning performance. Memory usage is independent of 1:1 vs. M:N, though, as pthread stack sizes are configurable.
Re:Wangle – an asynchronous C++ networking and RPC library by jhartmann on Wednesday April 20, 2016 @01:53PM (#11536300)
A reasonable compromise is to use a threadpool (which is a big part of what comes with wangle) with a fixed number of threads and you queue the tasks to be run by the threads. It works quite well in practice, and you can use coroutines (I'm most familiar with the implementation in boost coroutine and the Ewan webserver personally) to go the whole hog and get something as lightweight as Erlang green threads or goroutines. I would only bother doing that of course if in your particular use case you find the threadpool doesn't perform well. With proper sizing and broken up units of work, it really works quite well in practice.
Re:Wangle – an asynchronous C++ networking and RPC library by otabdeveloper on Wednesday April 20, 2016 @03:25PM (#11537037)
> Does that mean that one can use system threads as frivolously as goroutines (e.g. spawning new thread for each incoming request)?

Yes. In fact, under Linux oftentimes spawning a thread and then running a system call can be faster than just running a system call.

> Conventional C++ wisdom advices against it.

With 32 bit CPU's you might run out of virtual memory quickly, since each thread allocates virtual memory for its stack.

With 64 bit CPU's there are no issues. (Also never forget that virtual memory isn't real memory, it's just a page counter.)

Re:Wangle – an asynchronous C++ networking and RPC library by pcwalton on Wednesday April 20, 2016 @04:14PM (#11537380)
> Yes. In fact, under Linux oftentimes spawning a thread and then running a system call can be faster than just running a system call.

Interesting, do you have any further info (references, cites) on this?

Re:Wangle – an asynchronous C++ networking and RPC library by scott_s on Wednesday April 20, 2016 @05:04PM (#11537750)
Sign me up for wanting more info as well. I'm curious how that could work out, since spawning a thread is a system call.