Jump to content
MakeWebGames

Recommended Posts

Posted

Well im on a mission of reducing my server load and come to the globals.php.

 

Ive reduced query load by making the queries better via the header.php alone however is there anything that can be done in globals.php.

 

The queries in globals run every page load so Im after gaining some more performance. I dont see anything that can be done myself but I may have missed something. Can the existing queries be better constructed???

 

Any info would be great.

 

Many thx

Chaos

Posted

HI sorry. Was assuming everyone has the file to check this.

 

The queries I refer to are -

 

 

 
global $jobquery, $housequery; 
if($jobquery) 
{ 
$is=$db->query("SELECT u.*,us.*,j.*,jr.* FROM users u LEFT JOIN userstats us ON u.userid=us.userid LEFT JOIN jobs j ON j.jID=u.job LEFT JOIN jobranks jr ON jr.jrID=u.jobrank WHERE u.userid=$userid"); 
} 
else if($housequery) 
{ 
$is=$db->query("SELECT u.*,us.*,h.* FROM users u LEFT JOIN userstats us ON u.userid=us.userid LEFT JOIN houses h ON h.hWILL=u.maxwill WHERE u.userid=$userid"); 
} 
else 
{ 
$is=$db->query("SELECT u.*,us.* FROM users u LEFT JOIN userstats us ON u.userid=us.userid WHERE u.userid=$userid"); 
} 
$ir=$db->fetch_row($is); 

 

 

Can these queries be improved. Thet are usally in effect the most so if any performance can be gained I wish to take it.

Posted

Them queries so they can be used to pull every single column in all of the selected tables so i wouldn't think there is a way, short of predefining all columns at beginning of files and inputting that above require "globals.php"; (possible), i may actually do this unless someone thinks of a better solution.

Posted

In the past, I thought about optimizing it like so:

On EVERY mccode page, add a string variable above the include "globals.php"; line.

The string character will contain a comma separated list of all the fields from the users table used on that page.

E. G. $userfields=",crytalbank, crystalsstored";

In globals.php, the query would look like:

$db->query("SELECT money,exp,username,userid{$userfields} WHERE userid=$userid ");

or something along those lines. So in globals.php you would have it load all the variables that are used on every page like username/money/level, and then in the userfields variable have it store (and thus, load) those variables that are only used on specific pages.

May not be the most efficient, but that's the idea I had floating around in my head.

Posted

main file

<?php
$information_user = '`username`, `userid`';
include "globals.php";
echo $ir['username'].'
'.$ir['userid'];
?>

 

globals $ir...

if ( !empty($information_user) ) {
$sql = sprintf('SELECT $information_user FROM `users` WHERE `userid` = %u', $userid);
$is = mysql_query($sql);
}
else {
$sql = sprintf('SELECT * FROM `users` WHERE `userid` = %u', $userid);
$is = mysql_query($sql);
}

 

doesn't seem so hard

Posted

This idea intrigues me a bit, although i do not think i will be attempting it for an existing game. Would be something i would try for a game that is not open and in the case of Mccodes is being rewritten page by page.

Posted

As I already stated to Zerro in the chat, this would in principle have some impact if your web server and mysql server are 2 different machines. However on the same machine (as most of the setups are), you don't really see much of difference, if any. At least that's what I saw from my own experiences.

Posted

Well basically what I saw is the following:

Unless a full table row is REALLY huge, doing a select * is not much slower (if even slower) than a select a,c,e,z

From my point of view, this make sense as the database will need to somehow read the row basically.... and just give you the data back you asked. Also, if your queries changes all the time, it would not be possible to MySQL to cache the query results. Therefore you could even have worse results.

On the other side, if you need to transfer the query over the network, all bytes counts, and therefore returning just what you need is faster.

As always, don't trust my words, do some checks by yourself and tell me if you get different results.

Posted
Well basically what I saw is the following:

Unless a full table row is REALLY huge, doing a select * is not much slower (if even slower) than a select a,c,e,z

From my point of view, this make sense as the database will need to somehow read the row basically.... and just give you the data back you asked. Also, if your queries changes all the time, it would not be possible to MySQL to cache the query results. Therefore you could even have worse results.

On the other side, if you need to transfer the query over the network, all bytes counts, and therefore returning just what you need is faster.

As always, don't trust my words, do some checks by yourself and tell me if you get different results.

It would be interesting to see at what point the row is large enough to start eliminating fields from the query. I've altered a few event queries to only select what is needed instead of all of it (read, time, etc). I noticed a big difference in speed but i didnt record the actual time variance. I'm sure the amount of data in the table impacts this as well.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...