Jump to content


Corporate Sponsors


Latest News: (loading..)

* * * * * 1 votes

Massively Speed up Site and Reduce Server Load


21 replies to this topic

#1 monkeymoo1

  • Community Member
  • 2 posts
  • Real Name:Gary

Posted 08 May 2006, 21:42

Hi

Our site receives about 7000 uniques a day. With about 50,000 page views.
15 Categories + 30 ish Subcategories
3500 Products.
Our server load tends to hover around 3 or 4 - (Linux Debian 1gb Memory etc)

Looking at the Mysql logs I noticed that all the SQL seemed to be doing was counting categories even with the Mysql Cache on

Basically everytime the categories menu loaded it was counting the directorys from the DB. Thousands and thousands of times a day!!!

I removed the category count function from /catalog/includes/boxes/categories.php and removed the corresponding function in catalog/includes/functions/general.php

this bit:-

////
// Return true if the category has subcategories
// TABLES: categories
  function tep_has_category_subcategories($category_id) {
	$child_category_query = tep_db_query("select count(*) as count from " . TABLE_CATEGORIES . " where parent_id = '" . $category_id . "'");
	$child_category = tep_db_fetch_array($child_category_query);

	if ($child_category['count'] > 0) {
	  return true;
	} else {
	  return false;
	}
  }

////

The server has dropped down to a load average of 1 ish and the site absolutely zooooms now :-)

Cheers

Edited by monkeymoo1, 08 May 2006, 21:44.


#2 Jan Zonjee

  • Team Member
  • 7,001 posts
  • Real Name:Jan Zonjee
  • Gender:Male
  • Location:the Netherlands

Posted 08 May 2006, 21:57

View Postmonkeymoo1, on May 8 2006, 11:42 PM, said:

Basically everytime the categories menu loaded it was counting the directorys from the DB. Thousands and thousands of times a day!!!
I assume this contribution could handle that problem. Actually, there is a whole thread devoted to this subject with a lot more suggestions to speed up your site.

#3 swtnhpy

  • Community Member
  • 280 posts
  • Real Name:Jen

Posted 12 May 2006, 03:08

Used the contribution mentioned above...got nothing but errors with install.

#4 loosefigures

  • Community Member
  • 20 posts
  • Real Name:Michael Vetting

Posted 12 May 2006, 17:45

Are you sure there are no negative effects?

#5 swtnhpy

  • Community Member
  • 280 posts
  • Real Name:Jen

Posted 12 May 2006, 23:17

Yes, there are negative effects...bunches of errors.

#6 Jan Zonjee

  • Team Member
  • 7,001 posts
  • Real Name:Jan Zonjee
  • Gender:Male
  • Location:the Netherlands

Posted 13 May 2006, 14:26

View Postswtnhpy, on May 13 2006, 01:17 AM, said:

Yes, there are negative effects...bunches of errors.
I wonder if that is due to the contribution or your skills in adding them... :angry:

#7 insomniac2

  • Community Member
  • 407 posts
  • Real Name:Don

Posted 13 May 2006, 19:49

It may also not work correctly if you are not using a stock osc version of includes/boxes/categories.php.

There are a lot of modified categories.php files out there.

#8 swtnhpy

  • Community Member
  • 280 posts
  • Real Name:Jen

Posted 15 May 2006, 01:29

View PostJanZ, on May 13 2006, 10:26 AM, said:

I wonder if that is due to the contribution or your skills in adding them... :angry:

HMMM...that was pretty rude IMO. My skills in adding them are just fine seeing as how I have over 20 contribs added to my sites.

#9 mikey boy

  • Community Member
  • 89 posts
  • Real Name:Michael Ian Stollov
  • Location:Lynnwood, WA, USA

Posted 09 September 2006, 01:52

I'm confused. I would like to remove the Category Count overhead, but I can only find the code snippet shown below in catalog/includes/functions/general.php. I've searched catalog/includes/boxes/categories.php (unmodified) but I don't see anything like the code snppet there.

Is it different in catalog/includes/boxes/categories.php & if so what is it?

I've come across mention of removing Category Count quite oten, but this is the closest 've seen on actually how to do it.

Thanks.

Mike

View Postmonkeymoo1, on May 8 2006, 09:42 PM, said:

