<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="/stylesheets/rss.css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>lighty's life: Optimizing Lighty for high-concurrent, large-file downloads</title>
    <link>http://blog.lighttpd.net/articles/2005/11/11/optimizing-lighty-for-high-concurrent-large-file-downloads</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description></description>
    <item>
      <title>Optimizing Lighty for high-concurrent, large-file downloads</title>
      <description>&lt;p&gt;In lighttpd 1.4.6 we have added some modifications for sites which have handle some 100 files in parallel with size of more than 100Mb each.&lt;/p&gt;


	&lt;p&gt;The problem in earlier releases was that lighttpd had to wait until the disk had seeked to the right place, read a few 100 kbyte to send it out. And this for each request as this scenario was completly trashing the disk-buffering. The IO-wait went sky-high and we were completly bound to the disk-io.&lt;/p&gt;
&lt;p&gt;You could see this by running vmstat:&lt;/p&gt;


&lt;pre&gt;
$ vmstat 1
procs -----------memory---------- ---swap-- -----io---- --system-- ----cpu----
 r  b   swpd   free   buff  cache   si   so    bi    bo   in    cs us sy id wa
 0  7 306852  51396    152 237004  632  492 34952  7531 6983 11677  3 25  0 72
&lt;/pre&gt;

	&lt;p&gt;You see, we have 72% io-wait and 25% are spent in the kernel doing something. Only 3% are spent in userland (lighty).&lt;/p&gt;


	&lt;p&gt;When we investigated the problem we layed out a plan:&lt;/p&gt;


&lt;pre&gt;
/* Optimizations for the future:
 *
 * adaptive mem-mapping
 *   the problem:
 *     we mmap() the whole file. If someone has alot large files and 32bit
 *     machine the virtual address area will be unrun and we will have a failing
 *     mmap() call.
 *   solution:
 *     only mmap 16M in one chunk and move the window as soon as we have finished
 *     the first 8M
 *
 * read-ahead buffering
 *   the problem:
 *     sending out several large files in parallel trashes the read-ahead of the
 *     kernel leading to long wait-for-seek times.
 *   solutions: (increasing complexity)
 *     1. use madvise
 *     2. use a internal read-ahead buffer in the chunk-structure
 *     3. use non-blocking IO for file-transfers
 *   */
&lt;/pre&gt;

	&lt;p&gt;And that&amp;#8217;s what we did step-by-step:&lt;/p&gt;


	&lt;ul&gt;
	&lt;li&gt;instead of mmap()ing the whole file we use a moving window of 512kb&lt;/li&gt;
		&lt;li&gt;we used madvise() to tell the kernel to load this area into memory &lt;span class="caps"&gt;NOW&lt;/span&gt;&lt;/li&gt;
		&lt;li&gt;we have a switch to use local-buffering instead of asking the kernel to do so&lt;/li&gt;
	&lt;/ul&gt;


