Forum Moderators: coopster

Message Too Old, No Replies

script takes 99% of resources. Need some help

can the script be changed to run longer by taking less resources?

         

walkman

4:06 am on Aug 15, 2005 (gmt 0)



Hi,
the front page of my site is not dynamic. I have it so when I'm done updating, I click on a link to activate a script that prints the results in a php file. This is then included on my index when someone eneter my site. The index page loads superfast and I love it.

The problem I have is that when run the update script, it takes 25-30 seconds to run and no one can access the site during that time (97-98-99% CPU usage). Needless to say, that is too long and I lose people who don't like to wait as the browser hangs. I do this about 4-10 times a day so it ads up. I don't know if I'm losing the visitor will make me $100 or just waste bandwidth :), but I rather not lose anyone. I have talked to the programmer, paid extra and he tried 3 times already, but it's still too resource intensive. The DB schema, and several sorting options might be to blame.

Until this is solved permanently, and since this is just on my end, is it possible to tell the script to go slower (less CPU) so visitors have no problem accessing the the site as this is running? Waiting an extra 30 sec or a minute will not kill me.

any help would be greatly appreciated. I will, in a nice way, pass any info to my programer.

thanks

marcs

4:21 am on Aug 15, 2005 (gmt 0)

10+ Year Member



I have some scripts which take anywhere from 1 to 24+ hours to build new databases. I run those offline, on a local unix machine. Once finished, I upload databases to the web servers. That may be an option for you.

Otherwise, if you are running the script from shell (or if you could run it from shell), try this :

nice -n19 script_name

That will make it use less CPU cyles (and hence take longer to execute).

Marc

walkman

4:10 pm on Aug 15, 2005 (gmt 0)



Hi marcs,
thanks for the reply. I suggested that we do an index...guess what? It worked. Now it takes 2-3 seconds max, and the server load is less than 30%. Drastic improvement.

Now I got two more features to fix (speed wise) and I'm all set..

thanks again

walkman

3:30 am on Aug 17, 2005 (gmt 0)



replying to my own thread because it saved me soooooo much time and money (was considering a dual xeon server)--as it turned out for no reason: USE INDEX ;).

Now my (back end) site is blazing fast. Something that took 10+ seconds to load, now loads in 0.3 seconds. Same hardware, same settings.

jatar_k

5:07 am on Aug 17, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



very nice work walkman

trillianjedi

1:40 pm on Aug 17, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hey Walkman, good work.

I do exactly the same thing - printing articles and homepage elements which generally don't get edited to a php include to save the DB accesses.

I don't quite follow what you mean by using "INDEX"? I'm not experiencing speed issues, but I am curious.

marcs - I've always thought that using NICE on a DB query is not a good idea, as the table locking will affect users accessing the site at the same time? In other works, better to get in and out of the job as fast as possible?

TJ

walkman

1:50 pm on Aug 17, 2005 (gmt 0)



the command was like this:
ALTER TABLE `blah` ADD INDEX `some_name` ( `id_something` , `add_index` )

so I don't know ;).
I'm guessing MySQL keeps them in memory, no need to search the entire db each time.

trillianjedi

1:51 pm on Aug 17, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



OK, so previously you were using tables without indexes. I'm pretty sure ours all have indexes, but worth a double check.

Thanks.

TJ