Web Service Optimization

Source: Internet
Author: User

Recently, some simple Web Request optimizations have been made. The web-side logic is very simple, that is, to receive user post data, save it to the database, and process users' get query requests.

Web server: Ubuntu + Lighttpd + FastCGI + Django, the database uses MySQL 5.0

Almost allCodeIt is as simple as possible, and parameter verification is almost not done. Connection Pool, memcached Lite version, Django Lite version, etc. The advantage of python is that you can modify anySource code.

Everything seems to be ready, but I am surprised by the final stress test results. The post click rate is faster than get (1200: 800), which is unlikely. Although I cannot find the reason for adjusting the Lighttpd parameter and checking whether memcached is effective, how can the query be slower than inserting data?

 

After reading the code over and over again, the test results are still the same.

 

I accidentally looked at the template language of Django. Is it a very slow template of Django?

Our response results can be in two formats: JSON and XML. JSON is directly generated using simplejson, while XML is generated using Django templates.

So I compared the test results of JSON and XML. The original problem is that the CTR of XML is nearly 400 higher than that of JSON.

 

Finally, I found a breakthrough and abandoned the Django template. I used the most primitive method directly,Assemble strings.

Wow .... After testing with AB, the test result is still normal and the click-through rate reaches 1500.

 

Later, let's just think about it. Django's template will be slow, because every time the XML format reponse performs an IO operation to read the local template file, and then it will execute complicated template language parsing, the speed will inevitably be much slower.

 

Do not underestimate some of the operations or logic code that we usually seem to be less time-consuming, usually these inconspicuous operations, resulting in a significant reduction in the overall performance of our applications.

 

There are still several items for web optimization: avoid complicated logic, connection pool, cache, and Io operations as much as possible. Even String concatenation should be carefully considered.

 

I hope this article will be useful to you. Pai_^

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.