Go Back   HostGator Peer Support Forums > HostGator Peer Support Forums > Linux VPS Support

Notices

Reply
 
Thread Tools
  #1  
Old 12-28-2009, 08:05 PM
jamesoks jamesoks is offline
Hatchling Croc
 
Join Date: Sep 2009
Posts: 19
Question Reached CPU Limit - any SQL gurus?

I am using a mySQL database on a site to calculate the distance of multiple points based on zipcodes, latitudes and longitudes. E.g. Point A at zip code 123456 has latitude 100 and longitude 200 Using a static formula, the distance between Point A and multiple other points are calculated and returned real time. The reference Point A may change to Point B with a different lat/long.

The issue is that the server CPU is maxing out and taking quite a long time to do these calculations on a dynamic basis. Putting the actual distances into a DB is not practical as it means a N x N lookup (999999 x 999999) and will increase exponentially as more datapoints are added.

I can of course increase CPU (currently on VPS Level 3), but seems a waste as this calculation is extremely bursty - most of the time the CPU is idle. Also the RAM/harddisk/bandwidth are all far under-utilised at the moment.

Any SQL gurus on whether such a calculation can be optimised or is a hardware upgrade the only way out?
Reply With Quote
  #2  
Old 12-28-2009, 11:11 PM
junkstuff's Avatar
junkstuff junkstuff is offline
Junior Croc
 
Join Date: Feb 2008
Location: Have Laptop, Will Travel.
Posts: 106
Default Re: Reached CPU Limit - any SQL gurus?

Why are you re-inventing the wheel? There are a number of services and scripts you can use to do the distance for you. If you google you will probably find a few hundred and one (or maybe ten) probably would suit your needs.
Reply With Quote
  #3  
Old 12-29-2009, 02:25 AM
jamesoks jamesoks is offline
Hatchling Croc
 
Join Date: Sep 2009
Posts: 19
Default Re: Reached CPU Limit - any SQL gurus?

Junkstuff, I didn't want to do the calculation offline as it would mean I'm dependent on someone else's engine.

The calculation itself is not that complicated based on the Haversine Formula:
Distance = ACOS(COS(RADIANS(90-Lat1)) *COS(RADIANS(90-Lat 2)) +SIN(RADIANS(90-Lat1)) *SIN(RADIANS(90-Lat2)) *COS(RADIANS(Long1-Long2))) *6371*1000

However, the challenge I'm facing is if I have 1,000,000 Latitude and Longitude pairs, what is the most efficient way of structuring/accessing a database such that I can find the distance between any given pair and say 50,000 other pairs.

If I did it using an external service, I would still have to send them 50,001 pairs, let them do the calculation, then return to me 50,001 distances, which I assume will take longer than doing it in-house, unless the third-party service had really powerful servers.
__________________
FullofThings.com
Free local classifieds
www.fullofthings.com
Reply With Quote
  #4  
Old 12-29-2009, 04:40 AM
rota919 rota919 is offline
Swamp Croc
 
Join Date: Jan 2007
Location: Armagh, Northern Ireland
Posts: 323
Default Re: Reached CPU Limit - any SQL gurus?

PM Sent...
__________________
Fred
Reply With Quote
Reply

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Any Flash Gurus? atlan Web Hosting Services 4 05-27-2008 07:01 AM
CPU Limit for shared? cloggedone Pre-Sales Questions 21 01-25-2008 12:43 PM
Calling all gurus TeeJa Webhosting 8 07-09-2006 02:10 PM

All times are GMT -5. The time now is 02:58 AM.