Web Performace with Adflex.vn
Đoàn Văn TuyểnCTO Eway JSC
Họ Tên: Đoàn Văn Tuyển Chức vụ: Giám đốc kỹ thuật Eway JSC Sản phẩm: Adflex.vn và Sangame.net
Giới thiệu
Adflex.vn
Sản phẩm quảng cáo trên di động: in-app& web
1 năm tuổi với khoảng 12 triệu người dùng (80% ở Việt Nam)
DAU ~ 800k-1M, ~ 25-30 triệu request/ ngày
Tốc độ xử lý: 4ms-40ms / request
Nội dung trình bày
Thiết kế hệ thống Web Server & CDN PHP Database (MongoDB) Cache server (Redis) Job server (RabbitMQ) Monitoring Debug & Profiling
Thiết kế hệ thống
Web Server & CDN
Proxy (Nginx): Nhận request và phân chia vào nhiều server để xử lý
Server (Apache & PHP): Xử lý business chính CDN: trả về các nội dung tĩnh như image,
CSS & JS Config for Performace:
− Gzip / Cache time− Log reponse time / server time
PHP & Opcode cache
PHP Configuration
Cấu hình opcode cache: APC Giới hạn memory: 32MB-64MB Giới hạn execute time: 2-10s
Database Server
Database Server
Sử dụng ổ SSD Chia làm 2 DB
− 1 DB xử lý realtime. Yêu cầu update nhiều, số lượng request lớn
− 1 DB xử lý report: yêu cầu query phức tạp. Monitoring
− Mongotop− Mongo slow query log− Http console log
Cache Server
Sử dụng Redis làm cache server− Lưu dữ liệu thường xuyên truy cập− Lưu dữ liệu yêu cầu tạm thời (một vài ngày)
Cache file PHP + APC
Job Server: Rabbit MQ
Job Server: Rabbit MQ
Xử lý tất cả những tác vụ tốn thời gian qua job server: Gửi mail, log dữ liệu, tính toán...
Sử dụng RabbitMQ làm Job Server Sử dụng PHP làm worker (Chạy lệnh PHP) Worker sử lý theo Batch
Monitoring - Newrelic
RAM CPU Network Disk
Used /IO
Monitoring - Newrelic
Response time
Appdex Score
Throughput
Error & Alert
Debug & Profiling
Debug & Profiling
Profiling: xhprof Debug: Apache log4php Manual:
− microtime− register_shutdown_function− debug_print_backtrace− ...
Q&A
Tham khảohttp://www.slideshare.net/tuyenbk83/php-web-server-performace
http://java.dzone.com/articles/php-performance-crash-course
http://on.fb.me/1hAc7vL
https://developers.google.com/speed/docs/best-practices/rules_intro
http://developer.yahoo.com/performance/rules.html
http://www.slideshare.net/lonelywolf/web-optimization
http://code.google.com/p/modpagespeed/
https://github.com/pagespeed/ngx_pagespeed
://developer.yahoo.com/yslow/
https://developers.google.com/speed/pagespeed/insights_extensions
https://addons.mozilla.org/en-US/firefox/addon/firebug
http://php.net/manual/en/book.apc.php
http://php.net/manual/en/book.xhprof.php
http://www.mdproductions.ca/guides/50-best-practices-to-optimize-php-code-performance
http://www.chazzuka.com/63-best-practice-to-optimize-php-code-performances-58/
http://fuscata.com/kb/set-maxclients-apache-prefork