We are using kong api gateway as a single gateway for all apis. we are facing latency issue with few of our api's (1500-2000ms). later when we checked, latency was being created because of the "rate limiting" plugin. When we disable the plugin, latency improves and the response is same as what we get directly from IP (close to 300ms approx). I m trying to setup redis node to cache database queries, I m not sure how we can configure kong to read from redis itself. how we can cache the database queries to redis node. We are using postgresql for kong.
2 Answers
I think maybe you are trying to do a couple different things at once.
First, rate-limiting: what is the value for your config.policy
parameter? The Kong documentation has three values: "local
(counters will be stored locally in-memory on the node), cluster
(counters are stored in the datastore and shared across the nodes) and redis
(counters are stored on a Redis server and will be shared across the nodes)."
If you are seeing high latency, and your config.policy
is set to cluster
or redis
, it might be due to latency between Kong and postgres/redis (depending on what policy you're using). If you are using rate-limiting just to prevent abuse, using the 'local' policy is faster. (There's more about this at the Kong documentation.)
The other question is about caching: Kong Enterprise has a built-in caching plugin, but for Kong Community, since it's built on top of Nginx, you can do caching with Nginx. This link might help you.

- 368
- 4
- 15
-
Thanks @esperluette In rate-limiting plugin policy was set to cluster which was creating lot of latency. later I changed it to local which reduced the latency to 300ms. I will check provided link for caching from nginx. Thanks again!! – Divy Sep 05 '18 at 01:05
-
thanks for letting me know this worked for you! I see you're new to Stack Overflow, welcome! If you could mark this answer as 'accepted' (click on the checkmark) that would be great! (More info about accepted answers here: https://stackoverflow.com/help/someone-answers) – esperluette Sep 06 '18 at 14:07
There is a community custom plugin out there that enables the use of caching with redis without the need to use the Kong Enterprise -> https://github.com/globocom/kong-plugin-proxy-cache
Maybe you could combine that with rate limiting to achieve the desired latency performance or use this plugin as inspiration.

- 2,042
- 16
- 28