opt(server): Migrate connections which invoke Lua scripts to their target thread. (#2037)

This is enabled by default, but can be disabled via `--migrate_connections=false`.

Measuring with BullMQ benchmark I see a gain of almost 10% in
throughput. I haven't measured, but it's supposed to also reduce
latency.
This commit is contained in:
Shahar Mike 2023-10-19 22:31:07 +03:00 committed by GitHub
parent 395f65ddd2
commit bc0064e94d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 120 additions and 12 deletions

View file

@ -1606,6 +1606,7 @@ void Service::EvalInternal(CmdArgList args, const EvalArgs& eval_args, Interpret
// we can do it once during script insertion into script mgr.
auto& sinfo = cntx->conn_state.script_info;
sinfo = make_unique<ConnectionState::ScriptInfo>();
sinfo->keys.reserve(eval_args.keys.size());
optional<ShardId> sid;
for (size_t i = 0; i < eval_args.keys.size(); ++i) {
@ -1654,6 +1655,11 @@ void Service::EvalInternal(CmdArgList args, const EvalArgs& eval_args, Interpret
});
cntx->transaction = tx;
if (*sid != ServerState::tlocal()->thread_index()) {
VLOG(1) << "Migrating connection " << cntx->conn() << " from " << ProactorBase::GetIndex()
<< " to " << *sid;
cntx->conn()->RequestAsyncMigration(shard_set->pool()->at(*sid));
}
} else {
optional<bool> scheduled = StartMultiEval(cntx->db_index(), eval_args.keys, *params, cntx);
if (!scheduled) {