If you want to use it, set:
&lt;pre&gt;
server.network-backend = "writev" 
&lt;/pre&gt;

	&lt;p&gt;If you want to try out the local-buffering define &lt;span class="caps"&gt;LOCAL&lt;/span&gt;_BUFFERING in network_writev.c.&lt;/p&gt;


	&lt;p&gt;Up to now we don&amp;#8217;t put any pressure on async-file-io as the coding impact is quite large and we don&amp;#8217;t expect a big win over the current behaviour.&lt;/p&gt;


	&lt;p&gt;Both ways result in better caching the data we need which reduces the number of seeks and in the end reduces io-wait for  us.&lt;/p&gt;


	&lt;p&gt;Problem solved, next one :)&lt;/p&gt;</description>
      <pubDate>Fri, 11 Nov 2005 14:28:00 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:94ecbe62-bee5-4490-abda-d1d0c139cbbd</guid>
      <author>jan</author>
      <link>http://blog.lighttpd.net/articles/2005/11/11/optimizing-lighty-for-high-concurrent-large-file-downloads</link>
      <category>high</category>
      <category>concurrent,</category>
      <category>large-file</category>
      <trackback:ping>http://blog.lighttpd.net/articles/trackback/26</trackback:ping>
    </item>
    <item>
      <title>"Optimizing Lighty for high-concurrent, large-file downloads" by Jamie</title>
      <description>Albert, no, SSL requires a unique IP address (or at least a new instance of the server running on a separate port number). SSL cannot work as name-based. Remember that stunnel4 might be any easy way to do SSL if you're not too concerned about performance. Apache requires a unique IP per SSL instance as well. One way around this is to only have a single SSL certificate &lt;a href="https://www.example.com/customername" rel="nofollow"&gt;https://www.example.com/customername&lt;/a&gt; and then use mod_rewrite to redirect the request to /var/www/customername/ or something like that.</description>
      <pubDate>Mon, 03 Apr 2006 19:59:52 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:14c382cd-11bc-4532-b3f9-c5df853701f9</guid>
      <link>http://blog.lighttpd.net/articles/2005/11/11/optimizing-lighty-for-high-concurrent-large-file-downloads#comment-169</link>
    </item>
    <item>
      <title>"Optimizing Lighty for high-concurrent, large-file downloads" by GM</title>
      <description>Regarding large-file server troubles... :P
When will be a function like this:
&lt;a href="http://trac.lighttpd.net/trac/ticket/208" rel="nofollow"&gt;http://trac.lighttpd.net/trac/ticket/208&lt;/a&gt; developed?</description>
      <pubDate>Tue, 29 Nov 2005 01:12:24 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:27125001-bc19-4075-ba4f-8cc8ad6d54bf</guid>
      <link>http://blog.lighttpd.net/articles/2005/11/11/optimizing-lighty-for-high-concurrent-large-file-downloads#comment-58</link>
    </item>
    <item>
      <title>"Optimizing Lighty for high-concurrent, large-file downloads" by Yusuf</title>
      <description>Jan, People who are looking for virtual hosting with SSL using one IP are looking for Server Name Indication which is currently only supported by Opera and mod_gnutls. Patches are available for Mozilla.

&lt;a href="http://paul.querna.org/journal/articles/2005/04/24/tls-server-name-indication?po" rel="nofollow"&gt;http://paul.querna.org/journal/articles/2005/04/24/tls-server-name-indication?po&lt;/a&gt;
stid=70
 
&lt;a href="http://paul.querna.org/journal/articles/2005/04/29/sni-support-in-mozilla" rel="nofollow"&gt;http://paul.querna.org/journal/articles/2005/04/29/sni-support-in-mozilla&lt;/a&gt;
 


</description>
      <pubDate>Tue, 22 Nov 2005 05:20:17 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:040faca7-f0b6-49e1-ac37-bd01189734a8</guid>
      <link>http://blog.lighttpd.net/articles/2005/11/11/optimizing-lighty-for-high-concurrent-large-file-downloads#comment-33</link>
    </item>
    <item>
      <title>"Optimizing Lighty for high-concurrent, large-file downloads" by Albert</title>
      <description>I currently use Mathopd, and I can attest to sendfile() being much better in almost all cases.  zero-copy is excellent, and Mathopd runs about 3x faster on my current box than Apache 2.x.

I will see if I can try Lighttpd and do some benchmarks of it vs Mathopd.

I will be running some stuff that might _REQUIRE_ Apache, so all this might end up being moot..   It's actually shameful to me that Apache is the most popular web server in the world, it's slower than most..
</description>
      <pubDate>Fri, 18 Nov 2005 04:22:02 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:dae63d04-0e94-428d-a8f3-44fbed2fb010</guid>
      <link>http://blog.lighttpd.net/articles/2005/11/11/optimizing-lighty-for-high-concurrent-large-file-downloads#comment-32</link>
    </item>
    <item>
      <title>"Optimizing Lighty for high-concurrent, large-file downloads" by Jan Kneschke</title>
      <description>Peter, linux-sendfile is better 90% of the cases. Only if you suffer a high io-wait value in vmstat, you might want to try writev. 

