Forum Moderators: coopster

Message Too Old, No Replies

Best way to make Random from 30.000 products

actually CPU server is overloaded

         

rowtc2

1:54 pm on Jul 29, 2008 (gmt 0)

10+ Year Member



Hi ,

i have a site who is running very hard on server (CPU processor will not resist many more).MySql is the most solicited.
I think the random function is guilty. Is a better way to write the code to improve the speed of selection ?


$sql = "select * from product_table WHERE (category='$category' and subcategory='$subcategory') ORDER BY RAND() LIMIT 5";
$result = mysql_query ($sql);
while($row = mysql_fetch_array($result)){

$doc_id=$row["doc_id"];
$ description ..etc
echo"
product

eelixduppy

2:14 pm on Jul 29, 2008 (gmt 0)



You might want to look at the optimization documentation [dev.mysql.com] and see what you can do with your table. I'm sure there's more that can be done than just the select query.

rowtc2

5:52 pm on Jul 29, 2008 (gmt 0)

10+ Year Member



I have contacted a beginner developer because i am totally newbie in PHP, and he tell me it can be run this random from PHP in order to use more little MySql database. In this way pages can load more quickly on me e-shop and visitors will be more happy(and server too).

If anyone have experienced or hear about a very good way for random results can suggest me a theoretical solution and i will search to apply it in fact.

Lord Majestic

7:13 pm on Jul 29, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It's a very poor way to select random items. A much better way would be to:

a) assign sequential ID to each of the products from 0 to X.
b) generate in any language a few random IDs and then select appropriate products from the database.

This would cut down server load big time.