Smarty Forum Index Smarty
The discussions here are for Smarty, a template engine for the PHP programming language.

GoogleMapsAPI really really really slow
Goto page 1, 2  Next
 
Post new topic   Reply to topic    Smarty Forum Index -> Add-ons
View previous topic :: View next topic  
Author Message
Guinness
Smarty Rookie


Joined: 31 Oct 2007
Posts: 8

PostPosted: Wed Oct 31, 2007 5:24 pm    Post subject: GoogleMapsAPI really really really slow Reply with quote

I use this code on a generic map and it takes 60+(!) seconds to populate the map. This cant be normal. Addresses are all geocached in the local database and the select statement doesnt take that long. Whats wrong?

Edit: 60+ seconds for ~150 points, 10+ seconds for 15-25 points.

Code:

<body onload="onLoad()">
<table width=100% height=100%>
<tr width=100% height=100%>
<td width=100% height=100%>
<?
    require('includes/GoogleMapAPI.class.php');
    require('includes/mysql.php');
    $map = new GoogleMapAPI('lalalala');
    $map->setDSN('connection string here');
    $map->disableSidebar();
    $map->setInfoWindowTrigger('mouseover');
    $map->setWidth('100%');
    $map->setHeight('100%');
    $map->disableDirections();
    //$map->setControlSize('large');
    //$map->disableZoomEncompass();
    $map->setAPIKey('stuff here');

 $queryBarsMap = "select * from bars";
 $resultBarsMap = mysql_query($queryBarsMap, $link);
 while($rowBarsMap = mysql_fetch_array($resultBarsMap)) {
 $mapAddress = $rowBarsMap[5]." ".$rowBarsMap[6]." ".$rowBarsMap[7]." ".$rowBarsMap[8];
 $mapStreet = $rowBarsMap[5];
 $mapCity = $rowBarsMap[6];
 $mapState = $rowBarsMap[7];
 $mapZip = $rowBarsMap[8];
 $barNameMap = $rowBarsMap[3];


$map->addMarkerByAddress($mapAddress,$barNameMap,"<div class=gmap style=\"color:#004276\; font-size:16px\;font-family: Helvetica\;\"><b>".$barNameMap."</b><br />".$mapStreet."<br />".$mapCity.", ".$mapState." ".$mapZip."</div>");

  ?>

    <?php $map->printHeaderJS(); ?>
    <?php $map->printMapJS(); ?>
    <?php
     $map->printMap();
?>
</td></tr></table>
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7365
Location: Lincoln Nebraska, USA

PostPosted: Wed Oct 31, 2007 6:02 pm    Post subject: Reply with quote

Run some profiling, see where the time is being taken. Is the PHP script taking this long, or does it finish right away, then the javascript is what is taking the time?
Back to top
View user's profile Send private message Visit poster's website
Guinness
Smarty Rookie


Joined: 31 Oct 2007
Posts: 8

PostPosted: Wed Oct 31, 2007 6:27 pm    Post subject: Reply with quote

mohrt wrote:
Run some profiling, see where the time is being taken. Is the PHP script taking this long, or does it finish right away, then the javascript is what is taking the time?


When I comment out "$map->addMarkerByAddress" it takes < 1 second. How do I start poking around this function to see what is taking it so long?
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7365
Location: Lincoln Nebraska, USA

PostPosted: Wed Oct 31, 2007 7:35 pm    Post subject: Reply with quote

It must be looking up all the addresses, so either it is the first time, or your caching is not functioning properly.
Back to top
View user's profile Send private message Visit poster's website
Guinness
Smarty Rookie


Joined: 31 Oct 2007
Posts: 8

PostPosted: Wed Oct 31, 2007 7:57 pm    Post subject: Reply with quote

mohrt wrote:
It must be looking up all the addresses, so either it is the first time, or your caching is not functioning properly.


That was my guess. My table is populated with geocoded addresses. How do I verify that it is pulling from my DB server?
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7365
Location: Lincoln Nebraska, USA

PostPosted: Wed Oct 31, 2007 8:52 pm    Post subject: Reply with quote

I don't think there is anything built in, you'll have to insert to debug statements to see what is happening. It uses the address string as the key, so any little difference would be a cache miss.
Back to top
View user's profile Send private message Visit poster's website
Guinness
Smarty Rookie


Joined: 31 Oct 2007
Posts: 8

PostPosted: Wed Oct 31, 2007 9:40 pm    Post subject: Reply with quote

Would this correctly test if its pulling from the local GEOCODES table correctly?

Code:
    function addMarkerByAddress($address,$title = '',$html = '',$tooltip = '') {
        if(($_geocode = $this->getGeocode($address)) === false) {
            echo "not caching<br>";
            return false;
        }
        echo "pulling from cache<br>";
        return $this->addMarkerByCoords($_geocode['lon'],$_geocode['lat'],$title,$html,$tooltip);
    }
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7365
Location: Lincoln Nebraska, USA

PostPosted: Wed Oct 31, 2007 9:54 pm    Post subject: Reply with quote

It should. Also check the php processing time, and check if php is fetching data over http during the process.
Back to top
View user's profile Send private message Visit poster's website
Guinness
Smarty Rookie


Joined: 31 Oct 2007
Posts: 8

PostPosted: Wed Oct 31, 2007 10:05 pm    Post subject: Reply with quote

mohrt wrote:
It should. Also check the php processing time, and check if php is fetching data over http during the process.


I have verified that it is indeed pulling from cache. How would I go about seeing if php is fetching data over http?
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7365
Location: Lincoln Nebraska, USA

PostPosted: Wed Oct 31, 2007 10:15 pm    Post subject: Reply with quote

if its pulling from the cache, is the php processing time long? or is the time coming from javascript after the fact?
Back to top
View user's profile Send private message Visit poster's website
Guinness
Smarty Rookie


Joined: 31 Oct 2007
Posts: 8

PostPosted: Wed Oct 31, 2007 10:18 pm    Post subject: Reply with quote

mohrt wrote:
if its pulling from the cache, is the php processing time long? or is the time coming from javascript after the fact?


Each addMarkerByAddress pulls from cache and takes between .2 and .3 seconds.

I'm fairly certain its from the php processing time.

Edit: or doing 1 mysql query per address. How do I check the mysql_query time?

Double Edit: I have done the following to test query response times:

Code:

/*
echo $mapAddress."<br>";
//$map->addMarkerByAddress($mapAddress,$barNameMap,"<div class=gmapstyle=\"color:#004276\;font-size:16px\;font-family:Helvetica\;\"><b>".$barNameMap."</b><br />".$mapStreet."<br />".$mapCity.", ".$mapState." ".$mapZip."</div>");
*/

 $queryBarsMapAddress = "select * from GEOCODES where address = '".$mapAddress."'";
 $resultBarsMapAddress = mysql_query($queryBarsMapAddress, $link);




The mysql query to the GEOCODES table takes between .03 and .04 seconds where the addMarkerByAddress takes between .3 and .4 seconds. I think its safe to say its not the DB, hmmm.
Back to top
View user's profile Send private message
Guinness
Smarty Rookie


Joined: 31 Oct 2007
Posts: 8

PostPosted: Thu Nov 01, 2007 2:24 am    Post subject: Reply with quote

I think I have tracked it down to the PEAR connection. I have installed and tested the same script at home on my own server with a local DB and it works just fine. Script execution takes .33 seconds TOTAL to grab all the points. Now, if I can do an identical set of MySQL queries outside of pear it goes fast, but once it goes through pear thats where I hit the slowdown.

Any ideas?


Yet another edit: I have configured my hosting to use my home mysql server and it STILL goes just as slow. At this point I am convinced my host is somehow limiting the number of queries you can do through PEAR to MySQL somehow.
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7365
Location: Lincoln Nebraska, USA

PostPosted: Thu Nov 01, 2007 1:44 pm    Post subject: Reply with quote

I've been wanting to update the GoogleMapAPI to use the PHP5 PDO library as an option, I just haven't gotten around to it. There should be no problem using the PEAR library though. Do you have an index on the address column?
Back to top
View user's profile Send private message Visit poster's website
Guinness
Smarty Rookie


Joined: 31 Oct 2007
Posts: 8

PostPosted: Thu Nov 01, 2007 3:16 pm    Post subject: Reply with quote

mohrt wrote:
I've been wanting to update the GoogleMapAPI to use the PHP5 PDO library as an option, I just haven't gotten around to it. There should be no problem using the PEAR library though. Do you have an index on the address column?


I dont. I have read about creating indexes on tables but it still confuses the hell out of me.
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7365
Location: Lincoln Nebraska, USA

PostPosted: Thu Nov 01, 2007 3:44 pm    Post subject: Reply with quote

if you don't have an index on the address column and you have a LOT of addresses in there, that is going to be a performance problem. in MySQL its pretty easy. The example that comes with Google Maps puts the index in:

Code:
CREATE TABLE GEOCODES (
          address varchar(255) NOT NULL default '',
          lon float default NULL,
          lat float default NULL,
          PRIMARY KEY  (address)
        );
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Smarty Forum Index -> Add-ons All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP