# Geo-ip latency, or lazy load variables

**URL:** <https://www.ruby-forum.com/t/geo-ip-latency-or-lazy-load-variables/220832>\
**Category:** NGINX\
**Created:** [June 21, 2012, 5:25pm UTC](https://www.ruby-forum.com/t/geo-ip-latency-or-lazy-load-variables/220832 "2012-06-21T17:25:24Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![aris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/258eb7/32.png) [@aris](https://www.ruby-forum.com/u/aris)\
**Post date:** [June 21, 2012, 5:25pm UTC](https://www.ruby-forum.com/t/geo-ip-latency-or-lazy-load-variables/220832/1 "2012-06-21T17:25:24Z")

</div>

Hi,

We are testing the Geo-IP module with the city and country databases and  
noticed a decrease in performance for all locations on the server. It  
seems that whenever the geoip\_country and geoip\_city directives are  
specified the module looks up the geo variables for the IP address even  
if the variables are not used inside the location. We did the simplest  
test with Apache Bench against two identical servers on a location that  
doesn’t use the geo variables. One server has the geo databases loaded  
and the other has them commented out.

We did several tests, here are the averages for a few thousand HTTP  
requests with concurrency level 30:

Without geo databases loaded:  
Time per request: 12.260 [ms]  
Requests per second: 2446.91 [#/sec]

With geo databases loaded:  
Time per request: 35.352 [ms]  
Requests per second: 848.60 [#/sec]

Is it possible to lazy lookup the values for the geo variables when they  
are requested?

Thanks,  
Markus

---

<div class="post-metadata">

**Author:** ![mflive](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e99b99/32.png) [@mflive](https://www.ruby-forum.com/u/mflive)\
**Post date:** [June 21, 2012, 5:28pm UTC](https://www.ruby-forum.com/t/geo-ip-latency-or-lazy-load-variables/220832/2 "2012-06-21T17:28:19Z")

</div>

Hey Markus,

How does your config look like? I recall the geoip module costing more  
depending on how the configuration is designed

Thanks,  
Payam

---

<div class="post-metadata">

**Author:** ![mflive](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e99b99/32.png) [@mflive](https://www.ruby-forum.com/u/mflive)\
**Post date:** [June 21, 2012, 5:35pm UTC](https://www.ruby-forum.com/t/geo-ip-latency-or-lazy-load-variables/220832/3 "2012-06-21T17:35:56Z")

</div>

Hello Payam,

Our configuration is quitelarge and consists of several includes for  
servers and maps. Could you perhaps be more specific so i can confirm  
whether our config is designed so the module is more costly? And do you  
happen to know a work-around or solution for this case?

We have the following modules enabled and disabled:

–with-http\_stub\_status\_module   
–with-http\_geoip\_module   
–with-http\_ssl\_module   
–without-http\_autoindex\_module   
–without-http\_browser\_module   
–without-http\_uwsgi\_module   
–without-http\_userid\_module   
–without-http\_upstream\_ip\_hash\_module   
–without-http\_split\_clients\_module   
–without-http\_scgi\_module   
–without-http\_empty\_gif\_module   
–without-http\_geo\_module   
–without-http\_memcached\_module   
–add-module=…/modules/agentzh-chunkin-nginx-module-85eca98   
–add-module=…/modules/agentzh-headers-more-nginx-module-3580526   
–add-module=…/modules/simpl-ngx\_devel\_kit-24202b4   
–add-module=…/modules/agentzh-set-misc-nginx-module-e6a54ab   
–add-module=…/modules/gnosek-nginx-upstream-fair-5f6a3b7   
–add-module=…/modules/cep21-healthcheck\_nginx\_upstreams-16d6ae7   
–add-module=…/modules/agentzh-echo-nginx-module-080c0a1

Thanks,  
Markus

-----Original message-----

---

<div class="post-metadata">

**Author:** ![mflive](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e99b99/32.png) [@mflive](https://www.ruby-forum.com/u/mflive)\
**Post date:** [June 21, 2012, 6:50pm UTC](https://www.ruby-forum.com/t/geo-ip-latency-or-lazy-load-variables/220832/4 "2012-06-21T18:50:44Z")

</div>

Maxim,

After i read your e-mail i tested again and there was a clear difference  
in performance but more repeated tests showed no difference in  
performance at all. Something else must be acting up.

Thanks,  
Markus

-----Original message-----

---

<div class="post-metadata">

**Author:** ![mflive](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e99b99/32.png) [@mflive](https://www.ruby-forum.com/u/mflive)\
**Post date:** [June 21, 2012, 5:59pm UTC](https://www.ruby-forum.com/t/geo-ip-latency-or-lazy-load-variables/220832/5 "2012-06-21T17:59:18Z")

</div>

Hello!

On Thu, Jun 21, 2012 at 03:24:50PM +0000, Markus J. wrote:

> With geo databases loaded:  
> Time per request: 35.352 [ms]  
> Requests per second: 848.60 [#/sec]
> 
> Is it possible to lazy lookup the values for the geo variables when they are  
> requested?

Geoip module variables are looked up in a database only when  
actually used.

Maxim D.
