Millions PHP Web site Architecture Toolbox

Source: Internet
Author: User
Tags fpm memcached memory usage php server php script versions rabbitmq couchdb

After learning about the world's largest PHP site, Facebook's back-end technology, today we'll look at a millions PHP site's web architecture: poppen.de. Poppen.de, a social networking site in Germany, is a small web site relative to Facebook and Flickr, but it has a good architecture that incorporates a number of technologies, such as Nigix, MYSQL, CouchDB, Erlang, Memcached, RABBITMQ, PHP, Graphite, Red5, and Tsung.

Poppen.de currently has 2 million registered users, 20,000 concurrent users, 200,000 private messages per day, and 250,000 logon times per day. The project team has 11 developers, two designs, and two system administrators. The site's business model is free value-added mode, users can use search users, send messages to friends, upload pictures and videos and other functions.

If users want to enjoy unrestricted messages and upload pictures, they will have to pay for different types of membership services as needed, as well as video chats and other services on the web.

Nginx

Poppen.de all services are based on Nginx services. The front end has two nginx servers that provide 150,000 requests per minute at peak time, each with a four-year lifetime and only one CPU and 3GB RAM. Poppen.de has three independent image servers, which provide 80,000 requests per minute for *.bilder.poppen.de by the Nginx servers.

A cool design in the Nginx architecture is that many requests are processed by memcached, so requests to get content from the cache do not require direct access to the PHP machine. For example, user profile is the content that the website needs to deal with intensively, if the user Information page is all cached to the memcached, then the request obtains the content directly from the memcached. The poppen.de memcached can handle requests 8,000 times per minute.

There are three Nginx image servers in the architecture that provide local image caching, and users upload images to a central server. When an image is requested in one of these three nginx, if the image is not present on the server locally, it is downloaded from the central server to the server for caching and servicing. This load-balanced distributed Image server architecture design can reduce the load on primary storage devices.

php-fpm

The site runs on the PHP-FPM. There are 28 PHP machines with two CPUs and 6GB of memory running 100 PHP-FPM worker threads on each machine. Use an APC-enabled php5.3.x. PHP5.3 can reduce CPU and memory usage by more than 30%.

The program code is developed on top of the Symfony1.2 framework. One is the ability to use external resources, the second is to improve the progress of the project development, while in a well-known framework can make it easier for new developers to join the team. Although nothing is perfect, you can get a lot of benefits from the Symfony framework so that the team can focus more on Poppen.de's business development.

Web site performance optimization using Xhprof, this is a class library that Facebook opens up for open source. This framework is very easy to personalize and configure, and can cache most of the high cost of server computing.

Mysql

MySQL is the site's main RDBMS. Web site and several MySQL server: a 4CPU, 32GB server storage of user-related information, such as basic information, photo description information. The machine has been in use for 4 years, and the next plan is to replace it with a shared cluster. The design is still based on this system to simplify the data access code. Data partitions are based on the user ID, because most of the information in the site is user-centric, such as photos, videos, messages, and so on.

There are three servers that provide user forum services by main-from-configuration architecture. One from the server responsible for the Web site custom message store, to now have 250 million messages. The other four machines are primarily-from configuration relationships. In addition, 4 machines are configured to NDB communities dedicated to intensive write operation data, such as user access statistics.

Datasheet design avoids associated operations as much as possible and caches the most data. Of course, the structural specification of the database has been completely destroyed. Therefore, to make it easier to search, the database design creates a data mining table. Most tables are MyISAM and can provide quick lookup. The problem now is that more and more tables have been locked up all over the table. Poppen.de is considering migrating to the XTRADB storage engine.

Memcached

There are quite a few memcached applications in the Web site architecture, exceeding 45GB cache and 51 nodes. Session sessions, view caching, and function execution caching are cached. There is a system in the architecture that automatically updates the data to the cache when the record is modified. A possible solution for future improvements to cache updates is to use the new Redis Hash API or MongoDB.

Rabbitmq

Start using RABBITMQ in the architecture for 2009 years. This is a good messaging solution that is easy to deploy and centralize into the architecture, running two RABBITMQ servers after the LVS. In the last month, more stuff has been integrated into the queue, meaning that 28 PHP servers are processing 500,000 requests a day at the same time. Send a log, mail notification, system message, image upload, and more things into this queue.

The Fastcgi_finish_request () function in PHP-FPM is used to integrate the queue message, which sends the message asynchronously to the queue. This function is called when the system needs to send the user an HTML or JSON format response, so that the user does not have to wait for the PHP script to clean up.

This system can improve the management of architecture resources. For example, the service can process 1000 logon requests per minute at peak times. This means that there are 1000 concurrent update user tables that hold the user's logon time. Because of the queuing mechanism, you can run these queries in the reverse order. If you need to improve processing speed, you need to add more queue handlers, and you can even add more servers to the cluster without modifying any configuration and deploying new nodes.

Couchdb

The log storage couchdb runs on a single machine. On this machine, you can log queries/groupings according to the module/behavior, or depending on the type of error, and so on. This is useful for locating problems. Before using the Log aggregation service couchdb, it is very troublesome to log on to the PHP server and try logging to analyze the location problem. Now, all the logs are set up in the queue and saved in the COUCHDB, which can be centralized for problem checking and analysis.

Graphite

The website uses the graphite to collect the website real-time information and the statistics. From requesting each module/behavior to Memcached's hits and misses, RABBITMQ State monitoring, and UNIX load and so on. The graphite service has an average of 4,800 update operations per minute. Practice has confirmed that it is useful to monitor what happens to Web sites, and that its simple text protocols and drawing features can be easily plug and play in any system that needs to be monitored.

A cool thing to do is to use graphite to monitor two versions of the site at the same time. A new version of the Symfony framework was deployed in January, and the previous code was deployed as a backup. This means that the site may be experiencing performance problems. So you can use graphite to compare two versions online.

found that the UNIX load table on the new version is high, so use xhprof to analyze the two versions to find out the problem.

Red5

The website also provides two types of video service for users, one is the video that the user uploads, the other is video chatting, user video interacting and sharing. By 2009, the monthly 17TB traffic service is provided to the users.

Tsung

Tsung is a distributed baseline analysis tool written in Erlang. The Poppen.de Web site is mainly used for HTTP benchmarking, MySQL and other storage systems (XTRADB) comparison analysis. A system is used to record the traffic of the main MySQL server and then convert it into a Tsung base session. The traffic is then replayed and generated by Tsung thousands of concurrent users accessing the lab's servers. This can be very close to the real scene in the experimental environment.

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.