Tuning Linode VPS: Small-scale low-performance low-flow Web site optimization Practice

Source: Internet
Author: User
Keywords VPS small gauge low die

Intermediary transaction SEO diagnosis Taobao guest Cloud host technology Hall

I happened to see this post, "small-scale low performance low-flow Web site design principles", back to Weibo caused a little response, feel the need to Linode VPS as an example to do a simple optimization practice, so that someone always ask me, also by the way to earn points clicks:)

Assuming now you've got a basic VPS available, basic memory 512MB. Refer to the various installation instructions provided by the official operation of LAMP this combination, operating system general Ubuntu, Web server Apache, Database MySQL, then PHP, and need to install the application software, WordPress, Drupal or OpenCart What, step-by-step configuration, to normal browsing the page. One of the benefits of following official document operations is to include some basic optimization configuration. There is no big mistake.

Once the application is in place, log in to the operating system and collect baseline data through basic operating system commands such as Top/iostat/free. The more comprehensive the collection of information, the more convenient for the subsequent optimization. Optimization has no magic, only reasonable method.

1. Memory-related adjustments

Internal testing, or a smaller range of uses, may not be too much of a problem. Once the number of visitors is a bit more, the machine response may be a bit slow. For VPS, the first step is to adjust the use of each component of memory. Because memory is limited, the use of memory must be carefully calculated. Remember that once memory runs out, some memory calls are pressed onto the disk, and the system load soars and generally hangs.

In general, for the LAMP environment, the following areas should be noted:

Memory-related adjustments for PHP programs

The default value defined by Memory_limit in the PHP5 profile php.ini is 16MB, which defines the maximum memory size that a single PHP script consumes. If a program requires more memory than this limit, visitors are most likely to encounter an HTTP 500 error, and viewing the WEB server error log can also be seen. In most cases, this value needs to be adjusted accordingly. For example, set to 32MB, whether appropriate, need to do observation. An empirical approach is to look at the output of the top command and see the value of the SHR field of the process, which is actually always as large as possible. But can not be too large, once the individual programs write a bad call to occupy too much resources, will lead to the VPS hang up.

It is often asked, how many concurrent is the server running such a WEB application? A general idea is to estimate the memory consumed by a single process, how much memory the system can allocate to the application, and the amount of concurrency can be roughly estimated. But actually, the question is of little value.

In addition, there is a more important parameter to modify output_buffering need to be modified to on or specific values (eg, 4096). After modifying the configuration, check to see if it takes effect (how to check?). Also, remember the location of the error_log and view it at any time.

MySQL Database Memory Footprint

If you are unsure about MySQL memory usage, you can use the Mysqlreport tool to collect information reports on MySQL instances, and collect several more times in different time periods as a comparison. Then adjust the size of key_buffer/query_cache_size and other parameters, adjust one parameter at a time, restart MySQL, continue to extract the report, analyze the data, and then adjust the next parameter. Now that you need to edit the configuration file my.cnf, it is recommended that you add a little max_connections this parameter (why?).

Most memory problems are caused by database I/O, causing more I/O problems by unreasonable database calls (so rigorous?), resolving unreasonable calls or modifying applications, either through query caching or Key-value cache. This place is a long story, assuming that the VPS basically will not have such a complex environment.

2. Adjustments that affect CPU utilization

This is mainly for PHP Opcode (accelerator), parsing, compiling PHP code is quite CPU-consuming operation. Common is either APC, or Eaccelerator or XCache, in Ubuntu installation configuration is relatively simple, parameter adjustment simple search to know. If it is a PHP environment, then be sure to use Opcode to reduce the CPU load (why?). As to which relationship is not very small, but only if there must be one.

In addition, Zhang Lei this article lets the process run in the specified CPU for the specific needs of the application, it is very useful.

3. Network parameter control

Modify the/etc/sysctl.conf file to add the following lines:

Net.ipv4.tcp_syncookies = 1net.ipv4.tcp_tw_reuse = 1net.ipv4.tcp_tw_recycle = 1

Then sudo sysctl-p the changes to take effect. Observe the number of semi-connections using the following line command:

$ netstat-n | awk '/^tcp/{++s[$NF]} end {for (a in S) print A, s[a]} '

In general, the number of network connections is not the most obvious bottleneck. But adjust it well, "no charge". Some people ask, if encounter DDoS how to do?

4. Application-Related adjustments

More popular open source programs, without the installation of Third-party Plug-ins, the performance of how much passable. Recommend that if not necessary, do not enable too many third-party plug-ins, especially some with statistics or "smart" display content such as plug-ins can not be used.

These open source programs are also basically oriented to the front-end optimization of static solutions, such as WordPress Cache-related plug-ins, strongly recommended to enable. Have time to look at the front-end optimization practice recommendations. #p # subtitle #e#

  

Optimization is the most important to find the bottleneck, the right remedy. Already mentioned the memory, CPU, network, roughly raised a point I/O problem, basically enough. PHP log, MySQL slow query log, Apache Error log, often filtered to see if there is any new situation.

To add, don't forget to modify the OS Ulimit limit:

Edit/etc/security/limits.conf Add the following two lines (the specific value of the larger point small problem is not):

* Soft Nofile 40960

* Hard Nofile 40960

Edit/etc/pam.d/common-session and add the following line:

Session Required Pam_limits.so

Edit/etc/profile and add the following line:

Ulimit-shn 40960

Reboot the OS to take effect.

Linode background provides a few basic statistical charts, basic enough. can set the disk I/O is too high when the alarm, the system will email you. Take a look at the use of network traffic. Do not consume bandwidth because individual files are hotlinking.

The above mentioned many changes suggest not conditionings, know it, but also know why. Each step of the adjustment of multiple reading system manual, especially in relation to the specific parameter values, must be modified to the actual situation. After you have mastered the basic configuration, you can try performance-efficient components based on your situation, such as replacing Apache with NGINX/LIGHTTPD, but remember that if Apache is not a bottleneck, replacing the legendary Web server with better performance will be a toss.

Again, don't be overly optimized, enough to satisfy your needs. More energy can be put on other links altogether. In addition, if the basic adjustment has done, want to use the most convenient way to improve performance, then, directly to the service provider to buy additional memory.

Well, the last thing I want to say is that this optimization idea is not limited to VPS, this minimal practice for the complex server environment is also the basic application.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.