Hawxby
Hawxby

Reputation: 2804

Nodejs + Redis performance on Azure

We have an nodejs application sat on Azure using Redis to cache data from various external endpoints so we don't exhaust API limits unnecessarily and to keep page render times fast despite some extremely slow endpoints.

As the application has scaled we've started to get some issues with Redis performance. I put some logging around get setex calls to track response times and in some cases they can be over 500ms per call. However according to the Azure dashboard redis server load is fine. enter image description here

As a bit of background the application is hosted in 3 regions with an app service and redis cache in each. There can be up to 20 app service hosts per region. There is no cross communication between the redis caches as there is no requirement for the data to be in sync across regions, and to allow for an entire region to fall with no loss in service. We create a single redis client per running process and that is shared.

We're running nodejs 14 and using ioredis 4.27.6 and our config is

const client = new Redis({
  port,
  host: server,
  password: auth,
  maxRetriesPerRequest: 2,
  tls: {},
  enableAutoPipelining: true,
  enableOfflineQueue: true,
  connectTimeout: 30000,
});

An some example of the slow logging

2021-10-10T09:10:53.369997968Z warn: redis slow redis {
2021-10-10T09:10:53.370045469Z   "command": "setex",
2021-10-10T09:10:53.370053669Z   "diffMs": 611,
2021-10-10T09:10:53.370065369Z   "key": "getRolloutValue(product_over)"
2021-10-10T09:10:53.370070169Z }
2021-10-10T09:10:53.376250740Z warn: redis slow redis {
2021-10-10T09:10:53.376285841Z   "command": "get",
2021-10-10T09:10:53.376293841Z   "diffMs": 487,
2021-10-10T09:10:53.376303141Z   "key": "getDataForProduct(enus, XXXX)",
2021-10-10T09:10:53.376328241Z   "sizeStr": "8.93 KB"
2021-10-10T09:10:53.376332641Z }
2021-10-10T09:10:53.377994061Z warn: redis slow redis {
2021-10-10T09:10:53.378021261Z   "command": "get",
2021-10-10T09:10:53.378028661Z   "diffMs": 488,
2021-10-10T09:10:53.378037261Z   "key": "getDataForProduct(enus, XXXX)",
2021-10-10T09:10:53.378045661Z   "sizeStr": "5.45 KB"
2021-10-10T09:10:53.378049961Z }

Has anyone experienced this or have any advice regarding configuration on how we can improve performance?

Many thanks.

Upvotes: 0

Views: 508

Answers (1)

Renshaw
Renshaw

Reputation: 1155

I guess the slow reason is not redis self, but from Operating System Context Switching, the cpu was occupied by other processes. You can try run redis in a isolated environment, without any other applications.

Upvotes: 0

Related Questions