search

Home  >  Q&A  >  body text

Reasons for CPU spike

I use an epoll model at the bottom of the communication. When epoll processes the request, it will hand it over to a thread pool for processing. The threads in the thread pool call the upper-layer service. The upper-layer service involves network communication, so It generally takes less than 10ms to process a request

Will such a model cause a sharp surge in CPU when traffic increases?

Background: My CPU usage is about 75% (traffic: 20~22Mbps); when the traffic increases to 25Mbps, the CPU is directly full. . This is not quite as expected, because the traffic increase is less than 15%, but the CPU surges by 25%.

PHP中文网PHP中文网2738 days ago626

reply all(1)I'll reply

  • 阿神

    阿神2017-05-16 13:29:40

    Let me briefly explain my point of view, just for your reference:
    1: First consider whether your request is IO-intensive or CPU-intensive? The IO intensive I am talking about refers to network IO that requires read and write to send and receive messages, that is, communication; CPU intensive, for example, requires calculations to produce results, and it takes a long time.
    2: If it is the first type of IO-intensive, then I don’t think you need to hand over all requests to the thread pool for processing. If there are no time-consuming disk IO operations such as reading and writing files, the thread pool may not even be used. In this way, the One loop per thread model is undoubtedly the most efficient. To put it bluntly, all reading and writing (reading and writing of network data, not reading files) and scheduled events are completed in a single EPOLL.
    3: If it is CPU-intensive, there is no problem in using thread_pool. It depends on the number of threads and code you configure.

    This question is difficult to answer without the actual environment. I am just trying to draw out some ideas and point out any mistakes.

    reply
    0
  • Cancelreply