วิธีดู Process ของ IIS บน Windows Server 2022 เพื่อวิเคราะห์ปัญหาเว็บ

 เมื่อเว็บไซต์บน IIS เริ่มทำงานช้า ใช้ CPU สูง กิน RAM มากผิดปกติ หรือเกิดปัญหาเว็บไซต์ค้าง สิ่งแรกที่ผู้ดูแลระบบควรตรวจสอบคือ Process ของ IIS

บน Windows Server 2022 เว็บไซต์ทุกเว็บที่ทำงานบน IIS จะถูกรันผ่าน Process ที่ชื่อว่า w3wp.exe หรือที่เรียกว่า IIS Worker Process การเข้าใจการทำงานของ Process เหล่านี้จะช่วยให้สามารถวิเคราะห์ปัญหา Performance, Memory Leak และ Application Error ได้อย่างแม่นยำ

บทความนี้จะอธิบายวิธีดู Process ของ IIS แบบละเอียด ตั้งแต่ระดับพื้นฐานจนถึงระดับ Enterprise


🌐 IIS Process คืออะไร

เมื่อเว็บไซต์ทำงานบน IIS

IIS จะสร้าง Process

w3wp.exe

ขึ้นมาเพื่อประมวลผลเว็บไซต์

ตัวอย่าง

Website A
   ↓
AppPool_A
   ↓
w3wp.exe

Website B
   ↓
AppPool_B
   ↓
w3wp.exe

แต่ละ Application Pool สามารถมี Worker Process ของตัวเองได้


🔍 ทำไมต้องดู IIS Process

ช่วยวิเคราะห์

✅ CPU สูง

✅ RAM สูง

✅ เว็บไซต์ค้าง

✅ Application Crash

✅ Memory Leak

✅ Slow Response

✅ Process Loop


🚀 วิธีที่ 1 ดูผ่าน Task Manager

เปิด

Ctrl + Shift + Esc

หรือ

taskmgr

ไปที่

Details

ค้นหา

w3wp.exe

จะเห็น

  • PID

  • CPU

  • RAM

  • User Name

ของแต่ละ Process


🔍 ดู PID ของ Worker Process

ตัวอย่าง

w3wp.exe      PID 4580
w3wp.exe      PID 6212
w3wp.exe      PID 7140

แต่ยังไม่ทราบว่า PID ไหนเป็นเว็บไซต์ใด


🚀 วิธีที่ 2 ดูผ่าน IIS Manager

เปิด

inetmgr

เลือกชื่อ Server


ดับเบิลคลิก

Worker Processes

จะเห็น

App PoolPID
comsiam_pool4580
api_pool6212
intranet_pool7140

วิธีนี้ง่ายที่สุด

เพราะเห็นความสัมพันธ์ระหว่าง

  • Website

  • Application Pool

  • PID

ทันที


🚀 วิธีที่ 3 ดูผ่าน PowerShell

แสดง Process

Get-Process w3wp

ตัวอย่าง

Handles NPM(K) PM(K) CPU(s) Id
------- ------ ----- ------ ----
800     120    300MB  20.4  4580

ดู CPU สูงสุด

Get-Process w3wp |
Sort CPU -Descending

ดู RAM สูงสุด

Get-Process w3wp |
Sort WorkingSet -Descending

🚀 วิธีที่ 4 ดูผ่าน AppCmd

แสดง Worker Process

appcmd list wp

ตัวอย่าง

WP "4580" (applicationPool:comsiam_pool)
WP "6212" (applicationPool:api_pool)

วิธีนี้นิยมใช้มากใน Server Core


🚀 วิธีที่ 5 ดูผ่าน Resource Monitor

เปิด

resmon

ไปที่

CPU

หรือ

Memory

ค้นหา

w3wp.exe

ช่วยวิเคราะห์

  • CPU Spike

  • Memory Leak

  • Disk Usage

ได้ละเอียดกว่า Task Manager


🚀 วิธีที่ 6 ดูผ่าน Performance Monitor

เปิด

perfmon

เพิ่ม Counter

Process

