Home >PHP Framework >Workerman >How does workerman achieve high concurrency?

How does workerman achieve high concurrency?

(*-*)浩
(*-*)浩Original
2019-12-05 10:21:364826browse

How does workerman achieve high concurrency?

The concept of concurrency is too vague. Here we use two quantifiable indicators: the number of concurrent connections and the number of concurrent requests.

The number of concurrent connections refers to how many TCP connections the server maintains at the current moment, and it does not matter whether there is data communication on these connections. (Recommended study: workerman tutorial)

For example, a message push server may maintain millions of device connections. Since there is little data communication on the connection, the load on this server It may be almost 0, and as long as there is enough memory, you can continue to accept connections.

Video Course Recommendation→: "Concurrency Solution for Tens of Millions of Data (Theoretical and Practical)"

Concurrent Request The number is generally measured by QPS (how many requests the server handles per second), but the number of TCP connections on the server at the current moment is not of great concern. For example, if a server has only 10 client connections, and each client connection has 1W requests per second, then the server needs to be able to support at least 10*1W=10W throughput per second (QPS).

Assume that 10W throughput per second is the limit of this server. If each client sends 1 request to the server per second, then this server can support 10W clients.

The number of concurrent connections is limited by the server memory. Generally, a 24G memory workerman server can support approximately 120W concurrent connections.

The number of concurrent requests is limited by the server’s CPU processing capability. A 24-core Workerman server can achieve a throughput of 45W per second (QPS). The actual value varies depending on business complexity and code quality. .

Note

The event or libevent extension must be installed in high concurrency scenarios. In addition, the Linux kernel needs to be optimized, especially the limit on the number of files opened by a process.

Stress test data

Only the QPS data reference of Workerman stress test is provided here.

Test environment:

System: debian 6.0 64-bit

Memory: 64G

cpu: Intel(R ) Xeon(R) CPU E5-2420 0 @ 1.90GHz (2 physical CPUs, 6 cores, 2 threads)

Workerman: Start 200 Benchark processes

Stress test script :benchmark

Business: Send and return hello string

Normal PHP (version 5.3.10) stress test

Short connection (each request After completion, close the connection and request to establish a new connection next time):

Conditions: The stress test script opens 500 concurrent threads to simulate 500 concurrent users, each thread connects to Workerman 10W times, and each connection sends 1 Request

Result: Throughput: 2.3W/S, cpu utilization: 36%

Long connection (the connection is not closed after each request, and the next request will continue to reuse this Connection):

Conditions: The stress test script opens 2000 concurrent threads to simulate 2000 concurrent users, each thread connects to Workerman once, and each connection sends 10W requests

Result: Throughput: 36.7W/S, cpu utilization: 69%

Memory: Each process memory is stable at 6444K, no memory leaks

The above is the stress test data of php5.3 version, if With php7, the performance will be improved again by about 40%.

HHVM environment stress test

Short connection (close the connection after each request is completed, and establish a new connection next time the request is made):

Conditions: The stress test script opens 1000 concurrent threads to simulate 1000 concurrent users, each thread connects to Workerman 10W times, and each connection sends 1 request

Result: Throughput: 3.5 W/S, cpu utilization: 35%

Long connection (the connection is not closed after each request, and the connection will continue to be reused for the next request):

Conditions: The stress test script is opened at 6000 Concurrent threads simulate 6000 concurrent users, each thread connects to Workerman once, and each connection sends 10W requests

Results: Throughput: 45W/S, cpu utilization: 67%###### Memory: The memory of each process in the HHVM environment is stable at 46M, with no memory leaks###

The above is the detailed content of How does workerman achieve high concurrency?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:How to use workermanNext article:How to use workerman