-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: use RTC(Run-to-completion) model to speed up cache read #2837
Conversation
…#2629) * (Demo) Do read cmd before task queue. && add workflow_dispatch for manual action * Check authed and write lock ,fix go test error in MacOS and cache mode judge * fix some ut error by commands filter and return logic * rollback some flag,but add kCmdReadBeforeQueuefor get mget hget hget hgetall,hmget * fix mem error in macos * move mget and hmget;add before_queue_time metrics * fix cost to copy cmd_table by remove c_ptr
WalkthroughThe recent changes enhance the functionality of the Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant PikaClientConn
participant Cache
Client->>PikaClientConn: Send Command (Get)
PikaClientConn->>PikaClientConn: IsInterceptedByRTC()
alt Intercepted
PikaClientConn->>Cache: ReadCmdInCache()
Cache-->>PikaClientConn: Return Cached Data
else Not Intercepted
PikaClientConn->>PikaClientConn: Process Command Normally
end
PikaClientConn-->>Client: Return Result
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (4)
- include/pika_client_conn.h (3 hunks)
- include/pika_command.h (4 hunks)
- src/pika_client_conn.cc (5 hunks)
- src/pika_command.cc (5 hunks)
Additional comments not posted (28)
include/pika_client_conn.h (4)
22-22
: LGTM!The addition of
before_queue_ts_
enhances the granularity of time measurement.
41-43
: Ensure the logic forbefore_queue_time()
is correct.The method calculates the time difference between
before_queue_ts_
andenqueue_ts_
, contingent onprocess_done_ts_
exceedingdequeue_ts_
. This logic seems correct, but verify that it aligns with the intended behavior.
76-76
: LGTM!The addition of
IsInterceptedByRTC
improves command handling based on real-time control mechanisms.
80-80
: LGTM!The addition of
ReadCmdInCache
enhances the command processing capabilities by leveraging caching.src/pika_client_conn.cc (6)
241-241
: LGTM!The inclusion of
before_queue_time
in the slow log provides deeper insights into command processing timings.
260-269
: LGTM!The method correctly checks if the command should be intercepted based on the cache settings.
277-277
: Ensure the timestamp is correctly set.The method sets both
enqueue_ts_
andbefore_queue_ts_
to the current time. Verify that this is the intended behavior.
290-300
: LGTM!The logic correctly handles the interception of single commands and attempts to read from the cache.
337-380
: LGTM!The method performs necessary checks and updates command statistics upon successful cache reads.
290-300
: LGTM!The logic correctly handles the interception of single commands and attempts to read from the cache.
include/pika_command.h (2)
540-540
: LGTM!The method correctly checks if a command is intended to read from a cache.
584-584
: LGTM!The method enhances the command processing capabilities by leveraging caching.
src/pika_command.cc (16)
246-246
: LGTM! Formatting change improves consistency.The spacing around the bitwise OR operator enhances readability and maintains consistency.
395-395
: LGTM! Formatting change improves consistency.The spacing around the bitwise OR operator enhances readability and maintains consistency.
403-403
: LGTM! Formatting change improves consistency.The spacing around the bitwise OR operator enhances readability and maintains consistency.
739-739
: LGTM! Formatting change improves consistency.The spacing around the bitwise OR operator enhances readability and maintains consistency.
743-743
: LGTM! Formatting change improves consistency.The spacing around the bitwise OR operator enhances readability and maintains consistency.
747-747
: LGTM! Formatting change improves consistency.The spacing around the bitwise OR operator enhances readability and maintains consistency.
751-751
: LGTM! Formatting change improves consistency.The spacing around the bitwise OR operator enhances readability and maintains consistency.
755-755
: LGTM! Formatting change improves consistency.The spacing around the bitwise OR operator enhances readability and maintains consistency.
759-759
: LGTM! Formatting change improves consistency.The spacing around the bitwise OR operator enhances readability and maintains consistency.
763-763
: LGTM! Formatting change improves consistency.The spacing around the bitwise OR operator enhances readability and maintains consistency.
769-769
: LGTM! Formatting change improves consistency.The spacing around the bitwise OR operator enhances readability and maintains consistency.
773-773
: LGTM! Formatting change improves consistency.The spacing around the bitwise OR operator enhances readability and maintains consistency.
776-776
: LGTM! Formatting change improves consistency.The spacing around the bitwise OR operator enhances readability and maintains consistency.
779-779
: LGTM! Formatting change improves consistency.The spacing around the bitwise OR operator enhances readability and maintains consistency.
782-782
: LGTM! Formatting change improves consistency.The spacing around the bitwise OR operator enhances readability and maintains consistency.
914-934
: LGTM! New methodDoReadCommandInCache
enhances command handling.The method correctly handles shared locks, checks cache status, and returns a boolean indicating cache read success.
Ensure that this method is appropriately integrated and used within the codebase.
Verification successful
The method
DoReadCommandInCache
is defined insrc/pika_command.cc
, declared ininclude/pika_command.h
, and used insrc/pika_client_conn.cc
. The usage seems appropriate, but let's verify the context in which it is used insrc/pika_client_conn.cc
to ensure it is correctly implemented.
The method
DoReadCommandInCache
is correctly integrated and used within the codebase.The method is appropriately called in
src/pika_client_conn.cc
after verifying the cache status, and its return value is used to determine further processing.
src/pika_client_conn.cc
: Correct usage ofDoReadCommandInCache
within the context of cache status check and read command processing.Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the usage of the new method `DoReadCommandInCache`. # Test: Search for the method usage. Expect: Occurrences of `DoReadCommandInCache`. rg --type cpp -A 5 $'DoReadCommandInCache'Length of output: 951
Script:
#!/bin/bash # Description: Verify the context of the usage of `DoReadCommandInCache` in `src/pika_client_conn.cc`. # Search for the surrounding lines of the usage of `DoReadCommandInCache` in `src/pika_client_conn.cc` to understand its context. rg --type cpp -A 10 -B 10 $'DoReadCommandInCache' src/pika_client_conn.ccLength of output: 862
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (1)
- src/pika_client_conn.cc (5 hunks)
Files skipped from review as they are similar to previous changes (1)
- src/pika_client_conn.cc
This comment was marked as resolved.
This comment was marked as resolved.
附1:详细测试结果 测试配置机器配置:
Pika配置:
测试分两阶段阶段一:填充数据统一用如下命令填充约1亿条key进入DB: 阶段二:多次执行如下Get压测命令每次Get数量为300W, 指定范围0-100W的key, Get行为会让key进入Pika内嵌的Redis Cache,随着命令执行次数的增加,缓存命中率也会逐步提升: 测试结果RTC(本PR)第1次执行Get压测命令:Summary:
Redis-Cache最大命中率(每秒): 小于48% 第2次执行Get压测命令:Summary:
Redis-Cache最大命中率(每秒): 小于72% 第3次执行Get压测命令:Summary:
Redis-Cache最大命中率(每秒): 小于77% 第4次执行Get压测命令:Summary:
Redis-Cache最大命中率(每秒): 小于78% 原版代码(无RTC)第1次执行Get压测命令:Summary:
Redis-Cache最大命中率(每秒): 小于69% 第2次执行Get压测命令:Summary:
Redis-Cache最大命中率(每秒): 小于86% 第3次执行Get压测命令:Summary:
Redis-Cache最大命中率(每秒): 小于87% 第4次执行Get压测命令:Summary:
Redis-Cache最大命中率(每秒): 小于88% |
Co-authored-by: chenbt <[email protected]>
…omFoundation#2837) * feat: Improve the RTC process of Read/Write model (OpenAtomFoundation#2629) * (Demo) Do read cmd before task queue. && add workflow_dispatch for manual action * Check authed and write lock, fix go test error in MacOS and cache mode judge * fix some ut error by commands filter and return logic * rollback some flag,but add kCmdReadBeforeQueuefor get mget hget hget hgetall,hmget * move mget and hmget;add before_queue_time metrics * fix cost to copy cmd_table by remove c_ptr --------- Co-authored-by: chenbt <[email protected]>
…omFoundation#2837) Co-authored-by: chenbt <[email protected]>
本PR的前置PR为:#2629 (authored by @chenbt-hz )
本PR实现的功能:对于读请求,直接在网络线程查内嵌的Redis 分片Cache,避开ThreadPool的task_queue竞争并省略线程中转的开销。
基本结论:在Pika内嵌Redis Cache缓存命中率较高的情况下,高并发情况下,Get QPS能提高到原本的1.5-2倍,且p99仅为原来的二分之一
性能收益的来源:
PS: 为了稳定性起见,目前只添加了对GET、HGET命令的支持,但理论上所有单key的读命令,且缓存开启了的数据结构,都可以走RTC路径(但是哪怕纯内存也比较慢的操作不能走rtc)。先等生产环境验证GET、HGET, 确认稳定后再后续让其他符合要求的读命令也走RTC路径。
详细测试报告请见下方附1