w3wp

ตรวจสอบ

  • CPU

  • Memory

  • Thread Count

  • Handle Count

แบบ Real-Time


🔍 ตรวจสอบ Command Line ของ Process

PowerShell

Get-CimInstance Win32_Process |
Where {$_.Name -eq "w3wp.exe"} |
Select ProcessId,CommandLine

ช่วยตรวจสอบว่า Process นั้นเชื่อมกับ App Pool ใด


🚨 วิธีหาเว็บไซต์ที่กิน CPU สูง

PowerShell

Get-Process w3wp |
Sort CPU -Descending |
Select -First 5

จากนั้นดู PID

แล้วเทียบกับ

appcmd list wp

จะทราบว่าเว็บไซต์ใดเป็นต้นเหตุ


🚨 วิธีหาเว็บไซต์ที่กิน RAM สูง

PowerShell

Get-Process w3wp |
Sort WorkingSet -Descending

หากพบ

2 GB
4 GB
8 GB

อาจเกิด

  • Memory Leak

  • Query ไม่จบ

  • Application Error


🔍 ตรวจสอบ Thread ของ Process

PowerShell

Get-Process w3wp |
Select ProcessName,Threads

Thread จำนวนมากผิดปกติ

อาจบ่งบอกถึงปัญหา Performance


🚀 Kill Worker Process

กรณีฉุกเฉิน

taskkill /PID 4580 /F

หรือ

Stop-Process -Id 4580 -Force

IIS จะสร้าง Process ใหม่อัตโนมัติ

หาก Application Pool ยังทำงานอยู่


🚨 ข้อควรระวัง

ไม่ควร Kill Process โดยไม่ตรวจสอบก่อน

เพราะอาจทำให้

  • Session หาย

  • ผู้ใช้หลุดระบบ

  • Transaction ขาดตอน


📊 เครื่องมือที่นิยมใช้

เครื่องมือเหมาะกับ
Task Managerดูเร็ว
IIS Managerดู App Pool
PowerShellAutomation
AppCmdServer Core
Resource Monitorวิเคราะห์เชิงลึก
PerfMonMonitoring ระยะยาว

🔒 Best Practices

สำหรับ Production Server

ควร

① แยก App Pool ทุกเว็บไซต์

② เปิด Monitoring

③ ตั้ง Memory Limit

④ ตั้ง Auto Recycle

⑤ ตรวจสอบ CPU และ RAM ทุกวัน

⑥ เก็บ Log Performance

ทีมงาน comsiam มักเริ่มต้นการวิเคราะห์ปัญหา IIS ด้วย Worker Processes และ PowerShell เพราะสามารถระบุได้ทันทีว่าเว็บไซต์ใดกำลังใช้ทรัพยากรมากที่สุด

ในระบบที่มีหลายสิบเว็บไซต์ comsiam แนะนำให้ใช้ Performance Monitor และ Monitoring System ร่วมกัน เพื่อแจ้งเตือนก่อนที่ CPU หรือ RAM จะถึงระดับวิกฤต


🎯 สรุป

Process หลักของ IIS บน Windows Server 2022 คือ

w3wp.exe

ซึ่งเป็น Worker Process ที่ใช้ประมวลผลเว็บไซต์และ Web Application

เครื่องมือที่ใช้ตรวจสอบได้ดีที่สุดคือ

appcmd list wp

และ

Get-Process w3wp

เมื่อเข้าใจความสัมพันธ์ระหว่าง Website, Application Pool และ Worker Process แล้ว จะสามารถวิเคราะห์และแก้ไขปัญหา Performance ของ IIS ได้อย่างรวดเร็วและมีประสิทธิภาพ

Popular posts from this blog

Windows Server 2022 ยังน่าใช้ในปีนี้หรือไม่? คำตอบสำหรับคนกำลังวางระบบใหม่

สเปกเครื่องสำหรับติดตั้ง Windows Server 2022 เลือกอย่างไรให้คุ้มและใช้งานได้ยาว

Windows Server 2022 คืออะไร? คู่มือสำหรับมือใหม่