mirror of
https://github.com/dragonflydb/dragonfly.git
synced 2025-05-11 02:15:45 +02:00
feat(server): track pipeline requests cache capacity (#776)
1. now pipeline_cache_capacity tracks how many bytes are allocated via free_req_pool_ cache. it's been shown now via "pipeline_cache_bytes" stat in "info memory" command. 2. a small refactoring of server_state code into server_state.cc 3. Reduce dependency of dfly_transaction on facade lib. Signed-off-by: Roman Gershman <roman@dragonflydb.io>
This commit is contained in:
parent
6e612e7545
commit
6f1e49120e
12 changed files with 178 additions and 162 deletions
|
@ -4,12 +4,23 @@
|
|||
|
||||
#include "server/server_state.h"
|
||||
|
||||
#include <mimalloc.h>
|
||||
|
||||
extern "C" {
|
||||
#include "redis/zmalloc.h"
|
||||
}
|
||||
|
||||
#include "base/flags.h"
|
||||
#include "base/logging.h"
|
||||
#include "server/conn_context.h"
|
||||
#include "facade/conn_context.h"
|
||||
|
||||
ABSL_FLAG(uint32_t, interpreter_per_thread, 10, "Lua interpreters per thread");
|
||||
|
||||
namespace dfly {
|
||||
|
||||
void MonitorsRepo::Add(ConnectionContext* connection) {
|
||||
thread_local ServerState ServerState::state_;
|
||||
|
||||
void MonitorsRepo::Add(facade::Connection* connection) {
|
||||
VLOG(1) << "register connection "
|
||||
<< " at address 0x" << std::hex << (const void*)connection << " for thread "
|
||||
<< util::ProactorBase::GetIndex();
|
||||
|
@ -17,25 +28,14 @@ void MonitorsRepo::Add(ConnectionContext* connection) {
|
|||
monitors_.push_back(connection);
|
||||
}
|
||||
|
||||
void MonitorsRepo::Send(const std::string& msg) {
|
||||
if (!monitors_.empty()) {
|
||||
VLOG(1) << "thread " << util::ProactorBase::GetIndex() << " sending monitor message '" << msg
|
||||
<< "' for " << monitors_.size();
|
||||
for (auto monitor_conn : monitors_) {
|
||||
monitor_conn->SendMonitorMsg(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MonitorsRepo::Remove(const ConnectionContext* conn) {
|
||||
void MonitorsRepo::Remove(const facade::Connection* conn) {
|
||||
auto it = std::find_if(monitors_.begin(), monitors_.end(),
|
||||
[&conn](const auto& val) { return val == conn; });
|
||||
if (it != monitors_.end()) {
|
||||
VLOG(1) << "removing connection 0x" << std::hex << (const void*)conn << " releasing token";
|
||||
VLOG(1) << "removing connection 0x" << std::hex << conn << " releasing token";
|
||||
monitors_.erase(it);
|
||||
} else {
|
||||
VLOG(1) << "no connection 0x" << std::hex << (const void*)conn
|
||||
<< " found in the registered list here";
|
||||
VLOG(1) << "no connection 0x" << std::hex << conn << " found in the registered list here";
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -48,4 +48,31 @@ void MonitorsRepo::NotifyChangeCount(bool added) {
|
|||
}
|
||||
}
|
||||
|
||||
ServerState::ServerState() : interpreter_mgr_{absl::GetFlag(FLAGS_interpreter_per_thread)} {
|
||||
CHECK(mi_heap_get_backing() == mi_heap_get_default());
|
||||
|
||||
mi_heap_t* tlh = mi_heap_new();
|
||||
init_zmalloc_threadlocal(tlh);
|
||||
data_heap_ = tlh;
|
||||
}
|
||||
|
||||
ServerState::~ServerState() {
|
||||
}
|
||||
|
||||
void ServerState::Init() {
|
||||
gstate_ = GlobalState::ACTIVE;
|
||||
}
|
||||
|
||||
void ServerState::Shutdown() {
|
||||
gstate_ = GlobalState::SHUTTING_DOWN;
|
||||
}
|
||||
|
||||
Interpreter* ServerState::BorrowInterpreter() {
|
||||
return interpreter_mgr_.Get();
|
||||
}
|
||||
|
||||
void ServerState::ReturnInterpreter(Interpreter* ir) {
|
||||
interpreter_mgr_.Return(ir);
|
||||
}
|
||||
|
||||
} // end of namespace dfly
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue