Page 1 of 2
A large mount of co-current queries
Posted: Thu Jul 16, 2009 4:05 am
by amiramir
Hi guys,
I have written a PHP script that performsaround 10 queries.
And tested it intensively with a few client at the moment for along time and it loaded the database and caused a very long query time.
How can I prevent it? Should I lock and unlock the table in the beginning and the end of the PHP script?
Thanks!
Re: A large mount of co-current queries
Posted: Thu Jul 16, 2009 4:49 am
by onion2k
10 queries isn't very much at all. I've got scripts that do thousands of queries that are fine. I think there's a bigger problem somewhere.
Re: A large mount of co-current queries
Posted: Thu Jul 16, 2009 7:29 am
by jackpf
What are the queries doing?
Re: A large mount of co-current queries
Posted: Thu Jul 16, 2009 7:32 am
by amiramir
The update / insert to the table or just select.
Re: A large mount of co-current queries
Posted: Thu Jul 16, 2009 7:38 am
by jackpf
If there aren't any joins then it can't be slow at all with 10 queries, unless your server is a heap of junk.
Re: A large mount of co-current queries
Posted: Thu Jul 16, 2009 7:44 am
by amiramir
I made a stress test. 6 clients that call a PHP script every a few seonds.
The PHP makes about 10 queries. It started fine, but as the time passed it became slower and slower...
Re: A large mount of co-current queries
Posted: Thu Jul 16, 2009 7:50 am
by jackpf
Try using
this code with various queries to see if there is a bottleneck.
Re: A large mount of co-current queries
Posted: Thu Jul 16, 2009 8:10 am
by onion2k
amiramir wrote:I made a stress test. 6 clients that call a PHP script every a few seonds.
The PHP makes about 10 queries. It started fine, but as the time passed it became slower and slower...
Could be running out of memory. Do the queries select massive resultsets?
Re: A large mount of co-current queries
Posted: Thu Jul 16, 2009 8:16 am
by amiramir
Most of the queries update or insert to the table.
The select finds a unique row.
Re: A large mount of co-current queries
Posted: Thu Jul 16, 2009 8:18 am
by onion2k
Is it inserting loads of data? That can slow things down a lot.
Re: A large mount of co-current queries
Posted: Thu Jul 16, 2009 8:26 am
by amiramir
Around 10 rows per script execution.
Re: A large mount of co-current queries
Posted: Thu Jul 16, 2009 9:23 am
by onion2k
Well, be the sounds of it the script should run fine with loads of concurrent users. There's something seriously wrong with the code if it isn't working properly.
Re: A large mount of co-current queries
Posted: Thu Jul 16, 2009 10:35 am
by amiramir
Thank you guys for your help.
It seems that I created a huge load on the server. This server is my web host, and is not capable of dealing with a big amount of queries.
I'll start my project as a pilot mode, and when time comes, I will find a databse hosting service for that purpose.
Thanks again

Re: A large mount of co-current queries
Posted: Thu Jul 16, 2009 11:03 am
by jackpf
10 queries is not a lot.
As onion2k said, scripts can execute thousands in under a second.
Sounds like you need new hosts, or they need to upgrade their hardware.
Re: A large mount of co-current queries
Posted: Thu Jul 16, 2009 11:54 am
by s.dot
When I look in phpmyadmin stats it constantly handles thousands of queries per second, so there is something wrong with your queries. Show us them. On the crappiest machine it should not be noticeably slow.
Show us your code.
Are you inserting pictures? Are your tables HUGE? Indexed properly?