Resend my activation email : Register : Log in 
BCF: Bike Chat Forums


Speeding up cross server queries

Reply to topic
Bike Chat Forums Index -> The Geek Zone
View previous topic : View next topic  
Author Message

Phil.
World Chat Champion



Joined: 02 Feb 2002
Karma :

PostPosted: 20:28 - 08 Nov 2010    Post subject: Speeding up cross server queries Reply with quote

Hi

I am having some troubles with the performance of a report which pulls data from a few servers which I hope someone can give me a pointer or 2 with.

The way I'm doing it at the moment is connecting to each server's database in turn, running the queries I need to and storing the data in one big array before doing some calculations on and outputting.

It works well for smaller amounts of data but when large date ranges are pulled it pretty much grinds to a halt. It's not the query themselves as they run fast enough on the local host.

If anyone has any experience with this or could suggest some things which may help speed up cross server querying, i'd appreciate it.

Thanks
 Back to top
View user's profile Send private message Visit poster's website You must be logged in to rate posts

Frost
World Chat Champion



Joined: 26 May 2004
Karma :

PostPosted: 21:19 - 08 Nov 2010    Post subject: Reply with quote

SQL is the shit. Need to pull some complex data, it's much faster to use a huge SQL query than it is to pull data you don't need - transfer it over a connection - then process it with a slow scripting language. I've seen 100+ line SQL queries run in milliseconds. You can be fancy and use multi threading to pull data from both servers at once which will make the time taken to execute the queries less noticeable, but won't help much with the transfer times.
 Back to top
View user's profile Send private message Send e-mail You must be logged in to rate posts

Jayy
Mr. Ponzi



Joined: 08 Jun 2009
Karma :

PostPosted: 11:13 - 09 Nov 2010    Post subject: Reply with quote

Large SQL databases seem to fuck servers up and grind them to a halt as you say. I've spent hours on 2gb + databases trying to back them up and then restore them and had to break them down into small chunks in order to do it.

I don't know of any way to do what you're saying though unfortunately.
 Back to top
View user's profile Send private message You must be logged in to rate posts

ajag
Brolly Dolly



Joined: 08 Aug 2010
Karma :

PostPosted: 11:25 - 09 Nov 2010    Post subject: Reply with quote

which database server are you using? SQL server, oracle, mySQL?
____________________
Street Triple
 Back to top
View user's profile Send private message Send e-mail You must be logged in to rate posts

panrider_uk
World Chat Champion



Joined: 23 Sep 2007
Karma :

PostPosted: 11:48 - 09 Nov 2010    Post subject: Reply with quote

Recoil Jay wrote:
I've spent hours on 2gb + databases trying to back them up and then restore them and had to break them down into small chunks in order to do it.


Try Symantec's Backup Exec System Recovery product.

Its an excellent backup solution (was developed by Powerquest) which also allows you to restore your server to dissimilar hardware if you need to.

Mark
____________________
Current bikes: Honda ST1100 Pan European. Moto Guzzi V85 TT Travel
 Back to top
View user's profile Send private message You must be logged in to rate posts

ajag
Brolly Dolly



Joined: 08 Aug 2010
Karma :

PostPosted: 12:08 - 09 Nov 2010    Post subject: Re: Speeding up cross server queries Reply with quote

SummY wrote:
Hi

I am having some troubles with the performance of a report which pulls data from a few servers which I hope someone can give me a pointer or 2 with.

The way I'm doing it at the moment is connecting to each server's database in turn, running the queries I need to and storing the data in one big array before doing some calculations on and outputting.

It works well for smaller amounts of data but when large date ranges are pulled it pretty much grinds to a halt. It's not the query themselves as they run fast enough on the local host.

If anyone has any experience with this or could suggest some things which may help speed up cross server querying, i'd appreciate it.

Thanks


We need to know the database server and programming language/script you are using.

A query is a query and it should run in the same time whether you run it locally or remote. However, transfering the data is a different story which is why we might need to see hos you are calling these queries remotely.
____________________
Street Triple
 Back to top
View user's profile Send private message Send e-mail You must be logged in to rate posts

ajag
Brolly Dolly



Joined: 08 Aug 2010
Karma :

PostPosted: 12:10 - 09 Nov 2010    Post subject: Reply with quote

Recoil Jay wrote:
Large SQL databases seem to fuck servers up and grind them to a halt as you say. I've spent hours on 2gb + databases trying to back them up and then restore them and had to break them down into small chunks in order to do it.

I don't know of any way to do what you're saying though unfortunately.


again, what database server are you using? Are you taking the DB offline before doing the back up so that users cannot access it while you are doing the back up? Are you doing a complete backup every time or incrementals?
____________________
Street Triple
 Back to top
View user's profile Send private message Send e-mail You must be logged in to rate posts

Phil.
World Chat Champion



Joined: 02 Feb 2002
Karma :

PostPosted: 13:06 - 09 Nov 2010    Post subject: Reply with quote

Hi

I'm running PHP & MySQL.

Here's part of the cross database connection class
Code:

