# Question about key\_zone in proxy\_cache\_path

**URL:** <https://www.ruby-forum.com/t/question-about-key-zone-in-proxy-cache-path/208998>\
**Category:** NGINX\
**Created:** [July 2, 2011, 12:32pm UTC](https://www.ruby-forum.com/t/question-about-key-zone-in-proxy-cache-path/208998 "2011-07-02T12:32:49Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubstep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Post date:** [July 2, 2011, 12:32pm UTC](https://www.ruby-forum.com/t/question-about-key-zone-in-proxy-cache-path/208998/1 "2011-07-02T12:32:49Z")

</div>

Hi,

The wiki (1) states:  
“Zone size should be set proportional to number of pages to cache. The  
size of the  
metadata for one page (file) depends on the OS; currently it is 64 bytes  
for  
FreeBSD/i386, and 128 bytes for FreeBSD/amd64.”

So for 10.000 files i would need roundabout 1,3meg of key\_zone, and for  
example  
1mio files would need 122meg, is it that easy?

Another question would be, if i set it to big, will it hurt performance?  
I already  
had the key\_zone set to small so nginx complained about and it looked  
like it  
stopped serving new data.

Thanks and regards,  
Sven

1: [Module ngx\_http\_proxy\_module](http://wiki.nginx.org/HttpProxyModule#proxy_cache_path)

---

<div class="post-metadata">

**Author:** ![Sven\_SDarkmanS\_Mich](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e99b99/32.png) [@Sven\_SDarkmanS\_Mich](https://www.ruby-forum.com/u/Sven_SDarkmanS_Mich)\
**Post date:** [July 2, 2011, 3:39pm UTC](https://www.ruby-forum.com/t/question-about-key-zone-in-proxy-cache-path/208998/2 "2011-07-02T15:39:12Z")

</div>

Hello!

On Sat, Jul 02, 2011 at 12:32:15PM +0200, Sven ‘Darkman’ Michels wrote:

> The wiki (1) states:  
> “Zone size should be set proportional to number of pages to cache. The size of  
> the  
> metadata for one page (file) depends on the OS; currently it is 64 bytes for  
> FreeBSD/i386, and 128 bytes for FreeBSD/amd64.”
> 
> So for 10.000 files i would need roundabout 1,3meg of key\_zone, and for example  
> 1mio files would need 122meg, is it that easy?

Yes, except it’s not always trivial to calculate number of files  
you’ll have in cache. Aproach which is expected to work is to set  
maximum cache size and use max\_size / (average file size) as a  
reference point.

Note also that using proxy\_cache\_min\_uses will consume extra keys  
in keys\_zone for counting uses, even if actual files won’t be  
cached.

> Another question would be, if i set it to big, will it hurt performance?

It will consume extra memory, and hence may hurt performance.  
It’s unlikely will be noticeable though, unless you are  
memory-bound.

> I already had the key\_zone set to small so nginx complained  
> about and it looked like it stopped serving new data.

It will try to drop oldest file from cache and continue, though this  
may fail as well. So yes, working with full keys\_zone isn’t good.

Maxim D.

---

<div class="post-metadata">

**Author:** ![Sven\_SDarkmanS\_Mich](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e99b99/32.png) [@Sven\_SDarkmanS\_Mich](https://www.ruby-forum.com/u/Sven_SDarkmanS_Mich)\
**Post date:** [July 2, 2011, 11:26pm UTC](https://www.ruby-forum.com/t/question-about-key-zone-in-proxy-cache-path/208998/3 "2011-07-02T23:26:02Z")

</div>

Hi Maxim,

thanks for your quick reply (as usual :)!

Am 02.07.2011 15:38, schrieb Maxim D.:

> Yes, except it’s not always trivial to calculate number of files  
> you’ll have in cache. Aproach which is expected to work is to set  
> maximum cache size and use max\_size / (average file size) as a  
> reference point.

Ah, good point. I was more going to check how much file are at the  
backend server and use this, but they probably (for sure) won’t be  
all in the cache at the same time (at least at some setups).

> Note also that using proxy\_cache\_min\_uses will consume extra keys  
> in keys\_zone for counting uses, even if actual files won’t be  
> cached.

Ah, also a good catch. Currently i don’t use the min\_uses but i will  
put a remark in my config about it 🙂

> > Another question would be, if i set it to big, will it hurt performance?
> 
> It will consume extra memory, and hence may hurt performance.  
> It’s unlikely will be noticeable though, unless you are  
> memory-bound.

I don’t think i’m bound, its more like having 4GB of ram for a nginx  
dedicated box which will frontend for 3-4 servers which will have  
around 100meg of key\_zone size each. So maybe roundabout of 1GB is  
used by nginx itself and the rest will be for caching etc. (no other  
stuff will run on the box).

> > I already had the key\_zone set to small so nginx complained  
> > about and it looked like it stopped serving new data.
> 
> It will try to drop oldest file from cache and continue, though this  
> may fail as well. So yes, working with full keys\_zone isn’t good.

Ok, then i will try to monitor it and adjust the values if needed.  
I just would like not the have the cache as another point of failures  
for such things (best would be if something with caching fails to just  
proxy the request…).

Thanks a lot!

Regards,  
Sven
