• Downloading from our site will require you to have a paid membership. Upgrade to a Premium Membership from 10$ a month today!

    Dont forget read our Rules! Also anyone caught Sharing this content will be banned. By using this site you are agreeing to our rules so read them. Saying I did not know is simply not an excuse! You have been warned.

Hướng dẫn Tối ưu hóa apache và mysql để hỗ trợ nhiều kết nối

congtust24

Well-Known Member
Vip
Apache Memory Use Optimization


1. SSH into your server as root.
2. Run top.
3. Press shift + m.
4. Note the highest RES memory used by httpd.
5. Hit Q to exit top.
6. Execute: service httpd stop
7. Once httpd is stopped, execute: free -m
8. Note the memory listed under "used".
9. Find the guaranteed memory for your VPS plan. Support can tell you how much you have guaranteed if you cannot find it.
10. Subtract the memory USED from the memory that your plan is GUARANTEED. This will give you your base FREE MEMORY POOL.
11. Multiply the value of your FREE MEMORY POOL by 0.8 to find your average AVAILABLE APACHE POOL (this will allow you a 20% memory reserve for burst periods).
12. Divide your AVAILABLE APACHE POOL by the highest RES memory used by httpd. This will give you the MaxClients value that should be set for your system.
13. Open httpd.conf in your favorite text editor (don't use Windows text editors as they may break httpd.conf).
14. Set the MaxClients value you've calculated.
15. Set Keepalive Off if you don't need it (your server will handle more requests per second with keepalive on, but will require more memory for apache--don't turn on keepalive if you're not leaving a 20% memory reserve).
16. If you are leaving keepalive on, set keepalivetimeout to the lowest value you can to prevent connections from hanging. If you experience high latency to your server, set keepalivetimeout to 2-5 seconds.
17. Set your Timeout to a reasonable value. Pick a time that won't cut off the transfer of your pages to your customers, but keep it low enough that you don't have dead connections that remain open for a large period of time (10-30 seconds should be a good timeout if most of your users are on highspeed, and 30-120 should be ok for dialup).
18. MaxKeepAliveRequests should be set equal to the largest number of objects you have in 1 page. If you don't know, 70-200 should be good.
19. Set your MinSpareServers equal to 10-25% of MaxClients.
20. Set your MaxSpareServers equal to 25-50% of MaxClients.
21. Set your StartServers equal to either MinSpareServers or MaxSpareServers. When apache is restarted, this is the number of servers that will start and be ready for connections immediately. High-traffic sites should set this value to MaxSpareServers and lower volume sites should use MinSpareServrs.
22. MaxRequestsPerChild should be set somewhere between 500 (if you see rapid apache child process memory use growth) to 10000 (if you have no leaks in your applications). Setting this value to 0 will result in child processes never being killed, and eventually all shared memory used by apache will become "dirty" and unshared, possibly resulting in higher overall memory use.
23. Once you've set all values, save the file, exit, and issue: service httpd restart.

The following is an EXAMPLE with output:

Under TOP I notice that my biggest apache process is using 5mb of memory:
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
15535 root 16 0 15072 5376 3196 S 0 0.5 0:17.60 httpd


-bash-3.00# service httpd stop
/etc/init.d/httpd stop: httpd stopped
-bash-3.00# free -m
total used free shared buffers cached
Mem: 1024 131 892 0 0 0
-/+ buffers/cache: 131 892
Swap: 0 0 0
-bash-3.00#

I see I'm using 131MB of RAM without apache. I have 384MB of RAM available.

384 - 131 = 253MB Free Memory Pool
253 * 0.8 = 202.4MB Available Apache Pool
200 / 5 = 40

Armed with this information I now set up my httpd.conf with the following settings:

Timeout 10 (If it takes more than 10 seconds to load my pages, something is wrong)

MaxClients 40 (Note: I can set this lower if I know other processes will need more memory under load)
MinSpareServers 4 (My site gets almost no traffic)

MaxSpareServers 20 (My server never uses memory, so extra apache children hanging around doesn't hurt me)

StartServers 4 (again, low traffic, so I don't need to be handling an instantaneous burst on apache restart)

Keepalive On (Since I don't use much memory, I don't need to turn this off as the extra use won't hurt me)

MaxKeepAliveRequests 100 (I don't have 100 objects on any page, but using too low a value doesn't help performance, so I'll just do 100)

KeepAliveTimeout 1 (I don't have large files/pages, so I don't expect the remote computer to take more than 1 second to reply to each keepalive request)

MaxRequestsPerChild 10000 (I like the better performance with this, and I run no PHP Apps that leak memory)

Once I've set these, I save the file, exit the editor, and restart apache. I've now reconfigured apache to meet my specific needs!

Cấu hình sơ bộ:

httpd.conf

TimeOut 300
KeepAlive on
MaxKeepAliveRequests 500
KeepAliveTimeout 10
<IfModule prefork.c>
StartServers 25
MinSpareServers 25
MaxSpareServers 100
ServerLimit 384
MaxClients 256
MaxRequestsPerChild 10000
</IfModule>

my.cnf

[mysqld]
set-variable = net_buffer_length=8M
set-variable = max_allowed_packet=2M
set-variable = myisam_sort_buffer_size=72M
set-variable = sort_buffer=8M
set-variable = key_buffer=72M
set-variable = table_cache=3333
set-variable = query_cache_size=256M
set-variable = thread_cache_size=8
set-variable = innodb_buffer_pool_size=28M
set-variable = join_buffer_size=12M
set-variable = tmp_table_size=32M
set-variable = max_heap_table_size=28M
set-variable = max_connections=200
set-variable = wait_timeout=10
set-variable = max_connect_errors=100
 

Facebook Comments

Similar threads
Thread starter Title Forum Replies Date
P Phần mềm PC Windows 10 Manager v2.0.4 Multilingual Portable – Tối ưu hóa Windows 10 Phần mềm 0
Admin Mời tải về bản beta của trình duyệt Firefox được tối ưu hóa cho cảm ứng trên Windows 8 Phần mềm 0
Admin Hướng dẫn tối ưu hóa robots.txt cho blogger Thảo luận SEO 2
Admin Sandisk ra mắt chip nhớ nhúng iNand Extreme eMMC được tối ưu hóa cho SoC Intel Atom Bay Trail Tin tức CNTT 0
Admin Hướng dẫn tối ưu hóa xenforo phần 2 - Phân mảnh trong MySQL và cách sửa chữa Xenforo 0
Admin Hướng dẫn tối ưu hóa xenforo phần 1 với database - MySQL Optimization Xenforo 0
Admin Hướng dẫn tối ưu hóa thẻ alt cho vbb mọi phiên bản Vbb tutorial 0
Admin Share template blogger vnshare v3 tối ưu hóa seo tốt nhất 2013 Blogger 0
Admin FREE Windows Tuner 2.0.0.3-Công cụ tăng tốc và tối ưu hóa hệ thống miễn phí Phần mềm 0
Admin Share code wapka tối ưu hóa seo Wap builder, wapego, xtgem, wen.ru, wapka, wap4 0
V Phần mềm PC Download + key Bản quyền miễn phí phần mềm Advanced System Care -Tối ưu hóa hệ thống máy tính của bạ Phần mềm 0
H Cách tránh bị Google Penalty vì tối ưu hóa SEO quá mức Thảo luận SEO 0
Admin Tối ưu hóa các thẻ H – heading (h1, h2, h3,h4,…) chuẩn cho seo Thảo luận SEO 1
yeuthenao Hướng dẫn [SEO] Tối ưu hóa tiêu đề cho một bài viết. All Shared Scripts 0
Admin Cài đặt mod_pagespeed của google Tối ưu hóa VPS VPS & Dedicated Server 0
T Cho hỏi cách tối ưu hóa album ảnh vbb xuống dung lượng thấp nhất Vbulletin 2
congtust24 Tối ưu hóa ảnh web bằng Image Optimizer Máy tính 0
Admin Tối ưu hóa hệ thống, hạn chế tình trạng giật lag khi chơi game Thủ thuật máy tính 1
Admin Tối ưu hóa SEO cho CSS của wap/web Thảo luận SEO 2
Admin Tối ưu hóa wap/web Thảo luận SEO 1
Admin vB Optimise Pro v2.3.0 PHP-NULL Draxofavalon - tối ưu hóa forum VBB Add-ons 4
Admin Tối ưu hóa site của bạn Thảo luận wap việt 0
Admin Tối ưu hóa (Optimise) apache VPS & Dedicated Server 0
Admin Hướng dẫn tối ưu hóa tool auto upload xtgem Wap builder, wapego, xtgem, wen.ru, wapka, wap4 0
Admin 10 thủ thuật SEO tối ưu hóa tiêu đề thân thiện với Google Thảo luận SEO 0
Admin vB Optimise Pro v2.3.0 PHP-NULL Draxofavalon - tối ưu hóa forum VBB Vbulletin 0
J E cần tối ưu code check cc,web check ạ PHP 0
Npnken Hướng dẫn 10 bước tối ưu hoá SEO cho Blogger Blogger 0
B Những lưu ý khi vùng kín bị giản rộng và cách giải quyết tối ưu nhất Thảo luận chung 0
T Phương Pháp Tối Ưu Hình Ảnh Trong Thiết Kế Website Mã nguồn web 0
T 4 Thủ Thuật Tối Ưu Khi Thiết Kế Giao Diện Web Mobile Tin tức CNTT 3
NhokLove Share Thủ Thuật SEO : Tối Ưu Tiêu Đề Cho Blogger Thảo luận SEO 2
Tuzoro Share Theme Wordpress TaiGameHot.Mobi Tối ưu Seo pro Wordpress 3
G Share [AVATAR ONLINE]Mã Auto Kim Cương Xanh Tối Ưu, Fix Lỗi Trong Avatar Trò chơi 0
Admin Share template pizza tối ưu seo cho blogger Blogger 0
Admin Advanced SystemCare Ultimate 7 Full Key - Chăm sóc và tối ưu máy tính hàng đầu Phần mềm 0
Admin Share template blogspot truyện cực hot, tối ưu seo, load nhanh Blogger 5
Admin iOS 7 beta 4 đã có, tối ưu hệ thống, nhanh và mượt hơn Tin tức, giới thiệu về ĐTDĐ 0
Admin Advanced systemcare 6.2.0.254 - phần mềm chăm sóc và tối ưu hàng đầu Phần mềm 0
S 8Smoker Pro mang hàng tấn công cụ tối ưu hiệu năng cho Windows 8 Tin tức CNTT 0
Hero Phần mềm PC Advanced SystemCare 6.2.0.254 - Phần Mềm Chăm Sóc Và Tối Ưu Hàng Đầu Phần mềm 0
Admin Download CCleaner 4.02 full - phần mềm dọn rác, tối ưu máy tính dễ dàng Phần mềm 0
Admin Download CCleaner 4.01 full - phần mềm dọn rác, tối ưu máy tính dễ dàng Phần mềm 0
Admin Download Glary Utilities Pro full key - miễn phí bản quyền phần mềm tối ưu máy tính hàng đầu Phần mềm 2
Admin Hướng dẫn tạo robots.txt cho nukeviet tối ưu hoá công cụ tìm kiếm Mã nguồn web 0
Admin Hướng dẫn tạo robots.txt cho xenforo tối ưu hoá công cụ tìm kiếm Vbb tutorial 0
Myshare Hướng dẫn Tối ưu Tốc độ Cho Server Và Tăng Tốc Diễn đàn Vbb tutorial 0
Admin Hướng dẫn tối ưu css để load trang tốt hơn HTML & CSS 1
djdungcuty Tối ưu tốc độ wordpress vớifile config.php Wordpress 0
S Auslogics BoostSpeed 5.5.0.0 - Bộ công cụ tối ưu, tăng tốc máy tính mạnh mẽ Phần mềm 0

Similar threads

New posts New threads New resources

Back
Top