Our site receives about 7000 uniques a day. With about 50,000 page views.
15 Categories + 30 ish Subcategories
3500 Products.
Our server load tends to hover around 3 or 4 - (Linux Debian 1gb Memory etc)

Looking at the Mysql logs I noticed that all the SQL seemed to be doing was counting categories even with the Mysql Cache on

Basically everytime the categories menu loaded it was counting the directorys from the DB. Thousands and thousands of times a day!!!

I removed the category count function from /catalog/includes/boxes/categories.php and removed the corresponding function in catalog/includes/functions/general.php

this bit:-

////
// Return true if the category has subcategories
// TABLES: categories
  function tep_has_category_subcategories($category_id) {
	$child_category_query = tep_db_query("select count(*) as count from " . TABLE_CATEGORIES . " where parent_id = '" . $category_id . "'");
	$child_category = tep_db_fetch_array($child_category_query);

	if ($child_category['count'] > 0) {
	  return true;
	} else {
	  return false;
	}
  }

////

The server has dropped down to a load average of 1 ish and the site absolutely zooooms now :-)

Cheers


#10 eww

  • Community Member
  • 2,461 posts
  • Real Name:eww
  • Gender:Not Telling

Posted 12 September 2006, 05:36

isn't there a stock function in the admin panel that allows you to turn it off with the click of a button?
i don't remember having to remove any code to do this...
Admin -> My Store -> Show Category Counts -> false

#11 Jamez

  • Community Member
  • 108 posts
  • Real Name:James

Posted 12 September 2006, 17:06

View Posteww, on Sep 12 2006, 05:36 AM, said:

isn't there a stock function in the admin panel that allows you to turn it off with the click of a button?
i don't remember having to remove any code to do this...
Admin -> My Store -> Show Category Counts -> false
It turns it off but the queries for it still run if I remember rightly. :rolleyes:

#12 boxtel

  • Community Member
  • 5,237 posts
  • Real Name:amanda
  • Location:Taipei, Taiwan

Posted 12 September 2006, 17:44

View PostJamez, on Sep 13 2006, 01:06 AM, said:

It turns it off but the queries for it still run if I remember rightly. :rolleyes:

nope
Treasurer MFC

#13 kyotee

  • Community Member
  • 54 posts
  • Real Name:Bill

Posted 21 December 2006, 21:14

installed the contrib that JanZ mentioned and noticed a huge increase in speed.....thanks

#14 sleepy_hero

  • Community Member
  • 1 posts
  • Real Name:sleepy

Posted 31 January 2007, 00:24

THANKS MAN, IT WORKED WELL ENOUGH FOR ALL MY OSC SITES.



View Postmonkeymoo1, on May 8 2006, 01:42 PM, said:

Hi

Our site receives about 7000 uniques a day. With about 50,000 page views.
15 Categories + 30 ish Subcategories
3500 Products.
Our server load tends to hover around 3 or 4 - (Linux Debian 1gb Memory etc)

Looking at the Mysql logs I noticed that all the SQL seemed to be doing was counting categories even with the Mysql Cache on

Basically everytime the categories menu loaded it was counting the directorys from the DB. Thousands and thousands of times a day!!!

I removed the category count function from /catalog/includes/boxes/categories.php and removed the corresponding function in catalog/includes/functions/general.php

this bit:-

////
// Return true if the category has subcategories
// TABLES: categories
  function tep_has_category_subcategories($category_id) {
	$child_category_query = tep_db_query("select count(*) as count from " . TABLE_CATEGORIES . " where parent_id = '" . $category_id . "'");
	$child_category = tep_db_fetch_array($child_category_query);

	if ($child_category['count'] > 0) {
	  return true;
	} else {
	  return false;
	}
  }

////

The server has dropped down to a load average of 1 ish and the site absolutely zooooms now :-)

Cheers


#15 zalik22

  • Community Member
  • 217 posts
  • Real Name:Zahed Khan
  • Location:Atlanta, GA

Posted 04 February 2007, 01:36

View Postmonkeymoo1, on May 8 2006, 04:42 PM, said:

Hi

Our site receives about 7000 uniques a day. With about 50,000 page views.
15 Categories + 30 ish Subcategories
3500 Products.
Our server load tends to hover around 3 or 4 - (Linux Debian 1gb Memory etc)

Looking at the Mysql logs I noticed that all the SQL seemed to be doing was counting categories even with the Mysql Cache on

