How a Priority‑Queue Scheduler Supercharged Client Performance
This article examines client‑side performance bottlenecks caused by message overload, analyzes low‑level Windows message loops and async task queues, proposes a flexible priority‑queue scheduling framework, details its architecture, evaluation metrics, and demonstrates significant UI responsiveness improvements while outlining future enhancements.
Performance Issue Diagnosis and Optimization History
Clients experienced process hangs when large numbers of group messages flooded the UI thread, causing unresponsive behavior during login and when many chat windows were open.
1.1 Current Problem Analysis and Solutions
Problem定位 : Analyze user environment, collect error logs, reproduce issues to pinpoint failing modules.
Problem解决 : Reduce message volume and pull frequency; convert synchronous tasks to asynchronous; migrate main‑thread tasks to logical threads.
1.2 Low‑Level Analysis and Solution Ideas
By returning to the client’s layered architecture and leveraging the Windows message‑driven mechanism, the message loop—alternating between Windows messages and async tasks—allows monitoring of every runtime detail, including per‑message and per‑task durations.
Monitoring revealed UI thread task peaks up to 3500 tasks, with some async tasks exceeding 100 ms (up to 600 ms), indicating long‑running UI tasks.
Adding observers to record execution times >50 ms enables reporting of UI message names, IDs, and async task function info for data‑driven optimization.
1.3 Overlooked Queue Time
Response time = queue time + execution time. Queue time, often ignored, was found significant, especially within the first three minutes after login.
Industry Scheduling Solutions Survey
Scheduling frameworks are categorized into three layers: distributed cluster scheduling, OS‑level process/thread scheduling, and application‑level coroutine scheduling. The design adopts ideas from:
BlinkOn’s multi‑priority queue design
Distributed scheduling resource‑balancing strategies
Customizable coroutine scheduling strategies
The chosen solution is a resource‑allocation and flexible‑policy scheduler built on a priority queue.
Technical Architecture
The scheduler consists of a multi‑threaded, multi‑level queue dispatch center that allocates thread resources based on priority strategies, ensuring high‑priority UI operations receive prompt attention.
The framework provides unified resource allocation, thread management, performance monitoring, and data analysis, eliminating the need for per‑business optimizations.
3.1 Task Scheduling Process
Task encapsulation: Business functions set attributes (type, thread‑safety, blocking) and are wrapped into executable tasks.
Task dispatch and execution: The scheduler places tasks into appropriate priority queues based on static (UI‑related) and dynamic (short‑job, message‑priority) strategies, selecting tasks via a decision tree.
System monitoring and data collection: Collect statistical metrics (execution time distribution) and anomaly metrics (queue length, queue time, run time) for reporting and analysis.
3.2 R&D Framework Support
Debugging: Output detailed task execution data and clean up abnormal threads.
Online operation: Adjust queue counts, strategy priorities, and task switches via configuration.
3.3 Optimization Results
After several iterations, 99.97% of messages/tasks completed within 50 ms, achieving a 49% reduction in UI task response time for batch message scenarios and significant queue‑time reductions.
Future Outlook
Introduce a workflow system to link related tasks from a user‑centric perspective.
Generalize the scheduler to reduce coupling with IM business logic.
Expand support to additional client platforms beyond Windows.
Explore intelligent scheduling by monitoring user habits to adjust task timing dynamically.
Tencent Qidian Tech Team
Official account of Tencent Qidian R&D team, dedicated to sharing and discussing technology for enterprise SaaS scenarios.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.