FiveM Profiler คืออะไร? วิธีหา Script ทำ Server ช้า
FiveM Profiler คือเครื่องมือวิเคราะห์ Performance ที่ช่วยหาได้ว่า Resource, Thread, Function หรือ Code ส่วนใดกำลังทำให้ FiveM Server ช้า เกิด Hitch Warning หรือทำให้ Client FPS ตก
แทนที่จะเดาว่า
ESX หนัก
QBCore กิน CPU
Inventory ทำ Server Lag
Database ช้า
Script ใหม่เป็นตัวปัญหา
Profiler ช่วยให้ Developer ตรวจจากข้อมูลจริงได้เป็นลำดับ
ปัญหาเกิด
↓
Capture Profile
↓
หา CPU Time Spike
↓
ดู Resource Tick
↓
หา Resource
↓
หา Thread / File / Code
↓
แก้ Root Cause
↓
Profile ซ้ำ
Cfx.re ระบุว่า Profiler ใช้ได้ทั้ง Server-side และ Client-side โดยฝั่ง Server เหมาะกับการหา Hitch Warning ส่วนฝั่ง Clientใช้หา FPS Drop และ Micro-stuttering
สำหรับ FiveM Enhanced ระบบ Profiler ถูกเปลี่ยนไปใช้ Perfetto เป็น Backend ใหม่ ทำให้สามารถวิเคราะห์ Timeline ของ Server และ Client ได้ละเอียดขึ้น
บทความนี้จาก comsiam จะอธิบายตั้งแต่การเปิด Profiler วิธี Capture วิธีอ่านผล ไปจนถึงการหา Script ตัวจริงที่ทำให้ Server ช้า
① FiveM Profiler คืออะไร?
Profiler คือเครื่องมือสำหรับบันทึกว่า FiveM ใช้เวลาไปกับงานอะไรในช่วงเวลาหนึ่ง
ตัวอย่าง Server ทำงาน:
Server Tick
├── Framework
├── Inventory
├── Garage
├── Police
├── Housing
└── Custom Script
Profiler ช่วยบอกได้ว่าใน Tick ที่ Server กระตุก Resource ตัวไหนใช้เวลามากผิดปกติ
② Profiler ใช้หาอะไรได้บ้าง?
ใช้หาได้ เช่น
Server Thread Hitch
Resource กิน CPU
Script ทำงานช้า
Client FPS Drop
Micro-stutter
Heavy Loop
Resource Spike
Function ที่ใช้เวลานาน
โดยเฉพาะปัญหาที่เกิดเป็นช่วง ๆ ซึ่ง Task Manager หรือ Resmon อาจบอกได้ไม่ละเอียดพอ
③ Profiler ใช้ฝั่ง Server ได้ไหม?
ได้
นี่เป็น Use Case สำคัญมาก
ถ้า Console มี
server thread hitch warning
Profiler สามารถช่วยหา Resource ที่ทำให้ Tick นั้นใช้เวลานานผิดปกติ
④ Profiler ใช้ฝั่ง Client ได้ไหม?
ได้เช่นกัน
เหมาะกับอาการ
FPS ตก
กระตุกทุกไม่กี่วินาที
เปิด Phone แล้วกระตุก
เข้า Garage แล้ว FPS ลด
Client Resource หนัก
Resmon สามารถช่วยหา Resource ต้องสงสัยก่อน แล้ว Profiler ใช้เจาะลึกต่อ
⑤ Resmon กับ Profiler ต่างกันอย่างไร?
Resmon
เหมาะกับดูภาพรวม Client Resource อย่างรวดเร็ว
เช่น
CPU Time
Memory
Profiler
เหมาะกับเจาะลงไปว่า
Resource
↓
Thread
↓
Function
↓
File / Code
ดังนั้นสองเครื่องมือไม่ใช่คู่แข่งกัน
ควรใช้ร่วมกัน
⑥ Server CPU สูงควรใช้ Resmon หรือ Profiler?
Profiler
Resmon เป็นเครื่องมือฝั่ง Client เป็นหลัก
ถ้า FXServer CPU สูงหรือมี Server Hitch ให้ใช้
Server Profiler
txAdmin
Server Metrics
เป็นหลัก
⑦ ก่อน Profile ต้องทำอะไร?
จด Context ของปัญหาก่อน เช่น
Player Count: 150
CPU: 75%
RAM: 10 GB
อาการ: Inventory Delay
Console: Hitch Warning
เวลาเกิด: ตอน Payday
ข้อมูล Context ช่วยตีความ Profile ได้แม่นขึ้น
⑧ วิธีเริ่ม FiveM Profiler
เอกสาร Profiler ทั่วไปของ Cfx.re ระบุคำสั่ง
profiler record 500
เลข 500 คือจำนวน Frames ที่ต้องการบันทึกใน Workflow แบบ Legacy Profiler และเป็นค่าที่เอกสารใช้เป็นจุดเริ่มต้น
⑨ profiler record ทำอะไร?
มันเริ่มบันทึก Performance Data ในช่วงเวลาที่กำหนด
เป้าหมายคือให้ Capture ครอบคลุมช่วงที่ปัญหาเกิด
ถ้า Server กระตุกตอนกด Garage ให้เริ่ม Capture แล้วทำ Garage Action ขณะ Recording
⑩ ตรวจสถานะ Profiler อย่างไร?
ใช้
profiler status
เพื่อดูว่า
กำลัง Record อยู่หรือไม่
Capture ไปถึงไหนแล้ว
ควรรอให้ Capture เสร็จก่อนวิเคราะห์
⑪ Legacy Profiler เปิดดูอย่างไร?
เอกสาร Profiler แบบ Legacy ระบุ
profiler view
สำหรับเปิด Profile
ถ้าเรียกจาก Server Console ระบบจะให้ Address สำหรับนำไปเปิดใน Browser
⑫ Legacy Profiler บันทึกไฟล์อย่างไร?
เอกสาร Legacy ระบุคำสั่ง
profiler saveJSON filename.json
เพื่อ Save Profile เป็น JSON
จากนั้นสามารถนำไปวิเคราะห์เพิ่มเติมได้
⑬ Enhanced Profiler เปลี่ยนอะไร?
FiveM Enhanced เปลี่ยน Profiler Backend ไปใช้
Perfetto
Cfx.re ระบุคำสั่ง Enhanced เช่น
profiler record <duration>
profiler save <filename>.json
Trace จะถูกเก็บในโฟลเดอร์ profiler/ ของ FiveM Enhanced
⑭ ทำไมคำสั่ง Legacy กับ Enhanced ดูต่างกัน?
เพราะ FiveM มี Profiler Workflow คนละ Generation
Legacy Documentation
มีคำสั่งเช่น
profiler saveJSON
profiler view
Enhanced
ใช้ Perfetto Backend และประกาศ Workflow
profiler record
profiler save
ดังนั้นควรใช้คำสั่งให้ตรงกับ Runtime ที่กำลังใช้งาน
⑮ Perfetto คืออะไร?
Perfetto เป็นระบบ Trace/Performance Analysis ที่แสดง Timeline ของงานต่าง ๆ
ช่วยให้ Developerเห็นว่าในช่วงหนึ่งมี
Thread ไหนทำงาน
งานไหนใช้เวลานาน
Spike เกิดตรงไหน
ได้ชัดเจน
⑯ ทำไม Timeline สำคัญ?
สมมติ Server กระตุกทุก 10 วินาที
ค่า CPU เฉลี่ยอาจดูปกติ
30%
32%
31%
90% ← Spike
30%
31%
Profiler Timeline จะทำให้เห็น Spike นั้น
ต่างจากการดู Average CPU เพียงอย่างเดียว
⑰ CPU สูงตลอดกับ CPU Spike ต่างกันอย่างไร?
CPU สูงตลอด
อาจมี Continuous Heavy Workload
CPU Spike
อาจเกิดจาก
Scheduled Loop
Autosave
Payday
SQL Burst
Cleanup
Logging
Profiler เหมาะมากกับการหา Spike
⑱ ต้อง Capture ตอนปัญหาเกิด
นี่เป็นหลักสำคัญที่สุดข้อหนึ่ง
ถ้าปัญหาเกิดตอน Server มี 200 Players
อย่า Profile ตอนมีผู้เล่น 5 คนแล้วสรุปว่า Server ไม่มีปัญหา
Profile ต้องครอบคลุม Workload ที่ทำให้เกิดอาการ
⑲ Capture ตอน Peak Hour ดีที่สุดไหม?
ถ้าปัญหาเกิดตอน Peak Hour ใช่
เช่น
18:00 → 80 Players ปกติ
20:00 → 150 Players เริ่ม Hitch
22:00 → 220 Players Hitch หนัก
ควร Capture ใกล้ 150–220 Players
⑳ อย่า Restart ก่อน Capture ถ้าไม่จำเป็น
ถ้า Server ยังทำงานได้และไม่เสี่ยงต่อข้อมูล
ควรเก็บ
Profiler
Console
Metrics
Player Count
ก่อน Restart
เพราะ Restart สามารถทำให้อาการหายและเสีย Evidence
㉑ เปิด Profile แล้วดูอะไรเป็นอันดับแรก?
มองหา
CPU Time Spike
หรือ Frame/Tick ที่ใช้เวลานานกว่าปกติอย่างชัดเจน
จากนั้น Zoom เข้าไปในช่วงนั้น
㉒ Resource Tick คืออะไร?
เป็นช่วงที่ Script Resources ทำงานใน Tick นั้น
เมื่อ Zoom เข้า Spike สามารถเห็นว่า Resource ใดใช้เวลามาก
ตัวอย่าง:
resource tick
├── framework
├── inventory
├── housing
└── custom-garage ← สูงผิดปกติ
จากนั้นเจาะ custom-garage
㉓ Profiler หาได้ถึง File หรือไม่?
ได้
เอกสาร Cfx.re แสดงตัวอย่าง Profiler ที่สามารถระบุ
Resource
File
ช่วงบรรทัด
ของ Thread ที่ทำให้ Performance ลดลงได้
นี่เป็นเหตุผลที่ Profiler มีประโยชน์มากสำหรับ Developer ที่มี Source Code
㉔ หา Resource เจอแล้วทำอะไรต่อ?
อย่าเพิ่งลบ Resource
ให้ตรวจว่า Function ที่หนักกำลังทำอะไร
เช่น
Loop
Native
SQL
JSON
Entity Scan
Event
Logging
แล้วแก้เฉพาะต้นเหตุ
㉕ Loop เป็น Candidate อันดับต้น ๆ
ตัวอย่าง:
CreateThread(function()
while true do
Wait(0)
HeavyFunction()
end
end)
ถ้า HeavyFunction() ใช้เวลาแม้เพียงเล็กน้อยแต่ถูกเรียกตลอดเวลา Total Cost จะสูงมาก
㉖ Wait(0) ต้องลบทั้งหมดไหม?
ไม่
บาง Client Function ต้องทำงานทุก Frame
แต่ Server-side Logic จำนวนมากไม่จำเป็น
ถามว่า
Feature นี้ต้องทำงานทุก Frame จริงหรือไม่?
ถ้าไม่ ให้ลด Frequency
㉗ ตัวอย่างการลด Frequency
จาก
while true do
Wait(0)
CheckPlayers()
end
เป็น
while true do
Wait(1000)
CheckPlayers()
end
ถ้าตรวจทุกหนึ่งวินาทีก็เพียงพอกับ Feature
㉘ อย่าเพิ่ม Wait แบบเดาสุ่ม
ถ้า Interaction ต้อง Responsive
การเปลี่ยนทุก Loop เป็น
Wait(5000)
อาจทำ Gameplay ช้า
ต้องออกแบบ Interval ตาม Requirement
㉙ Player Loop ต้องตรวจด้วย Profiler
ตัวอย่าง:
for _, playerId in ipairs(GetPlayers()) do
CheckPlayer(playerId)
end
50 Players อาจเบา
500 Players อาจเริ่มหนัก
Profiler ตอน Player Count สูงจะทำให้เห็น Scaling Cost
㉚ O(n²) เป็นปัญหาสำคัญ
ถ้า Script ทำ Player กับ Player ทุกคู่
100 Players
≈ 10,000 Comparisons
500 Players
≈ 250,000 Comparisons
1,000 Players
≈ 1,000,000 Comparisons
ต่อหนึ่งรอบ
Resource อาจดูดีตอน Development แต่พังใน Production
㉛ Profiler เหมาะกับหา Scaling Problem
เปรียบเทียบ Profile
50 Players
vs
150 Players
vs
300 Players
แล้วดู Resource Tick ของตัวเดียวกัน
ถ้า Cost เพิ่มเร็วผิดปกติ ต้องตรวจ Algorithm
㉜ Entity Scan ต้องตรวจ
Resource อาจทำ
GetAllVehicles()
GetAllPeds()
GetAllObjects()
แล้ว Loopทุก Entity
เมื่อ Server มี Entity มากขึ้น Script จะหนักตาม
Profiler สามารถช่วยเห็น Resource ที่ใช้เวลาทำ Scan
㉝ Cleanup Script อาจเป็น Script ตัวปัญหา
บาง Resource มีชื่อว่า
optimizer
cleanup
entity-cleaner
แต่ถ้ามัน Scan Entity ทั้งโลกทุก 100 ms มันอาจสร้าง Load เอง
อย่าตัดสิน Performance จากชื่อ Script
㉞ SQL ทำให้ Profiler เห็น Hitch ได้ไหม?
ได้
Cfx.re ยก Slow SQL Queries เป็นหนึ่งในสาเหตุ Hitch Warning
ถ้า Resource ที่ Spike เกี่ยวข้องกับ
Inventory
Garage
Phone
Housing
Banking
ควรตรวจ Query ต่อทันที
㉟ Slow Query ต้องดูอะไร?
ตรวจ
Query Time
Frequency
Rows
Index
Result Size
Query หนึ่งครั้ง 100 ms ต่างจาก Query 100 ms ที่ถูกยิง 500 ครั้ง
㊱ Query ใน Player Loop ต้องระวังมาก
เช่น
200 Players
↓
Query 3 ครั้งต่อ Player
↓
600 Queries
ในรอบเดียว
อาจสร้าง Burst และ Hitch
㊲ Autosave เป็นจุดที่ควร Profile
Server RP มัก Save Player เป็นช่วง
ถ้าผู้เล่น 300 คน Save พร้อมกัน
Players
↓
SQL Updates
↓
Logs
↓
Callbacks
↓
Hitch
Capture Profiler ตอน Autosave จะช่วยพิสูจน์ได้
㊳ Payday ก็เช่นกัน
ถ้า Server กระตุกทุก 30 นาที
ให้ถามว่ามี Scheduled Job อะไรตรงเวลานั้น
เช่น
Payday
Save
Cleanup
Backup
Log Flush
Profiler ช่วงเวลานั้นสำคัญมาก
㊴ Event Spam หาได้อย่างไร?
ถ้า Resource ใช้ CPU สูงเพราะ Event Handler ถูกเรียกจำนวนมาก
ตรวจ Source ว่า Client ส่ง Event ถี่แค่ไหน
เช่น
TriggerServerEvent('updateState', data)
ทุก Frameจาก Player จำนวนมาก
Profiler อาจชี้ Handler ฝั่ง Server เป็น Hotspot
㊵ Network Payload ใหญ่ก็เพิ่ม Workload
ข้อมูลที่ต้อง
Serialize
Deserialize
Copy
Process
จำนวนมากสามารถเพิ่ม CPU
เช่นส่ง Inventory ทั้งหมดทุกครั้งที่ Item หนึ่งชิ้นเปลี่ยน
ควรพิจารณา Delta Update
㊶ JSON Encoding เป็น Hotspot ได้
ตัวอย่าง:
json.encode(hugeTable)
ใน Loop หรือ Log ทุก Event
Profiler อาจเผยให้เห็นว่า Resource เสียเวลาอยู่กับ Data Processing มากกว่าตัว Gameplay
㊷ Logging สามารถทำ Server ช้า
Resource บางตัวส่ง
Discord Webhook
Database Log
File Log
ทุก Action
ถ้า Player Count สูง Logging Pipeline อาจกลายเป็น Bottleneck
㊸ Error Spam ต้องดูใน Console ด้วย
Profiler เป็นเครื่องมือสำคัญ แต่ Console ยังจำเป็น
Resource ที่ Error หลายพันครั้งสามารถใช้เวลาไปกับ
Exception Handling
String Formatting
Logging
แก้ Error ต้นเหตุก่อน
㊹ Profiler กับ txAdmin ใช้ร่วมกันอย่างไร?
txAdmin ช่วยบอกว่า
เมื่อไร Server มีปัญหา
Profiler ช่วยตอบว่า
อะไรทำให้เกิดปัญหา
Workflow:
txAdmin
↓
พบ CPU/Thread Spike
↓
Profiler
↓
หา Resource
มีประสิทธิภาพมากกว่าดูเครื่องมือใดเครื่องมือหนึ่งอย่างเดียว
㊺ ดู Player Count คู่กับ Profiler
ถ้า Resource ใช้
50 Players → 1 ms
100 Players → 2 ms
200 Players → 8 ms
400 Players → 30 ms
มีสัญญาณว่า Scaling อาจไม่เป็น Linear ที่ดี
ต้องตรวจ Code
㊻ CPU รวมต่ำแต่ Profiler ยังเจอ Hitch ได้ไหม?
ได้
เพราะ Hitch สามารถเกิดจาก Thread หนึ่งถูก Block ชั่วคราว
Total CPU ของเครื่องอาจยังต่ำ
นี่คือเหตุผลที่ดู Task Manager อย่างเดียวไม่พอ
㊼ RAM สูงใช้ Profiler ได้ไหม?
Profiler ช่วยวิเคราะห์ Execution ได้ แต่ถ้าเป็น Memory Growth ควรใช้ Metrics/Monitoring เพิ่ม
โดยเฉพาะ Enhanced ที่มี
Lua Memory
JavaScript Memory
Entity Counts
ช่วยเจาะปัญหา Memory ได้ดีกว่า
㊽ Enhanced มี Metrics อะไรเพิ่ม?
Cfx.re ระบุว่ามี Prometheus-compatible Metrics มากกว่า 80 รายการ
ตัวอย่าง:
UDP Packets
Peer Counts
OneSync Entity Count
Sync Trees
State Bags
Routing Buckets
NetID Usage
Lua Memory
JavaScript Memory
Event Loop Queue
HTTP
Thread Tick Times
ช่วยประกอบการอ่าน Profiler
㊾ svMain, svNetwork และ svSync คืออะไร?
Enhanced ยังคงมี Tick-time Metrics สำหรับ Thread หลัก เช่น
svMainsvNetworksvSync
ใช้ช่วยระบุว่า Layer ใดมี Latency สูง
จากนั้นจึงใช้ Profiler/Resource Analysis เจาะต่อ
㊿ svMain สูงต้องโทษ Lua ไหม?
ไม่ควรฟันธง
มันเป็นเบาะแสว่า Main Server Workload สูง
ต้องใช้ Profilerดูว่า Script/Event ใดกำลังทำงาน
JavaScript หรือ C# Resource ก็สามารถสร้าง Workload ได้
51. svSync สูงควรตรวจอะไร?
ตรวจร่วมกับ
Player Count
Entity Count
OneSync
State Bags
NetIDs
โดยเฉพาะถ้า Server มี Networked Entity จำนวนมาก
52. Client Profiler ใช้หา FPS Drop อย่างไร?
ถ้า Resmon พบ Resource ต้องสงสัย
ให้ Capture ขณะที่ FPS Drop
แล้วหา
CPU Time Spike
Resource Tick
Client Thread
File/Line
หลักการเหมือนฝั่ง Server
53. ตัวอย่าง Phone Resource
สมมติ:
ปิด Phone → 120 FPS
เปิด Phone → 65 FPS
เริ่ม Profiler ก่อนเปิด Phone
จากนั้น
เปิด Phone
↓
เปิด Messages
↓
Scroll
↓
ปิด
แล้วดู Timeline ว่า Spike มาจาก Client Script หรือ Resource อื่น
54. NUI หนัก Profiler เห็นทั้งหมดไหม?
Profiler ช่วยฝั่ง Resource แต่ NUI เป็น Browser Environment เพิ่มอีก Layer
ถ้าสงสัย UI ควรใช้
nui_devtools
ร่วมด้วย
เพื่อตรวจ DOM, JavaScript และ Rendering
55. FPS ต่ำแต่ Profiler Script ปกติทำอย่างไร?
ตรวจต่อที่
GPU
Vehicles
MLO
Textures
Streaming
NUI
Profiler ไม่ได้แทน GPU/Asset Analysis ทั้งหมด
56. รถ High-poly อาจไม่โผล่เป็น Script Hotspot
ถูกต้อง
รถหนักสามารถทำ GPU/VRAM Load สูง
แม้ Client Resource Script ใช้ CPU ต่ำ
จึงต้องแยก
Script Performance
ออกจาก
Asset Rendering Performance
57. Profiler ใช้พิสูจน์ Paid Script ได้ไหม?
ได้
ถ้าไม่มี Source อย่างน้อยสามารถเก็บ
Resource Name
CPU Time
Spike
Reproduction Steps
ส่งให้ผู้พัฒนา
มีประโยชน์กว่าบอกเพียงว่า Script “รู้สึกหนัก”
58. Resource Restart Test ใช้ร่วมกับ Profilerได้
บน Staging:
Profile → Resource X สูง
↓
Stop Resource X
↓
Reproduce
↓
ปัญหาหาย
↓
Start X
↓
Reproduce
↓
ปัญหากลับ
เป็นหลักฐานที่แข็งแรงขึ้น
59. อย่าปิด Core Resource สุ่มบน Production
เช่น
Framework
Inventory
Database
Character
อาจกระทบข้อมูล
ควรทำ Isolation บน Test/Staging Server
60. Binary Isolation ใช้เมื่อ Profiler ยังไม่ชัด
ถ้ามี Custom Resources จำนวนมาก
ปิดครึ่งหนึ่งบน Test Server
Reproduce
เลือกกลุ่มที่ยังเกิดปัญหา
แบ่งครึ่งอีก
ทำซ้ำ
แล้วใช้ Profilerเจาะกลุ่มที่เหลือ
61. ต้อง Profile หลังแก้หรือไม่?
ต้อง
Optimization ที่ไม่มี Measurement หลังแก้ยังไม่ถือว่าพิสูจน์
เปรียบเทียบ
ก่อน
Resource Tick = 20 ms
หลัง
Resource Tick = 2 ms
ภายใต้ Workload เดียวกัน
62. อย่าเปรียบเทียบคนละ Player Count
ตัวอย่างที่ไม่ดี:
ก่อนแก้ → 200 Players
หลังแก้ → 15 Players
แล้วบอก Resource เร็วขึ้น
ต้อง Test ใกล้เคียงกัน
63. ทำ Performance Regression Test
บันทึก
Resource Version
Player Count
Scenario
CPU
Tick Time
Hitch Count
ก่อน/หลัง Update
ช่วยป้องกัน Resource Version ใหม่ทำ Server ช้าลงโดยไม่รู้ตัว
64. Resource ใหม่ทุกตัวควร Profile ไหม?
Resource ใหญ่หรือ Critical ควรตรวจอย่างน้อยใน Staging
เช่น
Inventory
Phone
Housing
Police
Garage
Vehicle System
Anti-cheat
โดยเฉพาะก่อน Server เปิดตัวหรือ Update ใหญ่
65. Profile ตอน Idle และ Active
ต้องทดสอบสองแบบ
Idle
Resourceไม่ได้ถูกใช้งาน
Active
Featureกำลังทำงานจริง
Resource ที่ Idle หนักเป็นสัญญาณหนึ่ง ส่วน Resource ที่หนักเฉพาะ Feature อาจ Optimizeเฉพาะ Path นั้นได้
66. Profile ตอน Player อยู่รวมกัน
สำหรับ Resource ที่ Scale กับ Player/Entity
ทดสอบ
โรงพยาบาล
สถานีตำรวจ
Event
Garage
ที่ผู้เล่นรวมจำนวนมาก
ปัญหาอาจไม่เกิดเมื่ออยู่คนเดียว
67. Soak Test + Profiler มีประโยชน์ไหม?
มี
ถ้า Server ช้าหลังเปิด 10 ชั่วโมง
ทำ Long-running Test แล้ว Capture เมื่อ Performance เริ่มตก
ช่วยหา Resource ที่ Workload เพิ่มตามเวลา
เช่น
Entity Leak
Timer
Queue
Cache
68. Profiler ไม่ได้แก้ Code ให้เอง
Profiler บอกว่า
ตรงไหนช้า
แต่ Developer ต้องแก้
ทำไมมันช้า
เช่น
เปลี่ยน Algorithm
ลด Loop
Cache
เพิ่ม Index
ลด Payload
Cleanup Entity
เครื่องมือเป็น Diagnostic ไม่ใช่ Auto-optimizer
69. อย่าแก้ทุกอย่างให้ 0 ms
เป้าหมายไม่ใช่ให้ Resource ทุกตัวแสดงศูนย์
Resource ที่ทำงานจริงย่อมใช้ CPU
เป้าหมายคือ
ไม่มีงานเกินจำเป็น
ไม่มี Spike รุนแรง
ไม่มี Hitch ต่อเนื่อง
Player Experience ดี
70. Optimization ที่มากเกินไปก็ทำ Code แย่ได้
อย่าเปลี่ยน Code อ่านง่ายให้ซับซ้อนมากเพื่อประหยัด Microseconds ที่ไม่ส่งผลจริง
ใช้ Profilerบอกว่าอะไรคือ Hot Path ก่อน
Optimize จุดที่มีผลจริง
71. หลัก 80/20 ใช้ได้ดี
ในหลาย Server ปัญหา Performance ส่วนใหญ่เกิดจาก Resource เพียงไม่กี่ตัว
เช่น
Resource 200 ตัว
↓
5 ตัวสร้าง Load ส่วนใหญ่
Profiler ช่วยหา 5 ตัวนั้นแทนการ Rewrite 200 ตัว
72. Workflow หา Server ช้าด้วย Profiler
ขั้นที่ 1
ดู txAdmin/Console
ขั้นที่ 2
จดเวลาที่ Lag
ขั้นที่ 3
เริ่ม Profiler
ขั้นที่ 4
Reproduce ปัญหา
ขั้นที่ 5
ดู CPU Time Spike
ขั้นที่ 6
Zoom Resource Tick
ขั้นที่ 7
หา Resource
ขั้นที่ 8
หา File/Function
ขั้นที่ 9
ตรวจ Loop/SQL/Event/Entity
ขั้นที่ 10
แก้ Code
ขั้นที่ 11
Profile อีกครั้ง
ขั้นที่ 12
Load Test
73. Checklist เมื่อ Profiler เจอ Resource หนัก
ตรวจ Resource นั้นว่ามี
Wait(0)มากเกินไปหรือไม่GetPlayers()Loop ถี่หรือไม่Entity Scan หรือไม่
Nested Loop หรือไม่
Database Query ใน Loop หรือไม่
JSON ใหญ่หรือไม่
Network Event Spam หรือไม่
Logging/Webhook หนักหรือไม่
Cache โตหรือไม่
Cleanup ถูกหรือไม่
74. Checklist ฝั่ง Client
หาก FPS Drop ให้ตรวจ
Client Loop
Distance Check
Draw Calls จาก Script
Entity Scan
NUI Messages
JSON Processing
Resource Memory
Asset Load
เริ่ม Resmon ก่อน แล้ว Profilerตาม
75. Checklist ฝั่ง Server
หาก Server Lag ให้ตรวจ
Server Thread
Hitch Warning
Player Loops
SQL
Event Spam
Entity Lifecycle
Logging
Scheduled Tasks
ใช้ txAdmin/Metrics ประกอบ
76. Enhanced Developer Mode ต้องรู้ไหม?
สำหรับ Enhanced Client Development Tools ทาง Cfx.re เปลี่ยนระบบ Developer Mode ใหม่
สามารถเปิดฝั่ง Serverด้วย
sv_devmode
หรือให้ Developer Mode เป็นราย Player ผ่าน Connection Handover
การเปิด Developer Mode ทั้ง Server จะจำกัด Server ไว้ที่ 8 Slots จึงไม่ควรเปิดบน Production ทั่วไป
77. Legacy Dev Mode กับ Enhanced ต่างกัน
คู่มือ Legacy บางหน้าอาจกล่าวถึง
+set moo 31337
แต่ Enhanced-specific Documentation ระบุว่า Legacy Mechanism นี้ถูกถอดออก
ดังนั้นต้องใช้ Workflow ที่ตรงกับ Client Generation
78. สิ่งที่ไม่ควรทำกับ FiveM Profiler
หลีกเลี่ยง
Profile ตอน Server ว่างทั้งที่ปัญหาเกิดตอน Peak
ดู CPU Average อย่างเดียว
Restart ก่อน Capture ทุกครั้ง
เจอ Resource แล้วลบทันที
โทษ Framework จากชื่อ
ไม่ตรวจ SQL
ไม่ดู Entity Count
ไม่ Reproduce หลังแก้
เปรียบเทียบคนละ Workload
คิดว่า Profiler Optimize ให้อัตโนมัติ
Profiler มีค่ามากที่สุดเมื่อใช้ร่วมกับวิธีทดสอบที่ควบคุมได้
79. คำถามที่พบบ่อย
FiveM Profiler คืออะไร?
เครื่องมือสำหรับวิเคราะห์ว่า Resource, Thread หรือ Code ใดใช้เวลาประมวลผลมากและทำให้ Server Hitch หรือ Client FPS ตก
ใช้ฝั่ง Server ได้ไหม?
ได้ และเหมาะกับการหา Server Hitch
ใช้ฝั่ง Client ได้ไหม?
ได้ เหมาะกับ FPS Drop และ Micro-stutter
เริ่ม Profiler อย่างไร?
ใน Legacy Workflow สามารถเริ่มด้วย
profiler record 500
ตรวจสถานะอย่างไร?
profiler status
FiveM Enhanced ใช้ Profiler อะไร?
ใช้ Perfetto เป็น Backend ใหม่
Enhanced บันทึกอย่างไร?
Cfx.re ระบุ Workflow
profiler record <duration>
profiler save <filename>.json
Profiler หาได้ถึงบรรทัด Code ไหม?
เอกสาร Cfx.re แสดงว่าการวิเคราะห์สามารถลงไปถึง Resource, File และ Line Range ของ Thread ที่ทำงานหนักได้
Resmon กับ Profiler ใช้อันไหนก่อน?
สำหรับ Client เริ่มจาก Resmon เพื่อหา Resource แล้วใช้ Profilerเจาะลึก
Server CPU สูงควรใช้อะไร?
ใช้ Server Profiler ร่วมกับ txAdmin และ Metrics
80. สรุป FiveM Profiler คืออะไร? วิธีหา Script ทำ Server ช้า
FiveM Profiler คือเครื่องมือที่เปลี่ยนการแก้ Server Lag จากการเดาให้เป็นการวิเคราะห์จากข้อมูลจริง
แทนที่จะถามว่า
“Script ไหนกิน CPU?”
Profiler ช่วยไล่ได้ว่า
Lag / Hitch
↓
CPU Time Spike
↓
Resource Tick
↓
Resource
↓
Thread
↓
File / Function
↓
Root Cause
FiveM Profiler ใช้ได้ทั้ง Server และ Client
ฝั่ง Server เหมาะกับ
Thread Hitch
CPU Spike
Slow Resource
SQL-related Delay
Scaling Problem
ฝั่ง Client เหมาะกับ
FPS Drop
Micro-stutter
Heavy Client Script
สำหรับ Legacy Workflow เอกสารทั่วไปมีคำสั่งอย่าง
profiler record
profiler status
profiler view
profiler saveJSON
ขณะที่ FiveM Enhanced เปลี่ยน Backend เป็น Perfetto และ Cfx.re ระบุ Workflow ใหม่ด้วย
profiler record <duration>
profiler save <filename>.json
พร้อมระบบ Metrics มากกว่า 80 รายการที่สามารถนำมาดูร่วมกับ Profiler เพื่อแยก Main Thread, Network, Sync, Entities, State Bags และ Runtime Memory ได้ละเอียดขึ้น
สิ่งที่ควรค้นหาหลังเจอ Resource ตัวปัญหาคือ
Heavy Loop
Player Loop
O(n²)
Entity Scan
Slow SQL
Autosave Burst
Event Spam
Large JSON/Payload
Logging/Webhook
Entity Leak
แนวทางที่ comsiam แนะนำคือ
วัดอาการ
↓
Capture ตอนปัญหาเกิด
↓
หา Spike
↓
หา Resource
↓
หา Function
↓
แก้ Root Cause
↓
Reproduce
↓
Profile Again
↓
Load Test
↓
Production
จำง่าย ๆ:
ไม่รู้ Resource ไหนหนัก → Profiler
Client FPS ต่ำ → Resmon แล้ว Profiler
Server Hitch → Server Profiler
CPU Average ปกติแต่กระตุก → หา Spike
Lag ตอนผู้เล่นเยอะ → Profile ตอนผู้เล่นเยอะ
Lag เป็นเวลา → Profile Scheduled Task
เจอ Resource แล้ว → อย่าเพิ่งลบ หา Code ตัวจริง
แก้แล้ว → ต้อง Profile ซ้ำ
FiveM Server ที่ Optimize ดีจึงไม่ได้เกิดจากการซื้อ CPU แรงที่สุดหรือปิด Resource ให้เหลือน้อยที่สุด แต่เกิดจากการรู้ด้วยข้อมูลจริงว่า Server ใช้เวลาไปกับอะไร และลดเฉพาะงานที่ไม่จำเป็นหรือทำงานไม่มีประสิทธิภาพ
Comments
Post a Comment