Basically everytime the categories menu loaded it was counting the directorys from the DB. Thousands and thousands of times a day!!!

I removed the category count function from /catalog/includes/boxes/categories.php and removed the corresponding function in catalog/includes/functions/general.php

this bit:-

////
// Return true if the category has subcategories
// TABLES: categories
  function tep_has_category_subcategories($category_id) {
	$child_category_query = tep_db_query("select count(*) as count from " . TABLE_CATEGORIES . " where parent_id = '" . $category_id . "'");
	$child_category = tep_db_fetch_array($child_category_query);

	if ($child_category['count'] > 0) {
	  return true;
	} else {
	  return false;
	}
  }

////

The server has dropped down to a load average of 1 ish and the site absolutely zooooms now :-)

Cheers

I removed the code above, what do you mean exactly by "I removed the category count function from /catalog/includes/boxes/categories.php." Can you tell me what code to comment out/delete? I am not sure what to delete.

Thanks!

#16 nutbolt

  • Community Member
  • 4 posts
  • Real Name:Stuart

Posted 23 May 2011, 12:01

This works in reducing a query in OSC 2.3.1 as well

in Catalog\includes\modules\boxes\bm_categories.php around line 61 comment out (using //) the following:

 // if (tep_has_category_subcategories($counter)) {
     //   $categories_string .= '->';
     // }

in Catalog\includes\functions\general.php around line 421 comment out the following:

////
// Return true if the category has subcategories
// TABLES: categories
//  function tep_has_category_subcategories($category_id) {
//    $child_category_query = tep_db_query("select count(*) as count from " . TABLE_CATEGORIES . " where parent_id = '" . (int)$category_id . "'");
//    $child_category = tep_db_fetch_array($child_category_query);
//
//    if ($child_category['count'] > 0) {
//      return true;
 //   } else {
 //     return false;
 //   }
//  }

IMHO a waste of a query just to show a silly ..> after the subcategory and it slows your site down especially if you have loads of subcategories, the query has to array all of them first.

#17 nutbolt

  • Community Member
  • 4 posts
  • Real Name:Stuart

Posted 23 May 2011, 16:27

View Postnutbolt, on 23 May 2011, 12:01, said:

This works in reducing a query in OSC 2.3.1 as well

in Catalog\includes\modules\boxes\bm_categories.php around line 61 comment out (using //) the following:

 // if (tep_has_category_subcategories($counter)) {
     //   $categories_string .= '->';
     // }

in Catalog\includes\functions\general.php around line 421 comment out the following:

////
// Return true if the category has subcategories
// TABLES: categories
//  function tep_has_category_subcategories($category_id) {
//    $child_category_query = tep_db_query("select count(*) as count from " . TABLE_CATEGORIES . " where parent_id = '" . (int)$category_id . "'");
//    $child_category = tep_db_fetch_array($child_category_query);
//
//    if ($child_category['count'] > 0) {
//      return true;
 //   } else {
 //     return false;
 //   }
//  }

IMHO a waste of a query just to show a silly ..> after the subcategory and it slows your site down especially if you have loads of subcategories, the query has to array all of them first.

Ignore the above and delete the // as it seems to fail when you go in deeper to the sub cats.. oh well

#18 fbas

  • Community Member
  • 7 posts

Posted 07 June 2011, 18:19

a reasonable workaround might be to simply cache the category counts once daily (or when admin alters categories) so you get the benefit of that info without the overhead.

#19 panicgripdesigns

  • Community Member
  • 44 posts
  • Real Name:Vince
  • Gender:Male

Posted 14 July 2011, 07:21

The most recent poster is not commenting out product counts, which would be helpful. He/she is commenting out a query to test for SUBCATEGORIES. Bad idea...

(Not trying to sound rude. Sorry its late and I'm tyoing on my cell)

Edited by panicgripdesigns, 14 July 2011, 07:24.

A little knowledge of php goes a long way.

#20 Rabaeys

  • Community Member
  • 11 posts
  • Real Name:Rabaeys H
  • Gender:Male
  • Location:Belgie

Posted 03 September 2011, 21:15

I have used some of the code from the contribution and they gave a huge boost in performance. I have not used all of them because I got some errors.
But I think this comes because I the contribution is written for osc 2.2 and not for 2.3