function link($site){
      return @mysql_connect($this->sites[$site]['url'],$this->sites[$site]['db_user'],$this->sites[$site]['db_pass']);
}
   
function fetch_query($sql,$site){
      @mysql_select_db($this->sites[$site]['db_table'],$this->link($site)) or die ("Unable to open database");
      return @mysql_query($sql,$this->link($site));
      mysql_close($this->link($site));
}



Using this I just select which site I want to access and run the query. One server holds a few sites which runs fine, it's the other servers which slow it down.
 Back to top
View user's profile Send private message Visit poster's website You must be logged in to rate posts

ajag
Brolly Dolly



Joined: 08 Aug 2010
Karma :

PostPosted: 13:25 - 09 Nov 2010    Post subject: Reply with quote

hmmm, I am not good with PHP so can't really comment on your code. However, if the query returns ok for one server and not hte other, I would probably start looking at the differences between the servers and the infrastructure around them.

How many rows is your query returning? I know for a fact that in MS SQL Server if your SQL returns more than 75k rows (I believe) it locks down the whole table for you and no one can read or write to it until you are done. Not sure if the same is true for MySQL but maybe another system is doing that for you?
____________________
Street Triple
 Back to top
View user's profile Send private message Send e-mail You must be logged in to rate posts

Kai.Wilson
Spanner Monkey



Joined: 26 Sep 2009
Karma :

PostPosted: 13:31 - 09 Nov 2010    Post subject: Reply with quote

could be your server blocking multiple conections,

I know some dont allow for then 10 conections at a time from anyone IP to stop DDoS attacks.
 Back to top
View user's profile Send private message You must be logged in to rate posts

TQ
Trackday Trickster



Joined: 17 Dec 2009
Karma :

PostPosted: 14:03 - 09 Nov 2010    Post subject: Reply with quote

It might be unrelated and might not even be right but it looks like the "mysql_close($this->link($site)); " line is not being executed because it is after the "return" statement.

In other languages once a function returns no code after that line will be executed, don't know if it's the same in php.
____________________
First Bike :Gilera DNA 50 | Second: Imported 1989 NSR125
Third: 1998 Yamaha XJ600N | Currently: 1999 Yamaha FZS600
 Back to top
View user's profile Send private message You must be logged in to rate posts

Frost
World Chat Champion



Joined: 26 May 2004
Karma :

PostPosted: 14:11 - 09 Nov 2010    Post subject: Reply with quote

He's right it's not closing the connection. Also make sure your sanitising your database inputs.

What is the actual query that's running?
 Back to top
View user's profile Send private message Send e-mail You must be logged in to rate posts

Phil.
World Chat Champion



Joined: 02 Feb 2002
Karma :

PostPosted: 11:20 - 10 Nov 2010    Post subject: Reply with quote

Hi

Thanks for pointing out that bug and all the suggestions that have been made.

More calculations are being done in PHP than are necessary so I'm going to move as much to sql as possible. Also going to try experimenting with table views to see if that has much impact on the speed.

Thanks
 Back to top
View user's profile Send private message Visit poster's website You must be logged in to rate posts

Kickstart
The Oracle



Joined: 04 Feb 2002
Karma :

PostPosted: 17:01 - 10 Nov 2010    Post subject: Reply with quote

Hi

Views in MySQL are just for convenience. They have no performance benefits.

While keeping it in an SQL query will give the best performance, if you need multiple queries on the same database to get a final amount of info (which would suggest a poor database design, but sometimes necessary) then it might be best to have a php script running on the other database servers to do the intermediate processing, and only return the final info required.

All the best

Keith
____________________
Traxpics, track day and racing photographs - Bimota Forum - Bike performance / thrust graphs for choosing gearing
 Back to top
View user's profile Send private message Send e-mail You must be logged in to rate posts

Frost
World Chat Champion



Joined: 26 May 2004
Karma :

PostPosted: 18:54 - 10 Nov 2010    Post subject: Reply with quote

If it's an unavoidable mega query that takes minutes to perform even when optimised, you can run it as a scheduled task. E.g Pull all data from everywhere and do loads of processing every hour, store result in table, pull from that table when needed. Obviously some data will be up to an hour out of date, but sometimes that's acceptable.
 Back to top
View user's profile Send private message Send e-mail You must be logged in to rate posts
Old Thread Alert!

The last post was made 15 years, 307 days ago. Instead of replying here, would creating a new thread be more useful?
  Display posts from previous:   
This page may contain affiliate links, which means we may earn a small commission if a visitor clicks through and makes a purchase. By clicking on an affiliate link, you accept that third-party cookies will be set.

Post new topic   Reply to topic    Bike Chat Forums Index -> The Geek Zone All times are GMT + 1 Hour
Page 1 of 1

 
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
You cannot attach files in this forum
You cannot download files in this forum

Read the Terms of Use! - Powered by phpBB © phpBB Group
 

Debug Mode: ON - Server: birks (www) - Page Generation Time: 0.09 Sec - Server Load: 0.45 - MySQL Queries: 13 - Page Size: 88.34 Kb