Re: download queue

From: Date: Tue, 30 Sep 2003 10:55:53 +0000
Subject: Re: download queue
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-164369@lists.php.net to get a copy of this message
25 queries a second? No problem. But you calculations are still wrong: 500 kb/s = 62.5 kB/s 62.5 kB/s * 100 users = 6 250 MB/s 6 250 MB/s / 4 kB (4096 B) = 1562.5 queries per second Well that's too much. At this load 4096 can be increased to 409600, the database load would be only 15.625 queries per second. Nathan Taylor wrote:
Actually, correct that, 200 queries every 8 seconds! It won't just explode, it will create a mushroom cloud while it's at it! ----- Original Message ----- From: Marek Kilimajer To: Alex Cc: php-general@lists.php.net Sent: Tuesday, September 30, 2003 6:32 AM Subject: Re: [PHP] download queue I would do it this way. Output your files and update bandwith usage: while($out=fread($file, 4096)) { echo $out; UPDATE bandwith_usage SET bandwith_usage = bandwith_usage+1 WHERE second = UNIX_TIMESTAMP() LIMIT 1 if(mysql_affected_rows()==0) { // if this is the first output in this second INSERT bandwith_usage SET bandwith_usage = 1, second = UNIX_TIMESTAMP() } } When you are about to start a download, check the bandwith usage first, in this case for the last minute: SELECT AVG(bandwith_usage) usage FROM bandwith_usage WHERE second > UNIX_TIMESTAMP() - 60 usage * 4096 gives you usage in bytes per second. If it exceeds your limit, output a html page (sorry...), else open the file and start the above loop. You might want to change 4096 to a higher value. You should also implement a garbage collector that will remove old bandwith usage data, the collector can make usage statistics too. Alex wrote: I'm considering start up a small download site with the large amount of excess bandwith I have on my site, however I thought it would be cool to put some sort of download queue up (you know, so all my bandwith doesn't get eaten up when 500 random people suddenly decide to download a 500meg file i've put up. In any case, I'm once again to the point where I know what I want, but the logic of it escapes me. If anyone has ever done this before, seen the code behind this before, or knows basically how this would be done, I'd be more than happy if you would share your wisdom with me. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php


« previous php.general (#164369) next »