
Wangle – an asynchronous C++ networking and RPC library - doppp
https://code.facebook.com/posts/215466732167400/wangle-an-asynchronous-c-networking-and-rpc-library/
======
jhartmann
I have used this library pretty heavily in some of my recent work and I love
how easy it makes building performant async network servers in C++. Minor
nitpick: It would be nice though, if they built shared libraries by default
though, last release I took I had to tell cmake to make a shared library.
Since this is used by fbthrift as a dependency, I think it really makes sense
to build it that way by default. I also use fblualib and it builds with a very
old version of some of these libraries probably because the FAIR team didn't
want to mess with tweaking the builds so they can work with standalone wangle
(parts of the library used to be part of folly).

------
rburhum
After most compilers started properly supporting the newer C++ standards, it
seems there has been an increase in the amount of love that C++ libraries are
getting. A lot of people like the to say that [x] is superior to C or C++ -
often ignoring that their favorite language's libraries/runtime/compilers/vm
is most likely implemented in the very same languages they are putting down.

~~~
pjmlp
> After most compilers started properly supporting the newer C++ standards, it
> seems there has been an increase in the amount of love that C++ libraries
> are getting. Sadly there are many more compilers out there than just gcc,
> clang, icc and msvc++.

Many of those aren't still C++11 compliant, specially in mainframes, classical
commercial UNIXes, embedded real time OS and certified compilers.

But it is true, thanks to the productivity of latest standards, there has been
an increase in C++ visibility, specially thanks to Microsoft.

People like to bash their C++'s compliance, but they are the commercial vendor
with the more up to date support, even than icc last time I checked.

Also they were the main sponsors for Back to native conferences and eventually
making it together with CppCon.

[https://blogs.msdn.microsoft.com/vcblog/2014/04/03/cppcon-
th...](https://blogs.msdn.microsoft.com/vcblog/2014/04/03/cppcon-the-c-
conference/)

Also Windows Phone is the only mobile OS where C++ is a first class language.

>. A lot of people like the to say that [x] is superior to C or C++ - often
ignoring that their favorite language's libraries/runtime/compilers/vm is most
likely implemented in the very same languages they are putting down.

A lot of people like to point out that fact, ignoring that many compiler
writers tend to use C or C++ out of convenience for existing tools instead of
bootraping the full eco-system around a new programming language.

Many use the same route as Go, using one of those languages and when the
toolchain gets mature, those parts get re-writen.

All in all, I do like the language, now if we could get rid of those C
underpinnings...

~~~
santaclaus
Intel's C++11 support continues to be quite buggy. I'm still running into with
issues with Intel's support for auto type deduction and for uniform
initialization in non-obscure use scenarios.

~~~
pjmlp
Sorry I was updating the comment as you replied.

I never used it, but last time this discussion came up and I searched for
their support page many C++11 features were either TBD or GNU/Linux only.

Thanks for the feeback.

