opencart电子商务网站的第一个字节时间很长

时间:2014-08-30 12:30:25

标签: php mysql nginx opencart

我检查了电子商务网站http://www.webpagetest.org/上的网站统计信息:它提供了以下报告----

Document Complete   Fully Loaded
Load Time   First Byte  Start Render    Speed Index DOM Elements    Time    Requests    Bytes In        Time    Requests    Bytes In
First View  20.995s 15.718s 16.492s 19760   1177    20.995s 117 2,357 KB    22.904s 161 2,827 KB
Repeat View 9.804s  8.200s  8.623s  9596    1177    9.804s  10  351 KB  11.276s 37  476 KB

我用top命令&检查了我的服务器检查mysql时间为CPU%TIME+时间为mysql> show variables like 'innodb_buffer_pool_size'; +-------------------------+-----------+ | Variable_name | Value | +-------------------------+-----------+ | innodb_buffer_pool_size | 134217728 | +-------------------------+-----------+ 1 row in set (0.00 sec) mysql> show variables like 'innodb_flush_log_at_trx_commit'; +--------------------------------+-------+ | Variable_name | Value | +--------------------------------+-------+ | innodb_flush_log_at_trx_commit | 1 | +--------------------------------+-------+ 1 row in set (0.00 sec) mysql> show variables like 'innodb_open_files'; +-------------------+-------+ | Variable_name | Value | +-------------------+-------+ | innodb_open_files | 300 | +-------------------+-------+ 1 row in set (0.00 sec) mysql> show variables like 'innodb_table_locks'; +--------------------+-------+ | Variable_name | Value | +--------------------+-------+ | innodb_table_locks | ON | +--------------------+-------+ 1 row in set (0.00 sec) mysql> show variables like 'innodb_thread_concurrency'; +---------------------------+-------+ | Variable_name | Value | +---------------------------+-------+ | innodb_thread_concurrency | 0 | +---------------------------+-------+ 1 row in set (0.00 sec) mysql> show variables like 'join_buffer_size'; +------------------+--------+ | Variable_name | Value | +------------------+--------+ | join_buffer_size | 131072 | +------------------+--------+ 1 row in set (0.00 sec) mysql> show variables like 'key_buffer_size'; +-----------------+----------+ | Variable_name | Value | +-----------------+----------+ | key_buffer_size | 16777216 | +-----------------+----------+ 1 row in set (0.00 sec) mysql> show variables like 'max_connections'; +-----------------+-------+ | Variable_name | Value | +-----------------+-------+ | max_connections | 151 | +-----------------+-------+ 1 row in set (0.00 sec) mysql> show variables like 'max_delayed_threads'; +---------------------+-------+ | Variable_name | Value | +---------------------+-------+ | max_delayed_threads | 20 | +---------------------+-------+ 1 row in set (0.00 sec) mysql> show variables like 'max_heap_table_size'; +---------------------+----------+ | Variable_name | Value | +---------------------+----------+ | max_heap_table_size | 16777216 | +---------------------+----------+ 1 row in set (0.00 sec) mysql> show variables like 'max_tmp_tables'; +----------------+-------+ | Variable_name | Value | +----------------+-------+ | max_tmp_tables | 32 | +----------------+-------+ 1 row in set (0.01 sec) mysql> show variables like 'thread_cache_size'; +-------------------+-------+ | Variable_name | Value | +-------------------+-------+ | thread_cache_size | 8 | +-------------------+-------+ 1 row in set (0.00 sec) mysql> show variables like 'tmp_table_size'; +----------------+----------+ | Variable_name | Value | +----------------+----------+ | tmp_table_size | 16777216 | +----------------+----------+ 1 row in set (0.00 sec) mysql> show variables like 'wait_timeout'; +---------------+-------+ | Variable_name | Value | +---------------+-------+ | wait_timeout | 28800 | +---------------+-------+ 1 row in set (0.00 sec) mysql> show variables like 'myisam_sort_buffer_size'; +-------------------------+---------+ | Variable_name | Value | +-------------------------+---------+ | myisam_sort_buffer_size | 8388608 | +-------------------------+---------+ 1 row in set (0.00 sec) 时间为214:26.79。

之前mysql表没有优化,所以我创建了那些表的索引。之后,加载时间大大减少。现在我遇到了第一个字节的问题。以下是mysql变量:

mysql

我认为第一个字节的延迟主要是由于opencart配置或{{1}}框架。我已经采取措施优化运行网站的nginx。如何减少第一个字节时间?请帮忙。

1 个答案:

答案 0 :(得分:1)

我解决了这个问题。 问题出在opencart数据库索引系统上。因为他们没有正确索引表格 - 一些与product_tags& url_alias过去需要很长时间才能执行。由于它们锁定了这些表,因此序列中的其他查询无法访问它们。在客户端为第一个字节创建了相当大的延迟。

解决方案是为所有这些表创建索引,查询需要花费相当长的时间。我的延迟时间减少到原来的十分之一。 (有关进一步的信息和详细信息,请查看opencart论坛 - 这是OC用户非常常见的问题)