leev / ngx_http_geoip2_module

Nginx GeoIP2 module
BSD 2-Clause "Simplified" License
953 stars 182 forks source link

high cpu usage on heavy traffic #107

Open Vladislavik opened 2 years ago

Vladislavik commented 2 years ago

Hi is there any advice or other when i try to use this module on a high load server nginx starts to consume a lot of cpu is there any caches for the found ip data in the database not to look it up again on the next request from the same ip or any other recommendation to reduce cpu usage. Almost on ddos it is 100% CPU usage with nginx...

leev commented 2 years ago

I would start with generating a flamegraph of the server when it's not under attack and when it is under attack. That will help with identifying where the CPU increase is and if it is in fact due to geo IP look up.

Right now, there is no caching of geoip information between requests.

tobias992 commented 1 year ago

Hello @leev,

first thank you for this nice nginx module. We also use it on every our servers for country blocking and in case of ddos attacks. I really have no idea how to program a nginx module but there is a efficient way to improve the performance of this module?

How this module works in detail?

  1. The geoip database is loaded into RAM on nginx start/reload
  2. Every nginx request is checked from database on local disk

If 2, maybe it could improve the performance to copy the geoip database into tmpfs directory because of faster RAM?

Because we also can see high cpu load on high traffic servers with active geoip2 module. We also would pay for a nice performance update.