New topic: How to make my httpserver faster
<http://forums.realsoftware.com/viewtopic.php?t=23563> Page 1 of 1 [ 4 posts ] Previous topic | Next topic Author Message newhow Post subject: How to make my httpserver fasterPosted: Tue Jul 22, 2008 6:51 pm Joined: Sun Oct 01, 2006 10:55 am Posts: 52 Location: Atlanta, GA hello, I wrote a very very primitive http server. It simply locates the file requested by the client and writes it back as a whole into a TCPsocket buffer, shown as the following code Code:..... if file<>nil and file.Exists then stream = file.OpenAsBinaryFile() Write "HTTP/1.1 200 OK" + chr(13) + chr(10) +chr(13) + chr(10) Write stream.Read(file.Length) end My httpserver works but slowly. It serves local file http://localhost/xxx.mp3 at speed 60kB/s. This is much slower than Apache does. I am wondering how to speed my httpserver up. I have tried writing chunk by chunk in the event of TCPscoket.sendprogress, which does not help a lot. Any idea? Thanks a lot. _________________ Wealth follows hard work. Top jdiwnab Post subject: Re: How to make my httpserver fasterPosted: Tue Jul 22, 2008 7:10 pm Joined: Sat Oct 01, 2005 12:18 pm Posts: 1323 What operating system are you running? How are you finding the file? How are you parsing the URL? Chunking the file will help. Using the SendComplete (because it can lie) and SendProgress, I fill up a buffer of &hFFFF bytes by adding &hFF bytes at a time until the file is done. I wrote a webserver based on the "Web Server in Less Than 100 Lines of Code" (only extended greatly) that was rather fast on windows (made in 5.5), but terribly slow last time I tried on Linux (2006r3). Neither reached Apache speeds, but I also didn't make much effort to optimize it for speed. _________________ Top newhow Post subject: Re: How to make my httpserver fasterPosted: Tue Jul 22, 2008 7:39 pm Joined: Sun Oct 01, 2006 10:55 am Posts: 52 Location: Atlanta, GA jdiwnab wrote:What operating system are you running? How are you finding the file? How are you parsing the URL? Chunking the file will help. Using the SendComplete (because it can lie) and SendProgress, I fill up a buffer of &hFFFF bytes by adding &hFF bytes at a time until the file is done. I wrote a webserver based on the "Web Server in Less Than 100 Lines of Code" (only extended greatly) that was rather fast on windows (made in 5.5), but terribly slow last time I tried on Linux (2006r3). Neither reached Apache speeds, but I also didn't make much effort to optimize it for speed. Yes, I have similar observation. On windows it is fast but slow on Linux. " How are you finding the file? How are you parsing the URL?" ---that's trivial and not relevant to the speed. I will try " fill up a buffer of &hFFFF bytes by adding &hFF bytes at a time". Thank you. _________________ Wealth follows hard work. Top guykuo Post subject: Re: How to make my httpserver fasterPosted: Wed Jul 23, 2008 11:25 am Joined: Mon Apr 02, 2007 5:51 pm Posts: 73 If you're not sending files to a browers, but instead to a client that you wrote, things can go MUCH faster if you send larger chunks. For sending files very quickly, I write out 2 MB chunks of data at a time out my http server port when sending files between two of my programs. This dramatically sped up transfers compared to smaller chunk sizes. Top Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending Page 1 of 1 [ 4 posts ] -- Over 900 classes with 18000 functions in one REALbasic plug-in. The Monkeybread Software Realbasic Plugin v8.1. <http://www.monkeybreadsoftware.de/realbasic/plugins.shtml> [email protected]
