How qihoo360/evpp works
Based on our review of the complete file tree and README, this project is the “evpp” C++ network library—a high-performance, event-driven framework that provides nonblocking TCP/UDP/HTTP servers and clients. It’s built using modern C++11 techniques and is heavily influenced by designs such as muduo and Golang. The project also includes client libraries that build on evpp (namely “evmc” for memcached and “evnsq” for NSQ) as well as a host of benchmarks, tests, examples, and integration with several third-party dependencies.
Main Components Identification
• Core evpp Library: At the center, illustrate the core modules which include:
• EventLoop and ThreadPool: The core reactor pattern that dispatches events.
• TCP/UDP/HTTP servers and clients: Modules that handle network I/O asynchronously.
• Supporting utilities: Buffer, DNS Resolver, Timer, and Invoke Timer.
• Application-Level Libraries: Represent “evmc” and “evnsq” as libraries or applications built on top of the core.
• 3rd Party and Dependencies: Include external components such as libevent, rapidjson, gtest, libhashkit, and platform-specific modules (such as win32code) as dependencies used within the evpp ecosystem.
• Build and Configuration: Elements like CMake scripts, Travis CI configuration, and Visual Studio projects help manage build and deployment.
Architectural Relationships and Interactions
• The Core evpp Library should be placed as the central block where all network components reside. Show that:
• The EventLoop is responsible for monitoring network events (using event watchers and libevent internally) and dispatching them to the appropriate handler.
• The ThreadPool or EventLoopThreadPool handles multi-threading, ensuring thread safety by confining event-related operations to their own threads.
• Callback mechanisms, in a functional style similar to Golang, are used to process data received on TCP/UDP sockets.
• Downstream Libraries “evmc” and “evnsq” are built on top of the evpp core, leveraging its asynchronous networking for specialized use cases (memcached client operations and NSQ messaging).
Design Patterns and Technical Stack
• Nonblocking, event-driven architecture at the heart of evpp. Note that:
• Components such as the TCP and HTTP servers follow a reactor pattern utilizing callbacks.
• Thread-safety is achieved through careful design where resources (like timers or events) are bound to the thread’s local storage.
• Use of modern C++11 features like lambda expressions to implement callbacks.
• Integration with the libevent library (even though evpp implements its own IO buffer and event add/del functions for driving performance).