บทที่ 2 Web Serversหลังจากนักฟิสิกส์นาม Tim Berners-Lee ได้ค้นคิด HTML โลกเราก็รู้จัก web page หลังจากนั้น National Center for Supercomputing Applications(NCSA)ทำให้เราได้รู้จัก Web Browser (NCSA Mosaic) และ Web Server (NCSA HTTPd) แต่ NCSA HTTPd ยังมีจุดอ่อนที่ต้องแก้ไข นาย Robert McCool ซึ่งมีส่วนเกี่ยวข้องกับาการพัฒนา NCSA HTTPd เมื่อออกจาก NCSA ก็ยังต้องการแก้ไข NCSA HTTPd ความตั้งใจเดิมของ Robert นั้นต้องการสร้างส่วนแก้ไข (a Patch) โดยตั้งชื่อโปรแกรมตัวเองว่า Apache (A Patch of NCSA HTTPd, A PAtCHy) โดยมีคนเข้าร่วมหลายคน ไปๆมาๆเลยกลายเป็น Web Server ทั้งตัว แถม Apache กลายเป็นมาตราฐานของ Web Server ของฝั่ง Unix/Linux ที่ใครๆก็รู้จัก
การออกแบบระบบให้สามารถใช้งานได้สูง ถ้าการใช้งานระบบกระทำผ่านเวป ส่วนสำคัญของระบบก็คือ Web Server นั้นเอง
Apache 1.3 and 2.0
http://www.linuxjournal.com/article/4559ตามที่กล่าวมา Apache ถูกสร้างโดยมุ่งที่การแก้ปัญหาของ Web Server เดิม (NCSA) จึงทำให้ Apache ถูกพัฒนาอย่างมากใน Apache รุ่นถัดมา โดย Apache รุ่นแรกจะมีการทำงานแบบสร้างตัวเอง(Fork) เพื่อรับงานที่มากขึ้น ในขณะที่ รุ่น 2.0 มีโหมดการทำงานที่เรียกว่า Worker ซึ่งใช้เทคนิคแบบ Multithread ทำให้ Apache มีประสิทธิภาพที่ดีขึ้น
Prefork• High memory usage
• Highly tolerant of faulty modules
• Highly tolerant of crashing children
• Fast
• Well-suited for 1 and 2-CPU systems
• Tried-and-tested model from Apache 1.3
• “You’ll run out of memory before CPU.”
Worker• Low to moderate memory usage
• Moderately tolerant to faulty modules
• Faulty threads can affect all threads in child
• Highly-scalable
• Well-suited for multiple processors
• Requires a mature threading library
(Solaris, AIX, Linux 2.6 and others work well)
• Memory is no longer the bottleneck.
จากการทดสอบของ camelrichard (
http://www.camelrichard.org/apache-prefork-vs-worker) ได้ผลได้ดังนี้
-------------------------------------------------------------
Siege results for prefork:
-------------------------------------------------------------
Lifting the server siege... done.
Transactions: 6045 hits
Availability: 100.00 %
Elapsed time: 300.38 secs
Data transferred: 0.25 MB
Response time: 0.50 secs
Transaction rate: 20.12 trans/sec
Throughput: 0.00 MB/sec
Concurrency: 9.97
Successful transactions: 6045
Failed transactions: 0
Longest transaction: 10.13
Shortest transaction: 0.00
-------------------------------------------------------------
-------------------------------------------------------------
Siege results for worker:
-------------------------------------------------------------
Lifting the server siege... done.
Transactions: 11024 hits
Availability: 100.00 %
Elapsed time: 300.24 secs
Data transferred: 0.46 MB
Response time: 0.27 secs
Transaction rate: 36.72 trans/sec
Throughput: 0.00 MB/sec
Concurrency: 9.91
Successful transactions: 11024
Failed transactions: 0
Longest transaction: 11.92
Shortest transaction: 0.00
-------------------------------------------------------------
ซึ่งพบว่าการทำงานแบบ Worker นั้นให้การตอบสนองได้ดีกว่าแบบ Prefork เกือบ 2 เท่า แต่เรามักจะได้ยินว่าถ้าเราใช้ PHP ให้ตั้งค่าเป็นแบบ Worker ทั้งนี้เหตุผลหลักก็เพราะ PHP ก่อนรุ่น 4.3 ยังมีปัญหากับการทำงานแบบ Worker (
http://th2.php.net/manual/en/install.unix.apache2.php) และ การทำงานแบบ Prefork นั้นมีความน่าเชื่อถือได้มากกว่า Worker (ถ้า Module หรือ Child Process เกิดข้อผิดพลาด)