Forum Moderators: open

Message Too Old, No Replies

Having a lot of small queries on page slow down processing time?

e.g. 20 queries.

         

Dilly

7:02 pm on Sep 8, 2007 (gmt 0)

10+ Year Member




If i have like 20 queries such as...

$query="SELECT columnName From tableName WHERE id= 'this'";

etc...

would this slow down processing/loading time of a page?

The reason i ask this is because I have so many queries from my database on my php page from different tables in order to populate and create the page. Now at the moment on localhost it doesn't seem to take much time at all to load, but im not sure how fast the page will load once my site is live.

Does it tend to be the same?

alexdunae

1:41 am on Sep 9, 2007 (gmt 0)

10+ Year Member



There are a lot of factors that come into play once you push your site onto its production server(s). It will almost certainly be slower, though.

Database round-trips are expensive, time wise. I would like into ways to combine your twenty queries (maybe joins or sub queries).

Of course, the fastest database access is *no* database access - caching the output of your database calls will keep things speedy.

Dilly

2:28 pm on Sep 9, 2007 (gmt 0)

10+ Year Member



Thanx forthe reply alex,
I have never used mysql cache so how do I go about implementing this into the queries.

[edited by: Dilly at 2:28 pm (utc) on Sep. 9, 2007]

alexdunae

9:15 pm on Sep 9, 2007 (gmt 0)

10+ Year Member



Hey Dilly,

I actually meant caching your HTML pages. Run your queries, build your page, write it out to a static file and then serve that until your data changes.

I would look at combining queries if at all possible.

SeanW

1:32 am on Sep 21, 2007 (gmt 0)

10+ Year Member



Cache, cache, cache.

Make sure you have the mysql query cache turned on.

Look at caching the HTML page, or parts of the page

Look into using memcached to cache all the data into one key, and invalidate it when the source changes.

Sean

vincevincevince

2:23 am on Sep 21, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



As SeanW suggested - memcached is a really great method.

Personally I combine it with PHP objects (OOP5) which get stored in memcached to enable very fast state, query result and session storage and reconsitution.