Skip to content
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:separation of fast and slow commands #2162

Conversation

dingxiaoshuai123
Copy link
Collaborator

@dingxiaoshuai123 dingxiaoshuai123 commented Nov 24, 2023

issue : #2085
issue : #2174

1 separation of fast and slow commands
2 modify the codis proxy & pika
3 add slow command queue and slow command thread pool in pika

@dingxiaoshuai123 dingxiaoshuai123 changed the title separation of fast and slow commands feat : separation of fast and slow commands Nov 24, 2023
@dingxiaoshuai123 dingxiaoshuai123 changed the title feat : separation of fast and slow commands feat:separation of fast and slow commands Nov 24, 2023
@github-actions github-actions bot added the ✏️ Feature New feature or request label Nov 24, 2023
@@ -491,18 +507,23 @@ func (s *sharedBackendConn) BackendConn(database int32, seed uint, must bool) *B
type sharedBackendConnPool struct {
config *Config
parallel int
quick int
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

补充注释

backend_primary_parallel = 1
backend_replica_parallel = 1
backend_primary_parallel = 2
backend_primary_quick = 1
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

补充注释

opTable[r.Name] = r
}

if cmdlist == "" {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

调用len判断字符串为空

conf/pika.conf Outdated
@@ -23,6 +23,13 @@ thread-num : 1
# are dedicated to handling user requests.
thread-pool-size : 12

# Size of the low level thread pool, The threads within this pool
# are dedicated to handling slow user requests.
low-level-thread-pool-size : 4
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

改为slowcmdthreadpool

include/pika_conf.h Outdated Show resolved Hide resolved
include/pika_conf.h Outdated Show resolved Hide resolved
} else if (set_item == "slow-cmd-list") {
g_pika_conf->SetSlowCmd(value);
ret = "+OK\r\n";
}else if (set_item == "max-cache-files") {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

空格

@AlexStocks
Copy link
Collaborator

todo:
1 seperate the read and write command;
2 elastic the slow command thread pool

@@ -6,8 +6,10 @@ package proxy
import (
"bytes"
"hash/crc32"
"pika/codis/v2/pkg/utils/log"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

重置下位置

include/pika_conf.h Outdated Show resolved Hide resolved
src/pika_server.cc Outdated Show resolved Hide resolved
src/pika_server.cc Show resolved Hide resolved
src/pika_server.cc Outdated Show resolved Hide resolved
codis/pkg/proxy/backend.go Show resolved Hide resolved
include/pika_conf.h Outdated Show resolved Hide resolved
@@ -50,6 +51,8 @@ int string2int(const char* s, size_t slen, unsigned long* lval);
int d2string(char* buf, size_t len, double value);
int string2d(const char* s, size_t slen, double* dval);
std::vector<std::string>& StringSplit(const std::string& s, char delim, std::vector<std::string>& elems);
void StringSplit2Set(const std::string&s, char delim, std::unordered_set<std::string>& elems);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

elems这个换成 * 把,一般需要修改的值的用引用+const修饰,需要修改值的用 *

src/pstd/include/pstd_string.h Outdated Show resolved Hide resolved
@@ -50,6 +51,8 @@ int string2int(const char* s, size_t slen, unsigned long* lval);
int d2string(char* buf, size_t len, double value);
int string2d(const char* s, size_t slen, double* dval);
std::vector<std::string>& StringSplit(const std::string& s, char delim, std::vector<std::string>& elems);
void StringSplit2Set(const std::string&s, char delim, std::unordered_set<std::string>& elems);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个delim也尽量不要值传递把,看下用指针还是引用

src/pstd/include/pstd_string.h Show resolved Hide resolved
codis/config/proxy.toml Outdated Show resolved Hide resolved
codis/config/proxy.toml Outdated Show resolved Hide resolved
Mixficsol
Mixficsol previously approved these changes Dec 4, 2023
codis/pkg/proxy/config.go Show resolved Hide resolved
// Print the current low level queue size if it exceeds QUEUE_SIZE_THRESHOLD_PERCENTAGE/100 of the maximum queue size.
size_t low_level_queue_cur_size = LowLevelThreadPoolCurQueueSize();
size_t low_level_queue_max_size = LowLevelThreadPoolMaxQueueSize();
size_t low_level_queue_thread_hold = (low_level_queue_max_size / 100) * QUEUE_SIZE_THRESHOLD_PERCENTAGE;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

变量名是想写low_level_queue_thresh_hold?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里的名字都要改成slow_cmd相关,下次提交的时候改

src/pika_client_conn.cc Show resolved Hide resolved
if quick := s.owner.quick; quick > 0 {
if isQuick {
i = seed % uint(quick)
if bc := parallel[i]; bc.IsConnected() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个地方,原来是在一个循环里,如果一个bc无效会继续找下一个,这里是不是也该加一下。

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里传入的seed是用key做的hash,为了保证pipeline中相同key的有序,所以没有找下一个连接。之前不知道为什么是进行了遍历,所以新添加的代码没有进行循环找conn

@@ -55,10 +61,14 @@ const (
FlagMasterOnly
FlagMayWrite
FlagNotAllow
FlagQuick
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quick和Slow不是互斥的吗?需要两个都定义吗?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

理论上只需要FlagSlow即可,但是为了简化一些逻辑就加了个FlagQuick,这样在一些打印快慢列表的函数中逻辑更清晰点,不需要的话删除也行

@AlexStocks
Copy link
Collaborator

继续改进下,解决下文件冲突

@dingxiaoshuai123 dingxiaoshuai123 force-pushed the split_fast_slow_cmd_codis branch 4 times, most recently from 62d84fa to 8df24fc Compare December 21, 2023 07:30
@github-actions github-actions bot added the 📒 Documentation Improvements or additions to documentation label Dec 21, 2023
@dingxiaoshuai123 dingxiaoshuai123 force-pushed the split_fast_slow_cmd_codis branch 4 times, most recently from bb78f5f to 719192d Compare December 21, 2023 08:25
return bc
}
}
}
}
return s.backend.bc.BackendConn(database, seed, true)
// fix:https://github.com/OpenAtomFoundation/pika/issues/2174
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这行去掉吧 可以放在comment中

flagString := "FlagQuick"
if flag&FlagSlow != 0 {
reverseFlag = FlagQuick
flagString = "FlagSlow"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

为啥FlagQuick 没有引号 FlagSlow有引号 这是有什么特殊的考虑吗

@AlexStocks AlexStocks merged commit c1917c7 into OpenAtomFoundation:unstable Jan 18, 2024
13 checks passed
bigdaronlee163 pushed a commit to bigdaronlee163/pika that referenced this pull request Jun 8, 2024
* split fast and slow cmd in codis

* separation of fast and slow commands

* Resolve formatting issues.

* use the unordered_set instead of unordered_map

* fix:disorderly execution of the same key when using pipeline

* update go 1.18 to go 1.21

* change proxy.go & mapper.go
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.5.3 📒 Documentation Improvements or additions to documentation enhancement ✏️ Feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants