Post by soamjena » Tue Mar 27, 2018 7:24 pm

HI, I have 2 opencart websites running on 3.0.2.0 on a dedicated server.
Its running all latest PHP and MySQL and cloudlinux.

Since last few weeks, after the MySQL upgrade was done, both sites are crazy slow at loading, and goes down multiple times, whenever few traffic comes.

I contacted cloudlinux and they said, both sites MySQL is killing the server.

User avatar
Active Member

Posts

Joined
Mon Feb 13, 2012 3:35 pm

Post by soamjena » Tue Mar 27, 2018 7:24 pm

This is what they replied,
Hello,
As I can see, the server is overloaded at the moment due to high amount of SELECT queries. Please check attached log.
According to perf top, most of the time MySQL stacks on JOIN::exec:


# perf top -g

- 92.42% 0.01% libc-2.12.so [.] __GI___ioctl ◆
- __GI___ioctl ▒
- 50.82% my_pthread_lvemutex_lock ▒
- 97.18% key_cache_read ▒
- _mi_fetch_keypage ▒
- 99.70% _mi_search ▒
- 73.98% mi_rkey ▒
99.99% ha_myisam::index_read_map(unsigned char*, unsigned char const*, unsigned long, ha_rkey_function) ▒
- handler::ha_index_read_map(unsigned char*, unsigned char const*, unsigned long, ha_rkey_function) ▒
- 81.65% 0xce2a39 ▒
- sub_select(JOIN*, QEP_TAB*, bool) ▒
- 89.94% 0xce618e ▒
- sub_select(JOIN*, QEP_TAB*, bool) ▒
- 53.28% 0xce618e ▒
- sub_select(JOIN*, QEP_TAB*, bool) ▒
- 73.77% JOIN::exec() ▒
handle_query(THD*, LEX*, Query_result*, unsigned long long, unsigned long long)

User avatar
Active Member

Posts

Joined
Mon Feb 13, 2012 3:35 pm

Post by soamjena » Tue Mar 27, 2018 8:10 pm

# mysqladmin pr
+-------+------------------+-----------+---------------------+---------+------+--------------+------------------------------------------------------------------------------------------------------+
| Id | User | Host | db | Command | Time | State | Info |
+-------+------------------+-----------+---------------------+---------+------+--------------+------------------------------------------------------------------------------------------------------+
| 4 | lvestats2 | localhost | db_lvestats2 | Sleep | 1 | | |
| 29970 | qubesys_clients | localhost | qubesys_new-qube-db | Query | 3 | Sending data | SELECT COUNT(DISTINCT p.product_id) AS total FROM oc_category_path cp LEFT JOIN oc_product_to_catego |
| 30004 | qubesys_clients | localhost | qubesys_new-qube-db | Query | 2 | Sending data | SELECT COUNT(DISTINCT p.product_id) AS total FROM oc_category_path cp LEFT JOIN oc_product_to_catego |
| 30032 | qubesys_clients | localhost | qubesys_new-qube-db | Query | 3 | Sending data | SELECT COUNT(DISTINCT p.product_id) AS total FROM oc_category_path cp LEFT JOIN oc_product_to_catego |
| 30082 | qubesys_clients | localhost | qubesys_new-qube-db | Query | 2 | Sending data | SELECT COUNT(DISTINCT p.product_id) AS total FROM oc_category_path cp LEFT JOIN oc_product_to_catego |
| 30105 | qubesys_clients | localhost | qubesys_new-qube-db | Query | 2 | Sending data | SELECT COUNT(DISTINCT p.product_id) AS total FROM oc_category_path cp LEFT JOIN oc_product_to_catego |
| 30128 | qubesys_clients | localhost | qubesys_new-qube-db | Query | 19 | Sending data | SELECT COUNT(DISTINCT p.product_id) AS total FROM oc_category_path cp LEFT JOIN oc_product_to_catego |
| 30153 | qubesys_clients | localhost | qubesys_new-qube-db | Query | 2 | Sending data | SELECT COUNT(DISTINCT p.product_id) AS total FROM oc_category_path cp LEFT JOIN oc_product_to_catego |
| 30156 | qubesys_clients | localhost | qubesys_new-qube-db | Query | 2 | Sending data | SELECT COUNT(DISTINCT p.product_id) AS total FROM oc_category_path cp LEFT JOIN oc_product_to_catego |
| 30159 | superbik_clients | localhost | superbik_devnew | Query | 2 | Sending data | SELECT COUNT(DISTINCT p.product_id) AS total FROM oc_category_path cp LEFT JOIN oc_product_to_catego |
| 30161 | superbik_clients | localhost | superbik_devnew | Query | 5 | Sending data | SELECT COUNT(DISTINCT p.product_id) AS total FROM oc_category_path cp LEFT JOIN oc_product_to_catego |
| 30164 | superbik_clients | localhost | superbik_devnew | Query | 1 | Sending data | SELECT COUNT(DISTINCT p.product_id) AS total FROM oc_category_path cp LEFT JOIN oc_product_to_catego |
| 30165 | superbik_clients | localhost | superbik_devnew | Query | 1 | Sending data | SELECT COUNT(DISTINCT p.product_id) AS total FROM oc_category_path cp LEFT JOIN oc_product_to_catego |
| 30166 | superbik_clients | localhost | superbik_devnew | Query | 5 | Sending data | SELECT COUNT(DISTINCT p.product_id) AS total FROM oc_category_path cp LEFT JOIN oc_product_to_catego |
| 30167 | superbik_clients | localhost | superbik_devnew | Query | 1 | Sending data | SELECT COUNT(DISTINCT p.product_id) AS total FROM oc_category_path cp LEFT JOIN oc_product_to_catego |
| 30171 | superbik_clients | localhost | superbik_devnew | Query | 1 | Sending data | SELECT COUNT(DISTINCT p.product_id) AS total FROM oc_category_path cp LEFT JOIN oc_product_to_catego |
| 30174 | superbik_clients | localhost | superbik_devnew | Query | 5 | Sending data | SELECT COUNT(DISTINCT p.product_id) AS total FROM oc_category_path cp LEFT JOIN oc_product_to_catego |
| 30176 | superbik_clients | localhost | superbik_devnew | Query | 5 | Sending data | SELECT COUNT(DISTINCT p.product_id) AS total FROM oc_category_path cp LEFT JOIN oc_product_to_catego |
| 30178 | qubesys_clients | localhost | qubesys_new-qube-db | Query | 2 | Sending data | SELECT COUNT(DISTINCT p.product_id) AS total FROM oc_category_path cp LEFT JOIN oc_product_to_catego |
| 30180 | superbik_clients | localhost | superbik_devnew | Query | 1 | Sending data | SELECT COUNT(DISTINCT p.product_id) AS total FROM oc_category_path cp LEFT JOIN oc_product_to_catego |
| 30181 | superbik_clients | localhost | superbik_devnew | Query | 1 | Sending data | SELECT COUNT(DISTINCT p.product_id) AS total FROM oc_category_path cp LEFT JOIN oc_product_to_catego |
| 30185 | qubesys_clients | localhost | qubesys_new-qube-db | Query | 1 | Sending data | SELECT COUNT(DISTINCT p.product_id) AS total FROM oc_category_path cp LEFT JOIN oc_product_to_catego |
| 30188 | superbik_clients | localhost | superbik_devnew | Query | 5 | Sending data | SELECT COUNT(DISTINCT p.product_id) AS total FROM oc_category_path cp LEFT JOIN oc_product_to_catego |
| 30189 | superbik_clients | localhost | superbik_devnew | Query | 1 | Sending data | SELECT COUNT(DISTINCT p.product_id) AS total FROM oc_category_path cp LEFT JOIN oc_product_to_catego |
| 30197 | qubesys_clients | localhost | qubesys_new-qube-db | Query | 2 | Sending data | SELECT COUNT(DISTINCT p.product_id) AS total FROM oc_category_path cp LEFT JOIN oc_product_to_catego |
| 30199 | superbik_clients | localhost | superbik_devnew | Query | 1 | Sending data | SELECT COUNT(DISTINCT p.product_id) AS total FROM oc_category_path cp LEFT JOIN oc_product_to_catego |
| 30203 | superbik_clients | localhost | superbik_devnew | Query | 4 | Sending data | SELECT COUNT(DISTINCT p.product_id) AS total FROM oc_category_path cp LEFT JOIN oc_product_to_catego |
| 30204 | superbik_clients | localhost | superbik_devnew | Query | 1 | Sending data | SELECT COUNT(DISTINCT p.product_id) AS total FROM oc_category_path cp LEFT JOIN oc_product_to_catego |
| 30210 | superbik_clients | localhost | superbik_devnew | Query | 5 | Sending data | SELECT COUNT(DISTINCT p.product_id) AS total FROM oc_category_path cp LEFT JOIN oc_product_to_catego |
| 30212 | superbik_clients | localhost | superbik_devnew | Query | 1 | Sending data | SELECT COUNT(DISTINCT p.product_id) AS total FROM oc_category_path cp LEFT JOIN oc_product_to_catego |
| 30215 | superbik_clients | localhost | superbik_devnew | Query | 1 | Sending data | SELECT COUNT(DISTINCT p.product_id) AS total FROM oc_category_path cp LEFT JOIN oc_product_to_catego |
| 30216 | qubesys_clients | localhost | qubesys_new-qube-db | Query | 2 | Sending data | SELECT COUNT(DISTINCT p.product_id) AS total FROM oc_category_path cp LEFT JOIN oc_product_to_catego |
| 30218 | qubesys_clients | localhost | qubesys_new-qube-db | Query | 1 | Sending data | SELECT COUNT(DISTINCT p.product_id) AS total FROM oc_category_path cp LEFT JOIN oc_product_to_catego |
| 30220 | superbik_clients | localhost | superbik_devnew | Query | 5 | Sending data | SELECT COUNT(DISTINCT p.product_id) AS total FROM oc_category_path cp LEFT JOIN oc_product_to_catego |
| 30221 | superbik_clients | localhost | superbik_devnew | Query | 5 | Sending data | SELECT COUNT(DISTINCT p.product_id) AS total FROM oc_category_path cp LEFT JOIN oc_product_to_catego |
| 30222 | superbik_clients | localhost | superbik_devnew | Query | 5 | Sending data | SELECT COUNT(DISTINCT p.product_id) AS total FROM oc_category_path cp LEFT JOIN oc_product_to_catego |
| 30223 | superbik_clients | localhost | superbik_devnew | Query | 1 | Sending data | SELECT COUNT(DISTINCT p.product_id) AS total FROM oc_category_path cp LEFT JOIN oc_product_to_catego |
| 30228 | superbik_clients | localhost | superbik_devnew | Query | 5 | Sending data | SELECT COUNT(DISTINCT p.product_id) AS total FROM oc_category_path cp LEFT JOIN oc_product_to_catego |
| 30232 | root | localhost | | Query | 0 | starting | show processlist |
+-------+------------------+-----------+---------------------+---------+------+--------------+------------------------------------------------------------------------------------------------------+

User avatar
Active Member

Posts

Joined
Mon Feb 13, 2012 3:35 pm

Post by straightlight » Tue Mar 27, 2018 10:09 pm

Over 30000 product IDs, there really isn't any doubt regarding performance issues at this point also depending on the host packaging you're currently using even when owning your own servers unless using your own data center and, even there, the platform resources must be well-maintained.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by soamjena » Wed Mar 28, 2018 12:28 am

total products only 700.

Not 30k

User avatar
Active Member

Posts

Joined
Mon Feb 13, 2012 3:35 pm

Post by straightlight » Wed Mar 28, 2018 12:32 am

How many products do the SQL queries pulls in average per queries?

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by soamjena » Wed Mar 28, 2018 12:35 am

Im not very good at MySQL.
I contacted cloudlinix, as I can see sites going down and loading very slow and they told me this.
I just have 700 products in backend

User avatar
Active Member

Posts

Joined
Mon Feb 13, 2012 3:35 pm

Post by straightlight » Wed Mar 28, 2018 1:39 am

Let's build a little diagnostic about this.

In catalog/controller/common/footer.php file,

find:

Code: Select all

$data['scripts'] = $this->document->getScripts('footer');
add above:

Code: Select all

if ((!empty($this->session->data['user_token']) || (!empty($this->session->data['token']))) && defined("PRINT_STATS") && PRINT_STATS == 1) {
			//-----------------------------------------------------
			//--- GZip Compression Monitor ------------------------
			//-----------------------------------------------------
			$do_gzip_compress = 0;
			
			if ($this->config->get('config_compression')) {
				if (get_php_version() >= 40004) {
					if (extension_loaded("zlib")) {
						ob_start("ob_gzhandler");
					}
				} elseif (get_php_version() > 40000 && isset($this->request->server['HTTP_ACCEPT_ENCODING'])) {
					if (preg_match("/gzip/i", $this->request->server["HTTP_ACCEPT_ENCODING"]) || preg_match("/x-gzip/i", $this->request->server["HTTP_ACCEPT_ENCODING"])) {
						if (extension_loaded("zlib")) {
							$do_gzip_compress = 1;
							
							ob_start();
							
							ob_implicit_flush(0);
						}
					}
				}
			}
			
			$start_time = microtime();
			
		    $starttime = explode(" ", $start_time);
			
		    $endtime = explode(" ", microtime());
			
		    $total_time = $endtime[0] - $starttime[0] + $endtime[1] - $starttime[1];
			
		    $sql_time = $this->db->getQueryTime();
			
		    $php_time = $total_time - $sql_time;
			
		    $gzip_text = ($this->config->get('config_compression') ? "GZIP compression enabled" : "GZIP compression disabled");
			
		    $gzip_text .= ($this->config->get('config_compression') && !extension_loaded("zlib") ? "*" : "");
			
		    printf("<p align=\"center\"><font size=\"-2\">Page generated in %f seconds with ".$this->db->getQueryCount() . " queries, spending %f seconds doing MySQL queries and %f doing PHP things. $gzip_text</font></p>", $total_time, $sql_time, $php_time);
		}

		if ((!empty($this->session->data['user_token']) || (!empty($this->session->data['token']))) && defined("PRINT_QUERIES") && PRINT_QUERIES == 1) {
		    echo implode('<br><br>', $this->db->getQueryArray());
		}

		if ((!empty($this->session->data['user_token']) || (!empty($this->session->data['token']))) && $do_gzip_compress && isset($this->request->server['HTTP_ACCEPT_ENCODING'])) {
			if (preg_match("/gzip/i", $this->request->server['HTTP_ACCEPT_ENCODING'])) {
				$encoding = "gzip";
			} elseif (preg_match("/x-gzip/i", $this->request->server["HTTP_ACCEPT_ENCODING"])) {
				$encoding = "x-gzip";
			}

			$gzip_contents = ob_get_contents();
		  
			ob_end_clean();

			if (defined("PRINT_STATS") && PRINT_STATS == 1) {
				$s = sprintf ("\n<!-- Use Encoding:         %s -->", $encoding);
			
				$s .= sprintf("\n<!-- Not compress length:  %s -->", strlen($gzip_contents));
			
				$s .= sprintf("\n<!-- Compressed length:    %s -->", strlen(gzcompress($gzip_contents, $this->config->get('config_compression'))));
			
				$gzip_contents .= $s;
			}

			$gzip_size = strlen($gzip_contents);
		  
			$gzip_crc = crc32($gzip_contents);

			$gzip_contents = gzcompress($gzip_contents, $this->config->get('config_compression'));
		  
			$gzip_contents = substr($gzip_contents, 0, strlen($gzip_contents) - 4);

			header("Content-Encoding: $encoding");
		  
			echo "\x1f\x8b\x08\x00\x00\x00\x00\x00";
		  
			echo $gzip_contents;
		  
			echo pack("V", $gzip_crc);
		  
			echo pack("V", $gzip_size);
		}
