วิธีใช้ IIS Worker Process (w3wp.exe) บน Windows Server 2022 อย่างมืออาชีพ
หากคุณดูแล IIS บน Windows Server 2022 ไม่ว่าจะเป็นเว็บไซต์องค์กร ระบบ ERP, CRM, Intranet หรือ Web Application ขนาดใหญ่ คุณจะต้องรู้จักกับ Process ที่ชื่อว่า
w3wp.exe
หรือที่เรียกว่า IIS Worker Process
Worker Process ถือเป็นหัวใจสำคัญของ IIS เพราะเป็นตัวที่ประมวลผล Request จากผู้ใช้งานทั้งหมด หาก Process นี้มีปัญหา เว็บไซต์ก็จะช้า ค้าง หรือหยุดทำงานทันที
บทความนี้จะอธิบายการทำงานของ IIS Worker Process อย่างละเอียด พร้อมแนวทางวิเคราะห์และแก้ไขปัญหาระดับผู้ดูแลระบบมืออาชีพ
🌐 IIS Worker Process คืออะไร
Worker Process คือ Process ที่ IIS สร้างขึ้นเพื่อรันเว็บไซต์และ Application
ชื่อ Process คือ
w3wp.exe
อยู่ที่
C:\Windows\System32\inetsrv\w3wp.exe
ทุกครั้งที่มีผู้ใช้งานเข้าเว็บไซต์
Browser
↓
IIS
↓
Application Pool
↓
w3wp.exe
↓
Website
Request จะถูกส่งมายัง Worker Process เพื่อประมวลผล
🔍 Worker Process ทำงานร่วมกับ Application Pool อย่างไร
IIS ไม่ได้รันเว็บไซต์ทั้งหมดใน Process เดียว
ตัวอย่าง
Website A
↓
AppPool_A
↓
w3wp.exe
Website B
↓
AppPool_B
↓
w3wp.exe
แต่ละ App Pool จะมี Worker Process ของตนเอง
ข้อดีคือ
✅ แยกปัญหาระหว่างเว็บไซต์
✅ เพิ่มความปลอดภัย
✅ ลดผลกระทบเมื่อเว็บล่ม
🚀 วิธีดู Worker Process ผ่าน IIS Manager
เปิด
inetmgr
เลือกชื่อ Server
ดับเบิลคลิก
Worker Processes
จะเห็น
| PID | Application Pool |
|---|---|
| 4580 | comsiam_pool |
| 6212 | api_pool |
| 7420 | intranet_pool |
ช่วยให้ทราบว่าแต่ละเว็บไซต์ใช้ Process ใด
🚀 ดู Worker Process ผ่าน PowerShell
แสดง Process ทั้งหมด
Get-Process w3wp
ตัวอย่าง
Handles CPU Id
1024 18 4580
845 12 6212
🚀 ดู Worker Process ผ่าน AppCmd
appcmd list wp
ผลลัพธ์
WP "4580" (applicationPool:comsiam_pool)
WP "6212" (applicationPool:api_pool)
วิธีนี้ได้รับความนิยมบน Server Core
🔍 วิธีดูว่า Worker Process กิน CPU เท่าไร
PowerShell
Get-Process w3wp |
Sort CPU -Descending
ตัวอย่าง
Id CPU
4580 980
6212 55
หมายถึง
Process 4580 ใช้ CPU สูงผิดปกติ
🔍 วิธีดูว่า Worker Process กิน RAM เท่าไร
Get-Process w3wp |
Sort WorkingSet -Descending
ตัวอย่าง
Id RAM
4580 2.5GB
6212 450MB
หากเพิ่มขึ้นเรื่อย ๆ อาจเกิด Memory Leak
🔍 วิธีจับคู่ PID กับเว็บไซต์
ดู PID
Get-Process w3wp
จากนั้น
appcmd list wp
ตัวอย่าง
4580 → comsiam_pool
แล้วดูว่าเว็บไซต์ใดใช้ Pool นี้
Get-Website
🚀 Recycle Worker Process
วิธีที่ดีที่สุดในการรีเฟรช Process
PowerShell
Restart-WebAppPool "comsiam_pool"
หรือ
appcmd recycle apppool /apppool.name:"comsiam_pool"
🚀 Kill Worker Process
กรณีฉุกเฉิน
taskkill /PID 4580 /F
หรือ
Stop-Process -Id 4580 -Force
IIS จะสร้าง Process ใหม่ให้อัตโนมัติ
⚠️ ควร Kill Process เมื่อใด
เหมาะกับกรณี
✅ CPU 100%
✅ Memory Leak รุนแรง
✅ Worker Process ค้าง
✅ Application ไม่ตอบสนอง
ไม่ควรใช้เป็นวิธีแก้ปัญหาประจำ
🔍 ตรวจสอบจำนวน Worker Process
PowerShell
(Get-Process w3wp).Count
ตัวอย่าง
15
หมายถึงมี Worker Process 15 ตัว
🚀 Web Garden คืออะไร
ค่าเริ่มต้น
1 App Pool = 1 Worker Process
แต่สามารถกำหนด
1 App Pool = หลาย Worker Process
เรียกว่า
Web Garden
ตั้งค่าที่
Application Pool
→ Advanced Settings
→ Maximum Worker Processes
⚠️ ควรใช้ Web Garden หรือไม่
Microsoft แนะนำ
Maximum Worker Processes = 1
สำหรับเว็บไซต์ส่วนใหญ่
เนื่องจาก
Session Sharing ซับซ้อน
Debug ยาก
Memory เพิ่มขึ้น
🚨 Worker Process Crash บ่อย
ตรวจสอบ
Event Viewer
→
Windows Logs
→
Application
มองหา Error
WAS
w3wp.exe
.NET Runtime
🚨 Worker Process ใช้ RAM สูงไม่หยุด
สาเหตุที่พบบ่อย
Memory Leak
Query ค้าง
Session มากเกินไป
Cache ไม่ถูกล้าง
แนวทางแก้
Recycle App Pool
และตรวจสอบ Source Code
🚨 Worker Process ใช้ CPU สูง
ตรวจสอบ
Get-Process w3wp
จากนั้น
appcmd list wp
เพื่อหาเว็บไซต์ต้นเหตุ
📊 Performance Counter ที่ควร Monitor
เปิด
perfmon
ติดตาม
Process → % Processor Time
Process → Working Set
Process → Thread Count
Web Service → Current Connections
🔒 Best Practices
สำหรับ Windows Server 2022
ควร
① แยก App Pool ทุกเว็บไซต์
② เปิด Auto Recycle
③ ตรวจสอบ Memory ทุกวัน
④ เปิด Performance Monitoring
⑤ ใช้ Dedicated Identity
⑥ เก็บ Log และ Event Viewer
ทีมงาน comsiam มักใช้ Worker Process Monitoring เป็นจุดเริ่มต้นในการวิเคราะห์ปัญหาเว็บไซต์ เพราะสามารถระบุได้รวดเร็วว่าเว็บไซต์ใดเป็นต้นเหตุของ CPU หรือ RAM ที่สูงผิดปกติ
ในระบบองค์กรขนาดใหญ่ comsiam แนะนำให้ติดตั้งระบบ Monitoring เช่น PRTG หรือ Zabbix เพื่อตรวจสอบ w3wp.exe แบบ Real-Time และแจ้งเตือนก่อนที่ระบบจะเริ่มมีผลกระทบต่อผู้ใช้งาน
🎯 สรุป
IIS Worker Process หรือ
w3wp.exe
คือ Process สำคัญที่ใช้ประมวลผลเว็บไซต์บน Windows Server 2022
การเข้าใจความสัมพันธ์ระหว่าง
Website
→ Application Pool
→ Worker Process
จะช่วยให้ผู้ดูแลระบบสามารถวิเคราะห์ปัญหา CPU สูง, RAM สูง, เว็บไซต์ช้า และ Application Crash ได้อย่างมีประสิทธิภาพ และลด Downtime ของระบบได้อย่างมาก