I already know about Facebook’s wangle, but it seems to rely more on it, the documentation is not very complete, and it doesn’t seem to have gained much popularity.

From a functional point of view, the only library that can be compared with netty, which encapsulates the underlying API, can be cross-platform, and provides a concurrent operating environment, is boost::asio. From the perspective of widespread use, C++ does not have a library comparable to netty. After all, Java only has netty. For many C++ projects, you can use C network libraries such as libevent (the libraries of C are basically POSIX API encapsulation, and they are not provided. Concurrent operating environment of netty’s executor or asio’s strand). Simply compare the advantages of asio and netty:netty: reactor mode. Easy to use, simple and easy to use. Defines the basic operation process of a server program. A series of APIs in the process are provided and can be used directly. And this set of procedures can basically cover most of the actual needs. Disadvantages: Not flexible enough, assuming a basic operation process of the server. The basic assumption is: the server processing message logic comes in a pipeline manner, and the thread processing channel messages is fixed and will not change. If you want to use your own thread to concurrently use a certain part of the logic, add executorasio to the pipeline. Advantages: flexibility and no unachievable requirements. With the strand design, you can control the granularity of concurrency at will. After all, it is just a queue on the ioservice. And netty’s executor is a real thread. The design of call chain (netty can also be used for some tasks, but netty is not implemented from a design point of view, but it can be done, not like asio is designed and implemented as a functional point) is very easy to use, some Appropriate functions are simple to implement and aesthetically pleasing. The design of io_serivce can be used in environments that do not have its own running thread, such as clients, or even embedded devices (anyway, the design takes into account, depending on whether you can compile it), this is also the name of the asio library called asynchronous The reason for IO, it is too versatile. Disadvantages: proactor mode, difficult to get started. Without making any assumptions about the server running process, you need to decide a process according to the project needs (for example, whether a connected IO message can be processed by multiple threads, these can be determined by yourself). Unlike netty, which basically comes with a bootstrap, it can directly process the received data (still decoded). No buffer is implemented, only a buffer wrapper, you need to write a readwritebuffer yourself (this is a bit painful). Although you can use free function async_write directly without buffer, you need to handle interleaving write yourself. Using sharedptr to manage memory, the core code part is more mind-blowing. For example, we must carefully consider weakptr and the ownership of sharedptr (of course this is not a problem with asio). In general, the language characteristics of these two libraries are very obvious. Netty, you can think of everything you can use, API, class a bunch of direct use. asio, provides a set of well-designed reusable components, complex functions, you have to put it together. In the past few years, asio has been proposing to enter the standard library, but due to the efficiency of the C++ committee, so far, I don’t know when it can enter std. The latest proposal: As for the wangle you mentioned, I personally think that there is no brain The libraries for translating libraries in other languages ​​are not quite on the table. It’s nothing to simply use, but there is no design rationality.

zhiwo

By zhiwo

0 0 vote
Article Rating
Subscribe
Notify of
guest
11 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments
helpmekim
8 months ago

As a universal asynchronous client. Currently supports http, redis, mysql and kafka protocols. Easily build highly efficient spiders. Implement custom protocol client/server and build your own RPC system. srpc is based on it and open source as an independent project. Supports protocols such as srpc, brpc and thrift. Build asynchronous task flow, support commonly used series and parallel connections, and also support more complex DAG structures. Use as a parallel computing tool. In addition to network tasks, we also include the scheduling of computing tasks. All types of tasks can be put into the same stream. Used as a file asynchronous IO tool under Linux system, the performance exceeds any standard call. Disk IO is also a task. Realize any high-performance and high-concurrency back-end service with a very complex relationship between computing and communication. Build a microservice system. The project has built-in service management and load balancing functions.

heloword
8 months ago

I feel that it is still related to the ecology of C++. You will find that Java, Go, and Python have their own very mature ecology, package management, and various out-of-the-box frameworks and libraries. For example, back-end development frameworks such as Spring and Springboot in Java are widely used, but there is not a widely used rpc in C++. The only famous ones may be grpc and brpc, but large companies will not use these things. They are all made by themselves. For example, Goose Factory has several rpc and svrkit of WeChat. Since C++ is about equal to no package management, if you reference other people’s libraries, you have to download the source code. The key is that sometimes you need a very small function, but you have to package the entire project and the third-party libraries it depends on. , To be honest, this is a very disgusting thing. You said only download the compiled binary link? Then C++ often has various disgusting ABI incompatibility issues. And many Cppers not only adjust libraries but also write libraries. C++ players don’t like bloated family buckets, so those so-called big frameworks are not popular in C++. To download hundreds of thousands of lines of code for a few hundred lines of functionality, it also requires a bunch of third-party dependencies…Any programmer who is obsessed with cleanliness may want to make his own wheels. But in Java, you only need to add a few lines in Maven to remember, which is convenient for a batch, and you only need to import Python…..The cost of quoting the library is very low. In fact, there are many powerful network libraries in C++, such as asio, ace, zeromq, etc., but no matter how powerful any library is, as long as it is not in the C++ standard library, it cannot be widely used. In addition, there is actually a proposal for a C++ network library, see this N4478, but to be honest, I personally feel that even if it is out, it may not be widely used. After all, Cpper loves to make wheels, and many even STL builds their own.

helpyme
8 months ago

Java Netty is more popular than C++ network libraries for these reasons: Netty takes advantage of the cross-platform capabilities of JVM. Netty itself hardly needs to consider what CPU architecture or operating system it is on, but only needs to focus on the abstract network middle layer. And C++ network libraries should be considered There are too many low-level details. Different low-level platforms have great differences. Many libraries do not consider a very complete cross-platform. Netty only needs to release a few M jar package, which is very convenient to import and use. And C++ If you want to release the library, you must either release the source code or release the static/dynamic library. To release the source code, you must consider how to build it, whether it can be well compatible with the build method used by the user; while publishing the static/dynamic library is easy to use, but it must Considering each CPU architecture, each operating system, and even each compiler and each compilation mode must generate a copy, various combinations are very scary. Java’s code style is more consistent, so it is easy to make everyone agrees Libraries. And C++ has many programming styles, and everyone is only used to a certain subset of C++, so there are different levels of acceptance when selecting libraries, which makes it difficult to produce a uniformly recognized library.

sina156
8 months ago

I am curious why no one mentioned the academic model ACE in the answer. Although its coding style is quite different from boost::asio (the former uses a large number of pure virtual functions to achieve diversity while the latter relies on templates and multiple inheritance), and it is huge, it is A very comprehensive network programming library. Here are some known advantages. ACE provides a wide range of cross-platform support, whether it is win or posix-supported Linux and Unix, or even some serial devices. ACE encapsulates network-related content from basic containers to multi-threaded multi-process management cache queues Manage memory management, etc. ACE supports a variety of network communication protocols, from serial communication to UDP/TCP to ICMP, etc. ACE implements multiple network concurrent requests. Boost asio is mainly based on Proactor, while ACE provides both Proactor and Reactor. Encapsulation can also be freely combined and selected for the underlying API (you can configure the underlying event processing interface that needs to be used. For example, on some BSD systems, you can choose kqueue or epoll as the underlying interface and you should use different classes) based on pure virtual functions The realization reduces the difficulty of template errors. Of course, the disadvantage is that it is too large. Compared with boost, the internal infrastructure of the freak is too much. It is not easy to take out the part and use it alone. Basically, the infrastructure of all servers is written. Once and I didn’t use the standard library, even the linked list was written by myself, which hindered its development to a certain extent. The pure virtual function increased the overhead. It seems that the speed is a bit slower than asio.

yahoo898
8 months ago

Many people use C++ not object-oriented, but type-oriented. The type information can only be processed during compilation, which leads to cumbersome header files and poor experience. In other words, C++ does not have a programming specification that everyone recognizes. Every team is tailoring and restricting C++ and formulating its own specifications. Almost all specifications do not want macros to fly in the sky, and include is just a macro, which leads to the introduction of third parties. The library must be very careful.

leexin
8 months ago

If you just want to use it, Libevent and asio are almost enough
If you want to learn, Chen Shuo has an open source project muduo, which is good for learning. Then there are the network modules of various open source projects, such as skynet and nginx. .

greatword
8 months ago

grpc asio libevent libuv
C++ is written less, and then divided into these few, and then there are some niche libraries, and then such as redis and nginx, which implement asynchronous event libraries internally, and then the number of each used is very small.

loveyou
8 months ago

360’s evpp understands that although it seems to have stopped maintenance, the internally implemented buffer is very similar to the databuffer implemented by Netty itself, and it is very easy to use when doing sub-packaging and sticking.

strongman
8 months ago

You can try poco. The POCO C++ Libraries are powerful cross-platform C++ libraries for building network- and internet-based applications that run on desktop, server, mobile, IoT, and embedded systems.

Last edited 8 months ago by stockin
stockin
8 months ago

libuv has a lot of pits, but it’s easy to use. There is too little domestic information. But by reading the source code and looking at the package of nodejs, I still figured it out. Very good framework. Try netplus, learn from and implement a lot of concepts and ideas in netty, implemented in c++11.

11
0
Would love your thoughts, please comment.x
()
x