Skip to main content

A High-Performance C++ Server Engine for Modern Backend Systems

·355 words·2 mins
C++ Server Engine Asynchronous High Performance Backend Development
Table of Contents

Sogou’s high-performance C++ server engine powers nearly all of its backend services—including search, cloud input method, and advertising—processing over ten billion requests per day. Designed with simplicity and elegance, this enterprise-grade engine satisfies the majority of C++ backend development needs with exceptional performance and flexibility.

🌟 What You Can Build with This Engine
#

🚀 Quickly Create an HTTP Server
#

#include "stdio.h"
#include "workflow/WFHttpServer.h"

int main()
{
    WFHttpServer server([](WFHttpTask *task) {
        task->get_resp()->append_output_body("<html>Hello World!</html>");
    });

    if (server.start(8888) == 0) {  // start server on port 8888
        getchar(); // press "Enter" to end.
        server.stop();
    }

    return 0;
}

Beyond simple web servers, the engine enables a wide range of backend development scenarios:

  • Universal asynchronous client supporting http, redis, mysql, and kafka.
  • High-performance web spiders for large-scale crawling.
  • Custom protocol clients/servers for building your own RPC ecosystem.
  • srpc, built on this engine, supports srpc, brpc, and thrift.
  • Asynchronous task flows including series, parallel, and complex DAG (Directed Acyclic Graph) structures.
  • Parallel computing, integrating both network and compute tasks into unified flows.
  • Asynchronous file IO on Linux with performance beyond standard system calls.
  • High-concurrency backend services with complex computation and communication patterns.
  • Complete microservices systems with built-in service governance and load balancing.

📐 System Design Overview
#

At its core, the engine follows a simple philosophy: Program = Protocol + Algorithm + Task Flow

🔧 Basic Tasks, Task Factory & Composite Tasks
#

  • Six foundational task types: Communication, File IO, CPU, GPU, Timer, and Counter.
  • All tasks are created via a centralized Task Factory and auto-recycled when callbacks finish.
  • Server tasks are specialized communication tasks generated by the framework.
  • Most user-created tasks are composite tasks, abstracting away internal complexity.

⚙️ Asynchronicity with std::function
#

  • Fully asynchronous—no coroutine dependency and minimal thread blocking.
  • All operations run non-blocking, ensuring high throughput.
  • Semi-synchronous interfaces exist but are not central to the engine’s design.

🧹 Smart Memory Recycling
#

  • Tasks automatically free memory after their callback.
  • Tasks that won’t run must be explicitly canceled using dismiss.
  • Task-internal data (e.g., HTTP responses) are recycled, so developers should extract required data using std::move().

🔗 Open-Source Repository
#

Explore the source code and documentation:

https://github.com/sogou/workflow

Related

How to Perform UDP Ping in Linux
·431 words·3 mins
Linux UDP Ping Network Troubleshooting
Scheduling Regular MySQL Backups on Linux
·415 words·2 mins
Linux MySQL Backup Cron
Understanding Peripheral Drivers Through the Linux Kernel Device Model
·725 words·4 mins
Linux Kernel Device Drivers Kobject Device Model Embedded Linux