Advanced PHP Programming- P6
Số trang: 50
Loại file: pdf
Dung lượng: 510.94 KB
Lượt xem: 19
Lượt tải: 0
Xem trước 5 trang đầu tiên của tài liệu này:
Thông tin tài liệu:
Tham khảo tài liệu advanced php programming- p6, công nghệ thông tin, kỹ thuật lập trình phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả
Nội dung trích xuất từ tài liệu:
Advanced PHP Programming- P6228 Chapter 9 External Performance Tunings Pre-Fork, Event-Based, and Threaded Process Architectures The three main architectures used for Web servers are pre-fork, event-based, and threaded models. In a pre-fork model, a pool of processes is maintained to handle new requests. When a new request comes in, it is dispatched to one of the child processes for handling. A child process usually serves more than one request before exiting. Apache 1.3 follows this model. In an event-based model, a single process serves requests in a single thread, utilizing nonblocking or asyn- chronous I/O to handle multiple requests very quickly. This architecture works very well for handling static files but not terribly well for handling dynamic requests (because you still need a separate process or thread to the dynamic part of each request). thttpd, a small, fast Web server written by Jef Poskanzer, utilizes this model. In a threaded model, a single process uses a pool of threads to service requests. This is very similar to a pre- fork model, except that because it is threaded, some resources can be shared between threads. The Zeus Web server utilizes this model. Even though PHP itself is thread-safe, it is difficult to impossible to guaran- tee that third-party libraries used in extension code are also thread-safe. This means that even in a threaded Web server, it is often necessary to not use a threaded PHP, but to use a forked process execution via the fastcgi or cgi implementations. Apache 2 uses a drop-in process architecture that allows it to be configured as a pre-fork, threaded, or hybrid architecture, depending on your needs. In contrast to the amount of configuration inside Apache, the PHP setup is very similar to the way it was before.The only change to its configuration is to add the following to its httpd.conf file: Listen localhost:80 This binds the PHP instance exclusively to the loopback address. Now if you want to access the Web server, you must contact it by going through the proxy server. Benchmarking the effect of these changes is difficult. Because these changes reduce the overhead mainly associated with handling clients over high-latency links, it is difficult to measure the effects on a local or high-speed network. In a real-world setting, I have seen a reverse-proxy setup cut the number of Apache children necessary to support a site from 100 to 20. Operating System Tuning for High Performance There is a strong argument that if you do not want to perform local caching, then using a reverse proxy is overkill. A way to get a similar effect without running a separate server is to allow the operating system itself to buffer all the data. In the discussion of reverse proxies earlier in this chapter, you saw that a major component of the network wait time is the time spent blocking between data packets to the client. The application is forced to send multiple packets because the operating system has a limit on how much information it can buffer to send over a TCP socket at one time. Fortunately, this is a setting that you can tune. Language-Level Tunings 229 On FreeBSD, you can adjust the TCP buffers via the following:#sysctl –w net.inet.tcp.sendspace=131072#sysctl –w net.inet.tcp.recvspace=8192On Linux, you do this:#echo “131072” > /proc/sys/net/core/wmem_maxWhen you make either of these changes, you set the outbound TCP buffer space to128KB and the inbound buffer space to 8KB (because you receive small inboundrequests and make large outbound responses).This assumes that the maximum page sizeyou will be sending is 128KB. If your page sizes differ from that, you need to change thetunings accordingly. In addition, you might need to tune kern.ipc.nmbclusters toallocate sufficient memory for the new large buffers. (See your friendly neighborhoodsystems administrator for details.) After adjusting the operating system limits, you need to instruct Apache to use thelarge buffers you have provided. For this you just add the following directive to yourhttpd.conf file:SendBufferSize 131072Finally, you can eliminate the network lag on connection close by installing the lingerdpatch to Apache.When a network connection is finished, the sender sends the receiver aFIN packet to signify that the connection is complete.The sender must then wait for thereceiver to acknowledge the receipt of this FIN packet before closing the socket toensure that all data has in fact been transferred successfully. After the FIN packet is sent,Apache does not need to do anything wi ...
Nội dung trích xuất từ tài liệu:
Advanced PHP Programming- P6228 Chapter 9 External Performance Tunings Pre-Fork, Event-Based, and Threaded Process Architectures The three main architectures used for Web servers are pre-fork, event-based, and threaded models. In a pre-fork model, a pool of processes is maintained to handle new requests. When a new request comes in, it is dispatched to one of the child processes for handling. A child process usually serves more than one request before exiting. Apache 1.3 follows this model. In an event-based model, a single process serves requests in a single thread, utilizing nonblocking or asyn- chronous I/O to handle multiple requests very quickly. This architecture works very well for handling static files but not terribly well for handling dynamic requests (because you still need a separate process or thread to the dynamic part of each request). thttpd, a small, fast Web server written by Jef Poskanzer, utilizes this model. In a threaded model, a single process uses a pool of threads to service requests. This is very similar to a pre- fork model, except that because it is threaded, some resources can be shared between threads. The Zeus Web server utilizes this model. Even though PHP itself is thread-safe, it is difficult to impossible to guaran- tee that third-party libraries used in extension code are also thread-safe. This means that even in a threaded Web server, it is often necessary to not use a threaded PHP, but to use a forked process execution via the fastcgi or cgi implementations. Apache 2 uses a drop-in process architecture that allows it to be configured as a pre-fork, threaded, or hybrid architecture, depending on your needs. In contrast to the amount of configuration inside Apache, the PHP setup is very similar to the way it was before.The only change to its configuration is to add the following to its httpd.conf file: Listen localhost:80 This binds the PHP instance exclusively to the loopback address. Now if you want to access the Web server, you must contact it by going through the proxy server. Benchmarking the effect of these changes is difficult. Because these changes reduce the overhead mainly associated with handling clients over high-latency links, it is difficult to measure the effects on a local or high-speed network. In a real-world setting, I have seen a reverse-proxy setup cut the number of Apache children necessary to support a site from 100 to 20. Operating System Tuning for High Performance There is a strong argument that if you do not want to perform local caching, then using a reverse proxy is overkill. A way to get a similar effect without running a separate server is to allow the operating system itself to buffer all the data. In the discussion of reverse proxies earlier in this chapter, you saw that a major component of the network wait time is the time spent blocking between data packets to the client. The application is forced to send multiple packets because the operating system has a limit on how much information it can buffer to send over a TCP socket at one time. Fortunately, this is a setting that you can tune. Language-Level Tunings 229 On FreeBSD, you can adjust the TCP buffers via the following:#sysctl –w net.inet.tcp.sendspace=131072#sysctl –w net.inet.tcp.recvspace=8192On Linux, you do this:#echo “131072” > /proc/sys/net/core/wmem_maxWhen you make either of these changes, you set the outbound TCP buffer space to128KB and the inbound buffer space to 8KB (because you receive small inboundrequests and make large outbound responses).This assumes that the maximum page sizeyou will be sending is 128KB. If your page sizes differ from that, you need to change thetunings accordingly. In addition, you might need to tune kern.ipc.nmbclusters toallocate sufficient memory for the new large buffers. (See your friendly neighborhoodsystems administrator for details.) After adjusting the operating system limits, you need to instruct Apache to use thelarge buffers you have provided. For this you just add the following directive to yourhttpd.conf file:SendBufferSize 131072Finally, you can eliminate the network lag on connection close by installing the lingerdpatch to Apache.When a network connection is finished, the sender sends the receiver aFIN packet to signify that the connection is complete.The sender must then wait for thereceiver to acknowledge the receipt of this FIN packet before closing the socket toensure that all data has in fact been transferred successfully. After the FIN packet is sent,Apache does not need to do anything wi ...
Tìm kiếm theo từ khóa liên quan:
thủ thuật máy tính công nghệ thông tin tin học quản trị mạng computer networkGợi ý tài liệu liên quan:
-
52 trang 430 1 0
-
24 trang 354 1 0
-
Top 10 mẹo 'đơn giản nhưng hữu ích' trong nhiếp ảnh
11 trang 314 0 0 -
Làm việc với Read Only Domain Controllers
20 trang 303 0 0 -
74 trang 296 0 0
-
96 trang 293 0 0
-
Báo cáo thực tập thực tế: Nghiên cứu và xây dựng website bằng Wordpress
24 trang 289 0 0 -
Đồ án tốt nghiệp: Xây dựng ứng dụng di động android quản lý khách hàng cắt tóc
81 trang 281 0 0 -
EBay - Internet và câu chuyện thần kỳ: Phần 1
143 trang 275 0 0 -
Tài liệu dạy học môn Tin học trong chương trình đào tạo trình độ cao đẳng
348 trang 269 1 0