Resolving slow site performance

Slow website - it's a widely known problem of almost every web developer. Suffer from this in the first place visitors resource, with negative responsive to the slightest delay in updating information. The site administrator must understand that if you do not solve this problem quickly, you can not only lose some of their clients, but also lose your income. Common problem is the download speed as it can take some time to load your website page (as separate parts, and the entire page). Data transmission speed over the public switched internet channels may differ, so simple and obvious reason may be the low-speed data transfer from the server to the user. The source of the problem in the connection speed to the Internet, as ordinary telephone (switched) line, or Dial-up line  can give you a maximum speed not more than 57.6 kbit/s, but in Russian this speed is almost impossible to reach over the telephone network.

Basically, the phone line gives the speed, which can not be considered as normal. The rate above 33.6 kbit/s is on the protocols k56flex, V90, V92 and X2, which are known to require excellent quality of the telephone line. Most telephone cables in Russia at the moment is a pair of copper sandwiched, in conditions unsuitable for use: they cannot provide a good signal. Fiber network is currently used only in the cities. Also necessary to consider the fact that even if the original top speed is 57.6 kbit/s the modem automatically reduces bandwidth and switches to protocol V.34.

Best advice - think that visitor has poor connection speed, standard 33.6 kbit/sec which is about 4.2 kb/s. Thus, to download a 10K webpage takes a couple of seconds, but the rate can slightly increase due to compression of data provided by the protocol. But count on a lot of it is not necessary, since the site simultaneously with page loaded and the necessary office dannye.Uchityvayte and the fact that some versions of modems trying individually select the optimum speed for each resource, which causes additional delay at startup. Data transmission on a dedicated line. Main user error - the belief in an ideal dedicated line and no problems with download speeds. Alas, here there are the cornerstones kamni.Vo first, leased line suffers from low bandwidth network connecting channel, which is connected to the server and computer klienta.Takaya problem may occur if one of the networks use the backup link, which is traditionally has less bandwidth unlike the main channel. Here it is failure-no one is safe - backup channel constantly stormy due to errors in the software.

Check the validity of this theory, you can use a special utility traceroute for * nix-systems or tracert for Windows. The program will check the entire route of the signal, detects the packet delay time for each site networks and provide an analysis of all hosting services through which the connection. The utility works extremely imperfect and depends on the scheme to build the network. Data transmission on ADSL has a problem with slow loading pages on the site and in the case of work by a dedicated line with the technology ADSL (asymmetric digital subscriber line). The technique involves the reduction of the data rate per subscriber and an increase in incoming packets. This practice no one criticism is not as focused just on the customer satisfaction to download large amounts of data from seti.V this case most of the traffic takes information directly leaving the user's computer, and created only a small overhead transmission from the subscriber to resource. Then when you stop the packet from the subscriber to the source during the page load resource automatically blocks and reverse load data. This variant is possible if an overload of the main channel data to the server. Dynamic pages, scripts.

Having dealt with the problems on the line, move on to reasons arising in the servera.Chasto slow loading of the website called slow processes to implement the browser responsible for the formation of dynamic web content. This is due to restrictions on the use of resources, which is written in the hosting plan. In fact, it means that the client host does not have the right to use all available resources of the physical server on which rests his site. This technique is not rare among providers and is banal struggle with the risks to server overload due to improperly prescribed browser klientov.V individual customer's disposal has only a separate part of the machine resources: limited memory, clearly Logged amount of CPU time and on t.d.Vliyayut low speed of the browser inefficient programming techniques and large volumes of processed dannyh.Osnovnoy error when the script becomes ill-written function to read large files entirely, or record all data in a single variable and the subsequent search for specific strok.Povliyaet to load and retrieve data from an external source of slow and the sheer volume of script code. The last reason is quite likely if the script weighs more than 50-100 KB and contains calls to other files, which cause additional podgruzku skriptov.Vazhno check and optimization of used scripts. Any language in which the script was written, whether PHP or Perl, will run slow and unproductive, if not pass it through a special PHP-optimizer (Turck MMCache or Zend Optimizer). The program will accelerate the performance of the script through its compilation into bytecode caching and get the results compiled for use options for subsequent calls.

 

Analyze in detail the optimization script with PHP-optimizer Turck MMCache. Program can not be called the best in their field, given the fact that the latest version 2.4.6 it came out in 2003. Source code optimizer was used to manufacture a new product eAccelerator, which took into account all the shortcomings and mistakes of the "big brother".

You can choose a different optimizer, which is already installed on your hosting. To do this, go directly to the technical support hosting provider or check the results of the function phpinfo ().

To do this, create a web space php-file with the line:

<? Php mmcache ()?>
By calling a script, you will get a table with information on the work of PHP-optimizer.

At first you will find:

- The current settings of the program;

- The total amount allocated for the memory optimizer is specified in the Memory Size;

- The amount of memory currently allocated for caching scripts and is specified in the Memory Allocated;

- Final amount of crypts, cached optimizer - parameter Cached Scripts.

The second table records the complete list of all executed scripts with their detailed description, including the size of each script (Size), the number of successful downloads from memory optimizer (Hits). Unsuccessful attempt to cache in this case will be described line: Hits = 0.

To determine the final amount of downloadable files that are required to run the same script, clear the memory from the previous query optimizer. This is easily done by pressing Clear. On a successful operation carried out in the list will only browser that you created. Then invokes the script via the browser and refresh the page shutdown optimizer. On a result you will get a complete list of files that call out when running this script. Will only summarize the volumes of files specified in the Size.

Using PHP-optimizers.

Useful program optimizers owners forums (such as yBulletin or phpBB) and content management systems CMS (Mambo, Bitrix or PHP-Nuke). However. Optimizer will not hurt others and surround resources written in PHP. But do not forget to test for compatibility code in each separately, as you have written scripts may work differently depending on whether or not the program optimizer.

 

Database.

Slow loading can be associated with suboptimal use of databases.

Consider an example. The client makes a request for a dynamic page of your site, which is constructed by generating a script several SQL-queries. Risks may be two: a job SQL-server that is prone to instability and script transfer large amount of data processed by the query.

Traditionally, virtual hosting uses MySQL as the database. A main reason for the slow query execution becomes no relevant indexes on tables in MySQL. Select the type of queries in the fields of the table without indexes in databases that use a large amount of information needs to be a decent runtime, which ultimately affects the pace of loading the correct page.

Check if problems with the database, you can run the command SHOW FULL PROCESSLIST. Then MySQL will generate a table of all the currently executing queries. Time field specifies the time it takes to execute each query. If the value exceeds the second, it is necessary to check the total number of rows are viewed data request. This can be done through the command EXPLAIN, which would give the results table. Rows column in the list will show the number of rows viewed. If the value is more than 1000 need to build new indexes for fields that fall under the sample. This will reduce the number of rows that are viewed when the query several times that immediately impact positively on the loading time of the site.

 To consolidate take the following example:

mysql> SELECT title FROM products WHERE id = 123212;
+ ----------- +
| Title |
+ ----------- +
| Product N |
+ ----------- +
1 row in set (0.60 sec)
 
mysql> EXPLAIN SELECT title FROM products WHERE id = 123212;
+ ---------- + ------ + --------------- + ------ + -------- - + ------ + -------- + ------------- +
| Table | type | possible_keys | key | key_len | ref | rows | Extra |
+ ---------- + ------ + --------------- + ------ + -------- - + ------ + -------- + ------------- +
| Products | ALL | NULL | NULL | NULL | NULL | 175246 | Using where |
+ ---------- + ------ + --------------- + ------ + -------- - + ------ + -------- + ------------- +
1 row in set (0.00 sec)
 

Thus, we query using the products table with the condition of the field id, which is not built under the Code. The query takes 0.6 seconds with watching 175246 rows in the table. Constructing an index for a field id, compare the results:

mysql> CREATE INDEX id_index ON products (id);
Query OK, 175246 rows affected (2.05 sec)
Records: 175246 Duplicates: 0 Warnings: 0
 
mysql> SELECT title FROM products WHERE id = 123212;
+ ----------- +
| Title |
+ ----------- +
| Product N |
+ ----------- +
1 row in set (0.00 sec)
 
mysql> EXPLAIN SELECT title FROM products WHERE id = 123212;
+ ---------- + ------ + --------------- + ---------- + ---- ----- + ------- + ------ + ------------- +
| Table | type | possible_keys | key | key_len | ref | rows | Extra |
+ ---------- + ------ + --------------- + ---------- + ---- ----- + ------- + ------ + ------------- +
| Products | ref | id_index | id_index | 5 | const | 1 | Using where |
+ ---------- + ------ + --------------- + ---------- + ---- ----- + ------- + ------ + ------------- +
1 row in set (0.00 sec)
On a result, the construction of a separate index for the id field has reduced the view to one row and cause immediate query execution.

 

Transferring large files over HTTP

And the last reason often occurs slow loading of websites - volumes of information downloaded from the sites themselves and often request to download. If your resource is a large library of files decent volume (up to several megabytes each), causing permanent interest of customers, processing requests will take longer intervals. While performing several requests site can not handle the load and go into a state of slow performance, or do not stop to open. Its role in these accelerations can play the clients themselves, used for the fastest file download special programs - download managers, download large files using three or four streams that multiplies the number of requests to the server and instantly comes to the limit.

If providing files for download is a necessity for the functioning of the resource should refer to other transports data transmission. For example, the presence of such services hosting provider, go to the FTP to work with files. Then you will be able to unload the web server, shifting the entire burden of processing requests for FTP-server.

In conclusion, we note that consider all causes of slow loading of the site, one article will not succeed. We have tried to describe in detail the main factors, as well as offer solutions to the problem, which we hope will help you in the future.