Closed dungvv-qsoft closed 2 months ago
Hi there - apologies for the long silence here. I'm not sure if this issue is still ongoing for you but I'd like to share my thoughts on it.
The high CPU usage when the SQS queue is enabled could be due to several reasons:
Firstly, the polling mechanism employed by the SQS consumer library could be a contributing factor. The frequent polling for new messages from the queue can be computationally intensive especially if the polling interval is set to a low value or if multiple queues are being polled simultaneously. Adjusting the pollingWaitTimeMs
configuration to a higher value or reducing the number of concurrent queue polls might help mitigate this issue.
Additionally, the batch size parameter batchSize
determines the maximum number of messages retrieved from the queue in a single batch. A larger batch size could potentially lead to higher CPU usage due to processing a greater number of messages concurrently. Experimenting with a lower batchSize value may help identify if this parameter is a significant factor in the increased CPU usage.
The way you configure the SDK could also impact CPU usage. For example, if you're creating a new SDK instance for each request, it can be inefficient and lead to higher CPU usage. Consider creating a shared instance of the SDK and reusing it across requests.
Hope it helps, John
Describe the bug
We are facing with an issue when turn on SQS on our server which is they use 100% of the available CPU compared around 60% when turn off queue (with the same traffic).
We run a profiler:
On the local server to be able to generate flame graph
With Queue enabled, It shows the initial spike is too high on resources occupied
This is non queue test, the initial spike is not too high compared with queue turning on:
Evidence:
.cpuprofile
and.text
report files for 2 cases (turn on/off queue when do stress test) https://github.com/dungvv-qsoft/cpu-profileOn our production server
Queue on: (CPU/Ram usage graph - From 3:20 - 3:30) Maximum average CPU usage is almost 100%
Queue off: (CPU/Ram usage graph - From 4:15 to 4:30) Maximum average CPU usage is around 60%
Environment Node version: v16.20.1 AWS-SDK version: v2.1106.0 SQS-Consumer version: v5.7.0
Snippet to initialize SQS consumer
Expected Behavior
CPU usage should be not high compared when turn off queue (with the same traffic)
Current Behavior
We are facing with an issue when turn on SQS on our server which is they use 100% of the available CPU compared around 60% when turn off queue (with the same traffic).
Reproduction Steps
Try to run a stress test on the api that using sqs-consumer lib -> The CPU usage increase significantly (It's not that high if we turn off the queue)
Possible Solution
No response
Additional Information/Context
No response
SDK version used
v2.1106.0
Environment details (OS name and version, etc.)
Fargate