*-sendfile offer zero-copy transfers which is just blazing fast. But as soon as you are disk-io-bound they have to wait too and reducing the wait-time becomes more important.</description>
      <pubDate>Thu, 17 Nov 2005 12:47:55 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:4784b2a6-06dc-4c12-a1b7-9ffd61424d8d</guid>
      <link>http://blog.lighttpd.net/articles/2005/11/11/optimizing-lighty-for-high-concurrent-large-file-downloads#comment-31</link>
    </item>
    <item>
      <title>"Optimizing Lighty for high-concurrent, large-file downloads" by Peter</title>
      <description>Jan, do you encourage "writev" and discourage OS specific network backend e.g. "linux-sendfile" in 1.4.7?
"linux-sendfile" works for me - so should I step to "writev"?

Thanks for lighty! :-)</description>
      <pubDate>Tue, 15 Nov 2005 23:02:13 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:6510cb47-ff8a-49ce-a34e-70da9c043014</guid>
      <link>http://blog.lighttpd.net/articles/2005/11/11/optimizing-lighty-for-high-concurrent-large-file-downloads#comment-30</link>
    </item>
    <item>
      <title>"Optimizing Lighty for high-concurrent, large-file downloads" by Albert</title>
      <description>Great question!  But I always had one certificate, one name, doesn't that work??

www1.domainname.com  = certificate 1
www2.domainname.com = certificate 2

No??

If I have virtual hosting, say:

albert.domainname.com
bob.domainname.com
jack.domainname.com

and I want all 3 to be accessable via https://  you are telling me that all 3 have to be on 3 different IP's?  I don't think it true, otherwise, most of the hosting companies wouldn't be able to host SSL, because it's just one Apache server with a bunch of virtual hosts.. no?</description>
      <pubDate>Tue, 15 Nov 2005 10:33:29 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:4f71ed37-54a0-41a0-8bfd-fe0560cbedd8</guid>
      <link>http://blog.lighttpd.net/articles/2005/11/11/optimizing-lighty-for-high-concurrent-large-file-downloads#comment-29</link>
    </item>
    <item>
      <title>"Optimizing Lighty for high-concurrent, large-file downloads" by Jan Kneschke</title>
      <description>How does apache support name-based virtual hosting ? 

SSL does the certificate check BEFORE the Host: header is exchanged. It is a problem of the protocol and not a problem of lighty. 

TLS as the successor of SSLv3 turns it around: First the Host: header and a request to Switch to TLS afterwards. Up to now we don't support TLS. </description>
      <pubDate>Mon, 14 Nov 2005 19:54:03 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:975b3163-ff85-489a-bf34-382413bf5ddd</guid>
      <link>http://blog.lighttpd.net/articles/2005/11/11/optimizing-lighty-for-high-concurrent-large-file-downloads#comment-28</link>
    </item>
    <item>
      <title>"Optimizing Lighty for high-concurrent, large-file downloads" by albert@achtung.com</title>
      <description>Problem solved, next one :)

I have hestitated to try lighty because I need virtual hosting (only have 1 IP) but I need name based hosting AND I need it to support SSL.  

It says in the SSL docs that it only supports IP based, not name based.  Is this still true??

If not, then the docs need to be changed, and I'll try out lighty.

If so, there you go, you now have the next problem to solve  :-)

Basically, I only have 4 requirements for a webserver, and it's amazing to me that short of apache, almost nothing out there meets these requirements:

1)  Free!
2)  Name based virtual hosting
3)  SSL support (also name based virtual hosting)
4)  runs PHP

I've looked at about 50 web servers, and so far, only apache meets these 4 simple criterias..  So if lighty supports name-based SSL, then I'm switching in a heartbeat..</description>
      <pubDate>Mon, 14 Nov 2005 08:34:14 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:08e57236-f348-42e7-b67f-00a95cda2923</guid>
      <link>http://blog.lighttpd.net/articles/2005/11/11/optimizing-lighty-for-high-concurrent-large-file-downloads#comment-27</link>
    </item>
  </channel>
</rss>
