Files
scylladb/test/perf/logalloc.cc
Kefu Chai 6ead5a4696 treewide: move log.hh into utils/log.hh
the log.hh under the root of the tree was created keep the backward
compatibility when seastar was extracted into a separate library.
so log.hh should belong to `utils` directory, as it is based solely
on seastar, and can be used all subsystems.

in this change, we move log.hh into utils/log.hh to that it is more
modularized. and this also improves the readability, when one see
`#include "utils/log.hh"`, it is obvious that this source file
needs the logging system, instead of its own log facility -- please
note, we do have two other `log.hh` in the tree.

Signed-off-by: Kefu Chai <kefu.chai@scylladb.com>
2024-10-22 06:54:46 +03:00

79 lines
2.3 KiB
C++

/*
* Copyright (C) 2021 ScyllaDB
*/
/*
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
#include <seastar/core/distributed.hh>
#include <seastar/core/app-template.hh>
#include <seastar/core/sstring.hh>
#include <seastar/core/thread.hh>
#include <seastar/core/reactor.hh>
#include <fmt/core.h>
#include <random>
#include "utils/allocation_strategy.hh"
#include "utils/logalloc.hh"
#include "utils/log.hh"
#include "test/perf/perf.hh"
class piggie {
size_t _extra_size;
public:
size_t storage_size() const noexcept { return sizeof(piggie) + _extra_size; }
piggie(size_t sz) noexcept : _extra_size(sz) {}
};
static constexpr unsigned nr_seq_allocations = 1024;
static constexpr unsigned nr_iterations = 20000;
static constexpr unsigned nr_sizes = 32;
int main(int argc, char** argv) {
app_template app;
return app.run(argc, argv, [] {
return seastar::async([&] {
logalloc::prime_segment_pool(memory::stats().total_memory(), memory::min_free_memory()).get();
logalloc::region reg;
std::array<piggie*, nr_seq_allocations> objects;
std::array<size_t, nr_sizes> sizes;
std::random_device rd;
std::mt19937 g(rd());
for (unsigned i = 0; i < nr_sizes; i++) {
sizes[i] = i;
}
auto& allocator = reg.allocator();
std::chrono::duration<double> total;
for (unsigned iter = 0; iter < nr_iterations; iter++) {
std::shuffle(sizes.begin(), sizes.end(), g);
void* mem = allocator.alloc<piggie>(sizeof(piggie) + sizes[0]);
objects[0] = new (mem) piggie(sizes[0]);
auto start = std::chrono::steady_clock::now();
for (unsigned i = 1; i < nr_seq_allocations; i++) {
void* mem = allocator.alloc<piggie>(sizeof(piggie) + sizes[i % nr_sizes]);
objects[i] = new (mem) piggie(sizes[i % nr_sizes]);
}
total += std::chrono::steady_clock::now() - start;
for (unsigned i = 0; i < nr_seq_allocations; i++) {
allocator.destroy(objects[i]);
}
reg.full_compaction();
}
fmt::print("Total time: {} s\n", total.count());
});
});
}