mirror of
https://github.com/dragonflydb/dragonfly.git
synced 2024-12-15 17:51:06 +00:00
Reuse vectors on a hot-path of parsing requests in dragonfly_connection.
This commit is contained in:
parent
cfaf173236
commit
5849d09f73
3 changed files with 12 additions and 9 deletions
2
helio
2
helio
|
@ -1 +1 @@
|
|||
Subproject commit 84c11521f7df58427b3a4e1706518babaff06bef
|
||||
Subproject commit b7755de9b28e0185d6aba2f2424b8e9c64ae5328
|
|
@ -383,8 +383,6 @@ void Connection::ConnectionFlow(FiberSocketBase* peer) {
|
|||
}
|
||||
|
||||
auto Connection::ParseRedis() -> ParserStatus {
|
||||
RespVec args;
|
||||
CmdArgVec arg_vec;
|
||||
uint32_t consumed = 0;
|
||||
|
||||
RedisParser::Result result = RedisParser::OK;
|
||||
|
@ -392,10 +390,10 @@ auto Connection::ParseRedis() -> ParserStatus {
|
|||
mi_heap_t* tlh = mi_heap_get_backing();
|
||||
|
||||
do {
|
||||
result = redis_parser_->Parse(io_buf_.InputBuffer(), &consumed, &args);
|
||||
result = redis_parser_->Parse(io_buf_.InputBuffer(), &consumed, &parse_args_);
|
||||
|
||||
if (result == RedisParser::OK && !args.empty()) {
|
||||
RespExpr& first = args.front();
|
||||
if (result == RedisParser::OK && !parse_args_.empty()) {
|
||||
RespExpr& first = parse_args_.front();
|
||||
if (first.type == RespExpr::STRING) {
|
||||
DVLOG(2) << "Got Args with first token " << ToSV(first.GetBuf());
|
||||
}
|
||||
|
@ -406,12 +404,13 @@ auto Connection::ParseRedis() -> ParserStatus {
|
|||
// fiber enters the condition below and executes out of order.
|
||||
bool is_sync_dispatch = !cc_->async_dispatch && !cc_->force_dispatch;
|
||||
if (dispatch_q_.empty() && is_sync_dispatch && consumed >= io_buf_.InputLen()) {
|
||||
RespToArgList(args, &arg_vec);
|
||||
service_->DispatchCommand(CmdArgList{arg_vec.data(), arg_vec.size()}, cc_.get());
|
||||
RespToArgList(parse_args_, &cmd_vec_);
|
||||
CmdArgList cmd_list{cmd_vec_.data(), cmd_vec_.size()};
|
||||
service_->DispatchCommand(cmd_list, cc_.get());
|
||||
last_interaction_ = time(nullptr);
|
||||
} else {
|
||||
// Dispatch via queue to speedup input reading.
|
||||
Request* req = FromArgs(std::move(args), tlh);
|
||||
Request* req = FromArgs(std::move(parse_args_), tlh);
|
||||
|
||||
dispatch_q_.push_back(req);
|
||||
if (dispatch_q_.size() == 1) {
|
||||
|
|
|
@ -102,11 +102,15 @@ class Connection : public util::Connection {
|
|||
|
||||
struct Request;
|
||||
|
||||
// args are passed deliberately by value - to pass the ownership.
|
||||
static Request* FromArgs(RespVec args, mi_heap_t* heap);
|
||||
|
||||
std::deque<Request*> dispatch_q_; // coordinated via evc_.
|
||||
util::fibers_ext::EventCount evc_;
|
||||
|
||||
RespVec parse_args_;
|
||||
CmdArgVec cmd_vec_;
|
||||
|
||||
unsigned parser_error_ = 0;
|
||||
uint32_t id_;
|
||||
|
||||
|
|
Loading…
Reference in a new issue