------
thepumpkin1979
I just tried to compile folly in OSX and it fails to compile with homebrew.
[https://github.com/facebook/folly/issues/400](https://github.com/facebook/folly/issues/400)

Also, Once I manage to compile folly and then wangle, what kind of database
drivers can I use in conjunction with this? Would I shoot myself in the foot
if I use this with libpq under CPUThreadPoolExecutor?

Same with Rust and dlang, I'm not sure how to apply the freedom to have
pluggable executor into something useful in real life, I think this is the
main reason Golang is killing it and it keeps getting better.

For now I have my money on Go but can't wait for
[http://www.ponylang.org/](http://www.ponylang.org/) to become stable.

Edit: Issue reported has been closed, I can now proceed to install wangle
[https://github.com/facebook/folly/issues/400](https://github.com/facebook/folly/issues/400)

Edit 2: Found another issue, this time installing wangle
[https://github.com/facebook/wangle/issues/37](https://github.com/facebook/wangle/issues/37)

~~~
zzzcpan
> what kind of database drivers can I use in conjunction with this?

Usually synchronous database drivers have to be reimplemented in an
asynchronous fashion to work with event loops. It's not very hard though,
could be as simple as adding jump tables and context structures into
synchronous functions.

Emulating asynchronous execution with a thread is ok too. You do that to
access filesystem anyway.

But if your first thought is about accessing a database server - you probably
don't need to go asynchronous at all.

~~~
jcoffland
MariaDB has an asynchronous C API.

~~~
infinite8s
libpq (Postgres's client library) has an asynchronous interface as well.

------
jfasi
The first thing that comes to mind after reading this is GRPC
([https://github.com/grpc/grpc](https://github.com/grpc/grpc)). That library
has the advantage of supporting just about every language, not just C++.

------
ausjke
Good to see C++ is gaining more visibilities these days, considering the
Oracle/Java combination I hope C++ can take away some JAVA dominance, at least
nobody is going to sue you over C++ APIs.

Failed to compile with CMake 2.8

    
    
        CMake Error at /usr/share/cmake-2.8/Modules FindPackageHandleStandardArgs.cmake:91 (MESSAGE):
        REQUIRED_ARGS (missing: FOLLY_INCLUDE_DIR  OLLY_LIBRARIES)
        Call Stack (most recent call first):
       /usr/share/cmake-2.8/Module/FindPackageHandleStandardArgs.cmake:252(_FPHSA_FAILURE_MESSAGE)
       cmake/FindFolly.cmake:23 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
       CMakeLists.txt:17 (find_package)

------
educar
Had to look up the meaning of wangle. "obtain (something that is desired) by
persuading others to comply or by manipulating events."

Does anyone know where facebook is coming up with all these words -
folly/wangle?

~~~
cgh
"Folly" is a relatively common English word. "Wangle" is less common but I
still see it from time to time.

What I find more interesting than the naming is FB's willingness to remove
features from Folly as they are made redundant by Boost or std. I'm
unaccustomed to such a lack of arrogance from a major player.

~~~
educar
Doesn't removing features break backward compatibility?

My favorite C++ library is Qt; they never remove public API for that reason.
In Qt world, we update regularly to get the bug fixes and other features. Last
thing I want to do is port my code to some other new API to update the
library.

~~~
mr_sturd
If it's a feature that has made it into the std/Boost libraries, we'll be
talking atomic utility functions which are being removed, in favour of calling
the std/Boost ones. Not actual API-level features.

------
vardump
So Wangle is (mostly) a protocol agnostic platform for building asynchronous
network clients and services in C++.

What transport layers are supported and can it be extended?

What I can gather, it only supports IPv4/IPv6 TCP or UDP transports. TLS is
also supported.

Notably, local pipes seem to be unsupported. Those can be sometimes useful for
performance and security/isolation reasons.

------
sametmax
Also, check out crossbar.io and the WAMP protocol, offering transparent, clean
and yet simple PUB/SUB & RPC accross languages, including C++, Python, PHP and
JS (node and yes, browsers).

~~~
Matthias247
WAMP is a protocol, Wangle is a framework that you can use to implement
protocols (like WAMP), crossbar is a broker (an application that implements
the protocol using a [python] framework. So it's not a direct comparison.

------
je42
does anybody know why this library is not based on (boost::)asio ?

~~~
vvanders
I'll take a shot in the dark and say they probably value their compile times.
Every boost library I've ever used has the tendency to pull in the world from
a single header and take forever to compile.

~~~
lhecker
ASIO can be used standalone with any C++11 compiler and the compile times are
quite good.

If I should make a guess then I'd say that the original author of that part of
the library either started before ASIO was standalone and/or simply has a
hatred for boost (which would be unwarranted), or he/she was simply more
experienced with libevent...

IMHO it's quite sad that they didn't use ASIO though as it's far more
extensive.

~~~
niekb
And interestingly, Chris Kohlhoff (asio author) is currently working on an
executors library / c++ standard proposal.

Other question: how would wangle compare to Cap'n Proto (as the post mentions
that wangle is an RPC framework, and is zero-copy)

~~~
dunkelheit
Zero-copy in capnproto docs and in this blog post actually mean different
things (the first means that serialized and in-memory representations of
capnproto messages are the same and the second means the absence of copying
between user space and kernel space when sending a file over the network).

------
chetanahuja
_" Wangle is heavily influenced by the JVM-based libraries Netty,"_

Stopped reading there. Have experience with using Netty in a java server
application and engineers dread being assigned a bug or enhancement in that
codebase. There's a tendency throw around the word "over-engineered" lightly
but netty is a real, live and inexplicably popular example of exactly what
that word means.

------
euyyn
I like that they explained the reasons behind the design decisions of the
library. Looking forward to the post about the RPC part!

------
averageJoeCoder
I'm wondering, how does C++ fare against Nodejs now, if this library is
implemented for creating servers?

~~~
ec109685
Node JS unfortunately doesn't have the notion of separate IO and CPU threads.

------
soconfused1
would this be useful for game development?

~~~
jfasi
I can't speak for Wangle, but I've used Google's version (GRPC) to implement
the networking transport for an N64 netplay hack[1] I wrote, and it was
awesome.

[1]: [https://github.com/water-works](https://github.com/water-works)

------
eva1984
Good that they mentioned Netty as inspiration

------
x5n1
In 2016 I would write networking and RPC in go.

~~~
thrownaway2424
Because you want to spend 10x as many CPUs?

~~~
x5n1
Mostly because it's easier, performant, and because of the nature of the
language it's less likely I would make a mistake doing anything in the
language compared to C++ or C.

