0Pricing
Redis Caching & Messaging (Pub/Sub, Streams) · บทเรียน

การวิเคราะห์บันทึกการทำงานช้า

ใช้บันทึกการทำงานช้าของ Redis เพื่อค้นหาคำสั่งที่บล็อกเซิร์ฟเวอร์ ตีความรายการ และปรับค่าเกณฑ์ที่ใช้บันทึกรายการเหล่านั้น

การวิเคราะห์บันทึกการทำงานช้า เป็นบทเรียน Redis Caching & Messaging (Pub/Sub, Streams) ฟรีบน CoddyKit นี่คือบทเรียนที่ 4 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน Redis Caching & Messaging (Pub/Sub, Streams) และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส Redis Caching & Messaging (Pub/Sub, Streams) มีบทเรียนทั้งหมด 4 บทเรียน

บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ

Redis Is Single-Threaded

Command execution in Redis is effectively single-threaded. One slow command blocks every other client. The slow log records commands whose execution time exceeds a threshold, so you can hunt down these blockers.

What It Measures

The slow log times only command execution, not network or I/O wait. So a logged entry means Redis itself spent that long, usually on an expensive operation over many elements.

Configuring the Threshold

slowlog-log-slower-than sets the threshold in microseconds. A value of 10000 logs commands slower than 10ms. Set it to 0 to log everything (for debugging) or -1 to disable.

CONFIG SET slowlog-log-slower-than 10000

Limiting Log Size

slowlog-max-len caps how many entries are retained; older ones are evicted. This keeps memory bounded.

CONFIG SET slowlog-max-len 128

Reading the Log

SLOWLOG GET returns recent entries; pass a count to limit them. Each entry has an ID, timestamp, microsecond duration, the command and arguments, and the client address.

SLOWLOG GET 10

Interpreting an Entry

Look at the command and its duration. A KEYS * or a large SMEMBERS over a million-element set will show big durations, pinpointing the culprit and the calling client.

# 1) id 14
# 2) timestamp 1716900000
# 3) microseconds 23000
# 4) ["KEYS", "*"]

Length and Reset

SLOWLOG LEN gives the current entry count, and SLOWLOG RESET clears the log, handy before reproducing an issue.

SLOWLOG LEN
SLOWLOG RESET

Common Offenders

Frequent slow-log culprits:

  • KEYS on large keyspaces (use SCAN)
  • Big SMEMBERS/HGETALL/LRANGE 0 -1
  • Unbounded SORT
  • Large DEL (use UNLINK)
SCAN 0 MATCH user:* COUNT 100
UNLINK biglist

From Detection to Fix

Once the slow log names a command, fix it: paginate with cursors, model data to avoid huge single keys, or move heavy work off the hot path. Re-check the log to confirm the durations drop.

Continuous Monitoring

Sample the slow log periodically from a monitoring job and alert when slow commands appear, so you catch regressions before users feel them.

redis-cli SLOWLOG GET 5

Threshold Tuning

Start with a moderate threshold (e.g. 10ms) in production. Lower it temporarily when investigating, then restore it, because logging everything adds a tiny per-command cost.

Quick Check

Test your understanding of the slow log.

Recap

You learned to use the slow log: configure slowlog-log-slower-than and slowlog-max-len, read entries with SLOWLOG GET, interpret durations, and fix common offenders like KEYS and huge single-key reads. Monitor it continuously to catch performance regressions early.

คำถามที่พบบ่อย

บทเรียน “การวิเคราะห์บันทึกการทำงานช้า” ฟรีหรือไม่

ใช่ — ข้อความเต็มของ “การวิเคราะห์บันทึกการทำงานช้า” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส Redis Caching & Messaging (Pub/Sub, Streams) ให้อัปเกรดเป็น CoddyKit PRO คอร์ส Redis Caching & Messaging (Pub/Sub, Streams) มีบทเรียนทั้งหมด 4 บทเรียน

คุณจะเรียนรู้อะไรในบทเรียน “การวิเคราะห์บันทึกการทำงานช้า”

ใช้บันทึกการทำงานช้าของ Redis เพื่อค้นหาคำสั่งที่บล็อกเซิร์ฟเวอร์ ตีความรายการ และปรับค่าเกณฑ์ที่ใช้บันทึกรายการเหล่านั้น คุณปฏิบัติ Redis Caching & Messaging (Pub/Sub, Streams) ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน

คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน Redis Caching & Messaging (Pub/Sub, Streams) หรือไม่

ไม่จำเป็นต้องมีประสบการณ์มาก่อน Redis Caching & Messaging (Pub/Sub, Streams) บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 4 จากทั้งหมด 4 บทเรียน

บทเรียน “การวิเคราะห์บันทึกการทำงานช้า” ใช้เวลานานแค่ไหน

บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย

ฉันเขียนและรันโค้ดในบทเรียน Redis Caching & Messaging (Pub/Sub, Streams) นี้ได้ไหม

ได้ บทเรียน Redis Caching & Messaging (Pub/Sub, Streams) ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ

บทเรียนทั้งหมดในหลักสูตรนี้

  1. เครื่องมือติดตาม Redis
  2. การวินิจฉัยปัญหาด้านประสิทธิภาพ
  3. การปรับแต่งและเพิ่มประสิทธิภาพ
  4. การวิเคราะห์บันทึกการทำงานช้า
← กลับไปที่ Redis Caching & Messaging (Pub/Sub, Streams)