View Full Version : Page Generation Takes 1.9 seconds? Is it ok?
olddocks
Aug 21st 2007, 3:29 pm
I implement complex algorithm with PHP and mysql. I noticed that to display main page, it takes about 1.8sec or more...
Is it too slow?
Kuldeep1952
Aug 21st 2007, 5:20 pm
It depends upon your mysql queries. You can run each query in phpmyadmin, note the time and add it up. This way you will also know which query is taking longer and needs optimisation
olddocks
Aug 22nd 2007, 1:55 am
actually i run about 100 queries to generate the results.
NoamBarz
Aug 22nd 2007, 3:20 am
The queries are time consuming. Try minimizing their number or maybe using Ajax so that you can load the page first and load the data second.
olddocks
Aug 22nd 2007, 3:53 am
Thanks NoamBarz, Actually i am worried about this site: quick-name-generator.com (http://quick-name-generator.com). I takes about 1.5s to load main page as it is algorithmically intensive. Until now i havent found a way, although i have tried my best to optimize.
codesome
Aug 22nd 2007, 3:58 am
olddocks, are all names pregenerated and stores in database? Or you generate Markov chains in real time?
HuggyCT2
Aug 22nd 2007, 5:57 am
Try and use left joins etc to speed it up rather then many querys.
l0gic
Aug 22nd 2007, 6:00 am
Tweak the code to debug SQL queries; dump them all to file for a single page load. Then, go over each one and see how it can be optimized and/or combined with others.
olddocks
Aug 22nd 2007, 7:57 am
olddocks, are all names pregenerated and stores in database? Or you generate Markov chains in real time?
yeah! i generate Markov chains in real time. Thatshow output is generated. Should i worry?
codesome
Aug 22nd 2007, 8:02 am
So, if you will pregenerate a some chains, your page will generates more faster. But i think it is not what you want to hear.
olddocks
Aug 22nd 2007, 8:06 am
So, if you will pregenerate a some chains, your page will generates more faster. But i think it is not what you want to hear.
very good idea indeed.
The problem is if i pre-generate the outcomes, there will be a large no of random words stored in database. Again if i want to pick randomly rand() in mysql would drastically face slowdowns. Further the pre-generated ones may occur frequently in outcomes.
I will see what i can do. +rep added :D:D
codesome
Aug 22nd 2007, 9:00 pm
Hm. Generete random number via php ($rand=mt_rand(1,$max)) and make select query like:
select * from table where `id`='$rand';
And if `ID` is primary key it will work very fast. If you need another field in 'where' build index with it.
ssanders82
Aug 23rd 2007, 11:35 am
Agree with you that "order by Rand()" is pretty slow in MySQL. One thing I saw on your page for baby's first name: popular name was "Sage" and randomly twisted was "Sage". You might want to check that these are not equal.
Cool site though
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.