# Problem with large static files

**URL:** <https://www.ruby-forum.com/t/problem-with-large-static-files/215023>\
**Category:** NGINX\
**Created:** [December 19, 2011, 7:22pm UTC](https://www.ruby-forum.com/t/problem-with-large-static-files/215023 "2011-12-19T19:22:57Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [December 19, 2011, 7:22pm UTC](https://www.ruby-forum.com/t/problem-with-large-static-files/215023/1 "2011-12-19T19:22:57Z")

</div>

I have a strange problem with slow load of relatively large files. On a  
domain without proxy (designed for serving static files), the request  
time (as monitored by access log $request\_time) for an simple jpg image  
file of 5KB is 0.000s (seems to be shorter than 1ms). Thus, one expect  
to load an image file of 15KB within 3ms, but surprisingly it takes  
about 600ms. A static file of 15KB is not big at all; but there should  
be a threshold which leads to this slow down upon slightly increasing  
the file size.

Posted at Nginx Forum:

> **[Problem with large static files](https://forum.nginx.org/read.php?2,220272,220272#msg-220272)**
>
> I have a strange problem with slow load of relatively large files. On a domain without proxy (designed for serving static files), the request time (as monitored by access log $request\_time) for an simple jpg image file of 5KB is 0.000s (seems to be...

---

<div class="post-metadata">

**Author:** ![etrader](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/b5e925/32.png) [@etrader](https://www.ruby-forum.com/u/etrader)\
**Post date:** [December 19, 2011, 9:46pm UTC](https://www.ruby-forum.com/t/problem-with-large-static-files/215023/2 "2011-12-19T21:46:25Z")

</div>

Hello!

On Mon, Dec 19, 2011 at 01:22:15PM -0500, etrader wrote:

> I have a strange problem with slow load of relatively large files. On a  
> domain without proxy (designed for serving static files), the request  
> time (as monitored by access log $request\_time) for an simple jpg image  
> file of 5KB is 0.000s (seems to be shorter than 1ms). Thus, one expect  
> to load an image file of 15KB within 3ms, but surprisingly it takes  
> about 600ms. A static file of 15KB is not big at all; but there should  
> be a threshold which leads to this slow down upon slightly increasing  
> the file size.

The $request\_time of 0.000s isn’t something real. Instead, it  
means that nginx wasn’t going through event loop while processing  
the request. It was able to read the request from client, read  
data from disk and send all data to socket buffer without  
overflowing it. As nginx only updates it’s idea about current  
time once per event loop iteration, the above results in  
$request\_time of 0.000s in logs. Real time spent may  
significantly differ if you are disk-bound and reading from disk  
blocks for a long time (and you aren’t using AIO).

Try looking into your disk subsystem stats, most likely it will  
explain things.

Maxim D.

---

<div class="post-metadata">

**Author:** ![etrader](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/b5e925/32.png) [@etrader](https://www.ruby-forum.com/u/etrader)\
**Post date:** [December 20, 2011, 7:01am UTC](https://www.ruby-forum.com/t/problem-with-large-static-files/215023/3 "2011-12-20T07:01:52Z")

</div>

Thanks for very useful description, Maxim!  
Actually, I suspected the nature of 0.000 request time; but what makes  
me wonder is that it takes only 3ms to process a relatively php file  
with output of 5KB. Then, why reading a static file of 15KB should take  
600ms? If it is normally the case, isn’t it better to save images as  
data instead of file? PHP should process a base64 string faster.

Posted at Nginx Forum:

> **[Re: Problem with large static files](https://forum.nginx.org/read.php?2,220272,220284#msg-220284)**
>
> I have a strange problem with slow load of relatively large files. On a domain without proxy (designed for serving static files), the request time (as monitored by access log $request\_time) for an simple jpg image file of 5KB is 0.000s (seems to be...

---

<div class="post-metadata">

**Author:** ![etrader](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/b5e925/32.png) [@etrader](https://www.ruby-forum.com/u/etrader)\
**Post date:** [December 21, 2011, 4:08pm UTC](https://www.ruby-forum.com/t/problem-with-large-static-files/215023/4 "2011-12-21T16:08:31Z")

</div>

On Dec 20, 2011, at 1:01 AM, etrader wrote:

> Actually, I suspected the nature of 0.000 request time; but what makes  
> me wonder is that it takes only 3ms to process a relatively php file  
> with output of 5KB. Then, why reading a static file of 15KB should take  
> 600ms?

It depends on the speed of your disk, filesystem, etc. Is this local  
disk or something like NFS? Is this a physical machine or a vm? How many  
workers are you running? We generally run 2 per cpu core – that does  
“worse” than 1 per core in benchmarking, but seems to work better in  
actual production use because of various places nginx may block (on  
Linux).

–Brian

---

<div class="post-metadata">

**Author:** ![etrader](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/b5e925/32.png) [@etrader](https://www.ruby-forum.com/u/etrader)\
**Post date:** [December 26, 2011, 9:31pm UTC](https://www.ruby-forum.com/t/problem-with-large-static-files/215023/5 "2011-12-26T21:31:19Z")

</div>

Thanks Brian, I always had this doubt whether it is good to have more  
workers (comparing to the number of CPUs) or not.

Posted at Nginx Forum:

> **[Re: Problem with large static files](https://forum.nginx.org/read.php?2,220272,220502#msg-220502)**
>
> I have a strange problem with slow load of relatively large files. On a domain without proxy (designed for serving static files), the request time (as monitored by access log $request\_time) for an simple jpg image file of 5KB is 0.000s (seems to be...