In system/library/db/mysqli.php file,

find:

Code: Select all

private $connection;
add below:

Code: Select all

private $query_time = 0;
private $query_count = 0;	
private $query_array = array();
Then, find:

Code: Select all

$result->rows = $data;
add below:

Code: Select all

if ((defined("PRINT_QUERIES") && PRINT_QUERIES == 1) || (defined("PRINT_STATS") && PRINT_STATS == 1)) {
                                        $startsqltime = explode(" ", microtime());
                                        
					$endsqltime = explode(" ", microtime());
					
					$totalsqltime = round($endsqltime[0] - $startsqltime[0] + $endsqltime[1] - $startsqltime[1], 3);
					
					$this->query_time += $totalsqltime;
					
					$this->query_count++;
				}
				
				if (defined("PRINT_QUERIES") && PRINT_QUERIES == 1) {
					$query_stats = htmlentities($sql);
					
					$query_stats .= "<br><b>Querytime:</b> ".$totalsqltime;
					
					$this->query_array[] = $query_stats;
				}
Then, find:

Code: Select all

public function escape($value) {
add above:

Code: Select all

public function getQueryCount() {
		return $this->query_count;
	}
	
	public function getQueryTime() {
		return $this->query_time;
	}
	
	public function getQueryArray() {
		return (array)$this->query_array;
	}
In system/library/db.php file,

find:

Code: Select all

/**
     * 
     *
     * @param	string	$value
	 * 
	 * @return	string
     */
	public function escape($value) {
add above:

Code: Select all

public function getQueryCount() {
		return $this->adaptor->getQueryCount();
	}
	
	public function getQueryTime() {
		return $this->adaptor->getQueryTime();
	}
	
	public function getQueryArray() {
		return $this->adaptor->getQueryArray();
	}		
In your root config.php file, add at the bottom of the file:

Code: Select all

define('PRINT_STATS', 1);
define('PRINT_QUERIES', 0);
For detailed troubleshooting, change to:

Code: Select all

define('PRINT_STATS', 1);
define('PRINT_QUERIES', 1);
1 = Enable
0 = Disable

To test this, login to your OC admin. Then, select your store and see the query results at the top of your store. I would suggest activating the PRINT_STATS only for now from your config.php file before jumping to the PRINT_QUERIES.

What is the text that you see on top of the site?
Last edited by straightlight on Thu May 16, 2019 7:54 pm, edited 1 time in total.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by soamjena » Wed Mar 28, 2018 4:43 pm

Wow, thats an extensive one.
Im afraid, something might get broken if I try your steps.
Let me see if I find someone in freelancer.com to do this steps and then will tell you what I got in print.

Thanks a ton.

User avatar
Active Member

Posts

Joined
Mon Feb 13, 2012 3:35 pm

Post by straightlight » Wed Mar 28, 2018 6:53 pm

Im afraid, something might get broken if I try your steps.
With the use of VQMod and VQMod Manager, that shouldn't happen.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by foobarac » Thu May 16, 2019 4:40 pm

Obviously no one has tried this ?

I am getting "undefined variable $startsqltime" in mysqli.php ?

New member

Posts

Joined
Fri Sep 21, 2018 9:46 pm

Post by lukeketchum1 » Thu May 16, 2019 4:44 pm

I had horrible issue with OC 3.0.2.0 load time due to a half uninstalled VQMOD. I removed VQMOD Folder, replaced index.php in root and /admin directories with the ones that come with the OC installer and it magically fixed it. Unlikely to be your issue, but just saying - it caused a terrible issue with same OC version.

Active Member

Posts

Joined
Tue Jan 23, 2018 12:30 am

Post by straightlight » Thu May 16, 2019 7:54 pm

foobarac wrote:
Thu May 16, 2019 4:40 pm
Obviously no one has tried this ?

I am getting "undefined variable $startsqltime" in mysqli.php ?
Fixed.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by foobarac » Thu May 16, 2019 7:58 pm

Thanks, but I think my problem is around the a loaded cart (20 or more tiems) and the performance of an AJAX based theme.

New member

Posts

Joined
Fri Sep 21, 2018 9:46 pm
Who is online

Users browsing this forum: dparakhiya and 420 guests