Re: How resource-intensive are these?
From: jerome (oups_at_wanadoo.fr)
Date: Sat, 28 Feb 2004 14:42:50 +0100
"Brent" <email@example.com> a écrit dans le message de news:
> I'm writing a fun little php script that generates a random image by
> stringing together 8 smaller images. It also reads lines in from several
> data text files and strings them together to make interesting phrases to
> go along with these images.
> My question is, how expensive are these features in terms of server
> load? I had to upgrade my hosting account for bandwidth earlier this
> month, because another little script of mine, BattleFishies
> (http://www.gremkin.com/fishies), got popular over night and was serving
> up 8 gb of traffic a day. I don't imagine the same overnight success
> with this new program, but I'm worried that if, let's say 10 people all
> try to access the program at the same time, something will snap and
> everything will come crashing down, with smoke coming out of the server
> and everything.
> The way the script is set up now, I am generating strings by grabbing
> random lines out of files using an array variable and the 'file'
> command. If I understand it correctly, this reads the whole file into an
> array. So, instead of getting a single line by printing a certain key in
> the array, is there a less resource intensive way of doing this? Would
> actually defining the arrays at the top of the script, and doing away
> with the external files, be benificial at all? Or perhaps there is a way
> to grab just one certain line number straight out of the text file and
> into a variable, without loading the whole thing into memory?
> Also, how will my host's linux server respond to lots of requests for
> the dynamic images? Will it crash? Will it just go really slow? Slow is
> ok. People can wait. I just don't want my host getting mad at me for
> bogging down their system. I know this is stretching, but is there any
> sort of way to restrain how many resources php is allowed to use at any
> given time, maybe spitting back a quick 'please try again' error message
> to the user? What tends to happen as php starts eating up resources? How
> many resources do you think this script will gobble up?
> Thanks for any and all help you can give me with this. PHP is fun, but I
> might be trying to make it do too much! :)
there are different points in your question :
- CPU load
- memory load
- bandwidth usage
if you propose people to incoporate in there website images witch are hosted
on you server, as it seems to be the cas with your battle tishes feature,
it's very normal that the bandwidth usage is growing. People incorporate the
image on their website, and each time somebody is displaying the page, you
server is requested a 5 Kb image. if a hundred pages are using this feature
each accessed 10 times a day, your server is requested 1000 images, 5000
kbytes a day. You just have to multiply those numbers to get an idea of how
much this feature costs without anybody really visiting your website.
I you propose a feature that builds images from other images, text... as
long as you only propose it to people visiting your website, everything
should work fine. It's possible to measure the cost in terms of CPU and
memory usage but this would be a bit complicated. 10 people requesting this
feature at the same time never happens. The thing that happens is for
example, 10 people requesting a script in the same period of time. 10
requests in 1 second for example. Just calculate how many requests per day
it would make : 864000 as day. If you consider that this would concern rush
hours lets say 3 hours a day, this would still mean 108000 requests in 3
hours. (10 x 3600 x 3). You're not going to reach that! So the question is
not only how much does it cost to do that.
The question is also, how many other sites (and what kind) are hosted on the
same server ?
If you serve for example 100 requests in the 3 rushy hours,
Lets say that you script takes 1 second to be executed if it can use 100% of
the ressources dedicated to web hosting.
Lets say that 100 sites hosted on the same server proposing the same kind of
Then, your site would consume 100 seconds at 100% during 3 hours.
All the sites together would require 10000 seconds during the 3 hours that
is 3300 seconds at 100 % / hour.
As the requests are not going regular during the 3 hours, the server is
going to be overloaded. And people are going to wait (possibly very much)
for their request to be treated.
The question of memory and bandwidth can be handled the same way. I don't
know if the way I'm thinking about it is very rigth.
Servers that propose hosting together with other sites can not handle heavy
features like image building. Try it, ask the server admin and don't propose
people to use this feature on their website usin your servers resources !