Files
scylladb/service/cache_hitrate_calculator.hh
Avi Kivity f3eade2f62 treewide: relicense to ScyllaDB-Source-Available-1.0
Drop the AGPL license in favor of a source-available license.
See the blog post [1] for details.

[1] https://www.scylladb.com/2024/12/18/why-were-moving-to-a-source-available-license/
2024-12-18 17:45:13 +02:00

55 lines
1.4 KiB
C++

/*
* Copyright (C) 2016-present ScyllaDB
*/
/*
* SPDX-License-Identifier: LicenseRef-ScyllaDB-Source-Available-1.0
*/
#pragma once
#include "replica/database_fwd.hh"
#include "schema/schema_fwd.hh"
#include <seastar/core/timer.hh>
#include <seastar/core/sharded.hh>
using namespace seastar;
namespace gms { class gossiper; }
namespace service {
class cache_hitrate_calculator : public seastar::async_sharded_service<cache_hitrate_calculator>, public seastar::peering_sharded_service<cache_hitrate_calculator> {
struct stat {
float h = 0;
float m = 0;
stat& operator+=(stat& o) {
h += o.h;
m += o.m;
return *this;
}
};
seastar::sharded<replica::database>& _db;
gms::gossiper& _gossiper;
timer<lowres_clock> _timer;
bool _stopped = false;
float _diff = 0;
std::unordered_map<table_id, stat> _rates;
size_t _slen = 0;
std::string _gstate;
uint64_t _published_nr = 0;
lowres_clock::time_point _published_time;
future<> _done = make_ready_future();
future<lowres_clock::duration> recalculate_hitrates();
void recalculate_timer();
public:
cache_hitrate_calculator(seastar::sharded<replica::database>& db, gms::gossiper& g);
void run_on(size_t master, lowres_clock::duration d = std::chrono::milliseconds(2000));
future<> stop();
};
}