"Go" open source C/E + + network library comparison

Source: Internet
Author: User
Tags epoll

In the open-source C + + network library, commonly used in a few, the industry's highest visibility, it should be ace, but a heavyweight big, lightweight with libevent, Libev, and boost ASIO.

ACE is a large-scale middleware product, the code is about 200,000 lines, too ambitious, a bunch of design patterns, the structure of a layer after layer, when using, depending on the situation, see you from that layer to use. Support cross-platform.

The boost ASIO is an asynchronous IO library that encapsulates common operations on sockets and simplifies the development of socket-based programs. Support cross-platform.

Libevent is a C-language network library, the official main support is the class Linux operating system, the latest version added to the Windows IOCP support. Since IOCP is asynchronous IO, with the poll model under Linux, the Epoll model, and the kqueue of FreeBSD, these synchronization models are completely inconsistent in usage, so the use of the method is not the same as the reactor and proactor patterns in Ace, Use needs to change the way of thinking. If there is no specific requirement for performance, then using the Select model in libevent for cross-platform operations, the Select model can span systems such as Windows, Linux, Unix,solaris, and so on.

Libev is a C language, only support the Linux system library, I previously studied the time only encapsulated the Epoll model, do not know whether the new version has been improved. The use method is similar to libevent, but very concise, the code amount is the least one library, also thousands of lines of code. Obviously this kind of code cross-platform certainly is unable to support, if you only need to run under Linux, then use this library is also possible.


Ace Network Library in use, has been the memory of the management of the confused, the allocation of memory needs to be released where not know, Ace is worthy of a research library, you can say that the package in the design mode of the book listed in the model is implemented in the code, used to feel like in Java, If you want to use ACE as your network library, do not just use it as a network library, you have to use it as a framework, if you only want to use its network library, it is not necessary to use ACE, because it is too large, learning is too laborious. But you think of it as a framework to use, you will feel really good, there are things, such as thread pool, memory pool, timers, recursive locks, etc., are very convenient. Boost ASIO, more intuitive in memory management. The following is a simple comparison to ace.

1. Hierarchical Architecture:
The ACE is the C-style OS adaptation layer, the previous layer is based on the C + + wrap class, the next layer is some framework (accpetor, Connector,reactor,proactor, etc.), the top layer is the framework service.
Boost.asio is similar to this, the bottom layer is the OS adaptation layer, some template classes on the previous layer, and then the parameterization of the template class (TCP/UDP), and then the next layer is the service, it has only one framework for Io_service.
Livevent the abstraction of a multiplexed model under different operating systems, optionally using different models and providing services through event functions.

2. Scope of involvement:
Ace includes log, IPC, thread pool, shared memory, config service, recursive lock, timer, etc.
ASIO only involves sockets, providing simple threading operations.
Libevent only provides a simple network API encapsulation, thread pool, memory pool, recursive lock, etc. all need to be implemented by themselves.

3. Design mode:
ACE is mainly used in reactor,proactor and so on.
And ASIO is mainly used in Proactor.
Libevent for reactor mode

4. Thread Scheduling:
Ace's reactor is single-threaded scheduling, Proactor supports multi-threaded scheduling.
ASIO supports single-threaded and multithreaded scheduling.
Libevent's thread scheduling requires itself to register a different event handle.

5. Event Dispatch Processing:
The ACE is primarily to register the handler class when the event is dispatched, calling its handler virtual hook function. Implements virtual functions for classes such as Ace_handler/ace_svc_handler/ace_event_handler.
ASIO is a Hanlder event dispatch based on a function object. Any function can become hanlder, less maintenance of a bunch of virtual tables, and better scheduling than aces.
The Libevent implements event distribution based on the registered event callback function.

6. How to publish:
Ace is open source free and does not rely on 3rd party libraries, and when used by a general application, it publishes dynamic libraries in a dynamically linked manner.
ASIO is open source free, relying on boost, application use as long as the include header file, do not need a dynamic library.
Libevent is free for open source, and is generally compiled for use in static libraries.

7. Portability:
ACE supports a variety of platforms, portability is not a problem, it is said that socket programming under Linux has a lot of bugs.
ASIO supports multiple platforms, portability is not a problem.
Libevent mainly supports the Linux platform, the FreeBSD platform, the other platform through the Select model to support, the efficiency is not too high.

8. Difficulty in development:
Developing applications based on Aces requires a high level of programmer requirements, and the framework must be well understood. In the framework of development, often new out of an object, do not know where to release good.

Developing applications based on ASIO requires programmers to familiarize themselves with function objects, function pointers, and boost::bind in the Boost library. Memory management control aspects.

Based on libevent development and application, it is relatively easy, we can refer to memcached this open source application, which uses libevent this library.

"Go" open source C/E + + network library comparison

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.