mirror of
https://github.com/scylladb/scylladb.git
synced 2026-04-21 00:50:35 +00:00
Currently, we use std::vector<*mutation> to keep
a list of mutations for processing.
This can lead to large allocation, e.g. when the vector
size is a function of the number of tables.
Use a chunked vector instead to prevent oversized allocations.
`perf-simple-query --smp 1` results obtained for fixed 400MHz frequency
and PGO disabled:
Before (read path):
```
enable-cache=1
Running test with config: {partitions=10000, concurrency=100, mode=read, query_single_key=no, counters=no}
Disabling auto compaction
Creating 10000 partitions...
89055.97 tps ( 66.1 allocs/op, 0.0 logallocs/op, 14.2 tasks/op, 39417 insns/op, 18003 cycles/op, 0 errors)
103372.72 tps ( 66.1 allocs/op, 0.0 logallocs/op, 14.2 tasks/op, 39380 insns/op, 17300 cycles/op, 0 errors)
98942.27 tps ( 66.1 allocs/op, 0.0 logallocs/op, 14.2 tasks/op, 39413 insns/op, 17336 cycles/op, 0 errors)
103752.93 tps ( 66.1 allocs/op, 0.0 logallocs/op, 14.2 tasks/op, 39407 insns/op, 17252 cycles/op, 0 errors)
102516.77 tps ( 66.1 allocs/op, 0.0 logallocs/op, 14.2 tasks/op, 39403 insns/op, 17288 cycles/op, 0 errors)
throughput:
mean= 99528.13 standard-deviation=6155.71
median= 102516.77 median-absolute-deviation=3844.59
maximum=103752.93 minimum=89055.97
instructions_per_op:
mean= 39403.99 standard-deviation=14.25
median= 39406.75 median-absolute-deviation=9.30
maximum=39416.63 minimum=39380.39
cpu_cycles_per_op:
mean= 17435.81 standard-deviation=318.24
median= 17300.40 median-absolute-deviation=147.59
maximum=18002.53 minimum=17251.75
```
After (read path)
```
enable-cache=1
Running test with config: {partitions=10000, concurrency=100, mode=read, query_single_key=no, counters=no}
Disabling auto compaction
Creating 10000 partitions...
59755.04 tps ( 66.2 allocs/op, 0.0 logallocs/op, 14.2 tasks/op, 39466 insns/op, 22834 cycles/op, 0 errors)
71854.16 tps ( 66.1 allocs/op, 0.0 logallocs/op, 14.2 tasks/op, 39417 insns/op, 17883 cycles/op, 0 errors)
82149.45 tps ( 66.1 allocs/op, 0.0 logallocs/op, 14.2 tasks/op, 39411 insns/op, 17409 cycles/op, 0 errors)
49640.04 tps ( 66.1 allocs/op, 0.0 logallocs/op, 14.3 tasks/op, 39474 insns/op, 19975 cycles/op, 0 errors)
54963.22 tps ( 66.1 allocs/op, 0.0 logallocs/op, 14.3 tasks/op, 39474 insns/op, 18235 cycles/op, 0 errors)
throughput:
mean= 63672.38 standard-deviation=13195.12
median= 59755.04 median-absolute-deviation=8709.16
maximum=82149.45 minimum=49640.04
instructions_per_op:
mean= 39448.38 standard-deviation=31.60
median= 39466.17 median-absolute-deviation=25.75
maximum=39474.12 minimum=39411.42
cpu_cycles_per_op:
mean= 19267.01 standard-deviation=2217.03
median= 18234.80 median-absolute-deviation=1384.25
maximum=22834.26 minimum=17408.67
```
`perf-simple-query --smp 1 --write` results obtained for fixed 400MHz frequency
and PGO disabled:
Before (write path):
```
enable-cache=1
Running test with config: {partitions=10000, concurrency=100, mode=write, query_single_key=no, counters=no}
Disabling auto compaction
63736.96 tps ( 59.4 allocs/op, 16.4 logallocs/op, 14.3 tasks/op, 49667 insns/op, 19924 cycles/op, 0 errors)
64109.41 tps ( 59.3 allocs/op, 16.0 logallocs/op, 14.3 tasks/op, 49992 insns/op, 20084 cycles/op, 0 errors)
56950.47 tps ( 59.3 allocs/op, 16.0 logallocs/op, 14.3 tasks/op, 50005 insns/op, 20501 cycles/op, 0 errors)
44858.42 tps ( 59.3 allocs/op, 16.0 logallocs/op, 14.3 tasks/op, 50014 insns/op, 21947 cycles/op, 0 errors)
28592.87 tps ( 59.3 allocs/op, 16.0 logallocs/op, 14.3 tasks/op, 50027 insns/op, 27659 cycles/op, 0 errors)
throughput:
mean= 51649.63 standard-deviation=15059.74
median= 56950.47 median-absolute-deviation=12087.33
maximum=64109.41 minimum=28592.87
instructions_per_op:
mean= 49941.18 standard-deviation=153.76
median= 50005.24 median-absolute-deviation=73.01
maximum=50027.07 minimum=49667.05
cpu_cycles_per_op:
mean= 22023.01 standard-deviation=3249.92
median= 20500.74 median-absolute-deviation=1938.76
maximum=27658.75 minimum=19924.32
```
After (write path)
```
enable-cache=1
Running test with config: {partitions=10000, concurrency=100, mode=write, query_single_key=no, counters=no}
Disabling auto compaction
53395.93 tps ( 59.4 allocs/op, 16.5 logallocs/op, 14.3 tasks/op, 50326 insns/op, 21252 cycles/op, 0 errors)
46527.83 tps ( 59.3 allocs/op, 16.0 logallocs/op, 14.3 tasks/op, 50704 insns/op, 21555 cycles/op, 0 errors)
55846.30 tps ( 59.3 allocs/op, 16.0 logallocs/op, 14.3 tasks/op, 50731 insns/op, 21060 cycles/op, 0 errors)
55669.30 tps ( 59.3 allocs/op, 16.0 logallocs/op, 14.3 tasks/op, 50735 insns/op, 21521 cycles/op, 0 errors)
52130.17 tps ( 59.3 allocs/op, 16.0 logallocs/op, 14.3 tasks/op, 50757 insns/op, 21334 cycles/op, 0 errors)
throughput:
mean= 52713.91 standard-deviation=3795.38
median= 53395.93 median-absolute-deviation=2955.40
maximum=55846.30 minimum=46527.83
instructions_per_op:
mean= 50650.57 standard-deviation=182.46
median= 50731.38 median-absolute-deviation=84.09
maximum=50756.62 minimum=50325.87
cpu_cycles_per_op:
mean= 21344.42 standard-deviation=202.86
median= 21334.00 median-absolute-deviation=176.37
maximum=21554.61 minimum=21060.24
```
Fixes #24815
Improvement for rare corner cases. No backport required
Signed-off-by: Benny Halevy <bhalevy@scylladb.com>
Closes scylladb/scylladb#24919
188 lines
7.8 KiB
C++
188 lines
7.8 KiB
C++
/*
|
|
* Copyright (C) 2017-present ScyllaDB
|
|
*/
|
|
|
|
/*
|
|
* SPDX-License-Identifier: LicenseRef-ScyllaDB-Source-Available-1.0
|
|
*/
|
|
|
|
#include "test/lib/sstable_utils.hh"
|
|
|
|
#include "replica/database.hh"
|
|
#include "replica/memtable-sstable.hh"
|
|
#include "dht/i_partitioner.hh"
|
|
#include "dht/murmur3_partitioner.hh"
|
|
#include "sstables/version.hh"
|
|
#include "test/lib/mutation_reader_assertions.hh"
|
|
#include "test/lib/reader_concurrency_semaphore.hh"
|
|
#include "test/boost/sstable_test.hh"
|
|
#include <seastar/core/reactor.hh>
|
|
#include <seastar/core/seastar.hh>
|
|
#include <seastar/core/coroutine.hh>
|
|
|
|
using namespace sstables;
|
|
using namespace std::chrono_literals;
|
|
|
|
lw_shared_ptr<replica::memtable> make_memtable(schema_ptr s, const utils::chunked_vector<mutation>& muts) {
|
|
auto mt = make_lw_shared<replica::memtable>(s);
|
|
|
|
std::size_t i{0};
|
|
for (auto&& m : muts) {
|
|
mt->apply(m);
|
|
// Give the reactor some time to breathe
|
|
if (++i == 10) {
|
|
seastar::thread::yield();
|
|
i = 0;
|
|
}
|
|
}
|
|
|
|
return mt;
|
|
}
|
|
|
|
std::vector<replica::memtable*> active_memtables(replica::table& t) {
|
|
std::vector<replica::memtable*> active_memtables;
|
|
t.for_each_active_memtable([&] (replica::memtable& mt) {
|
|
active_memtables.push_back(&mt);
|
|
});
|
|
return active_memtables;
|
|
}
|
|
|
|
sstables::shared_sstable make_sstable_containing(std::function<sstables::shared_sstable()> sst_factory, lw_shared_ptr<replica::memtable> mt) {
|
|
return make_sstable_containing(sst_factory(), std::move(mt));
|
|
}
|
|
|
|
sstables::shared_sstable make_sstable_containing(sstables::shared_sstable sst, lw_shared_ptr<replica::memtable> mt) {
|
|
write_memtable_to_sstable(*mt, sst).get();
|
|
sstable_open_config cfg { .load_first_and_last_position_metadata = true };
|
|
sst->open_data(cfg).get();
|
|
return sst;
|
|
}
|
|
|
|
sstables::shared_sstable make_sstable_containing(std::function<sstables::shared_sstable()> sst_factory, utils::chunked_vector<mutation> muts, validate do_validate) {
|
|
return make_sstable_containing(sst_factory(), std::move(muts), do_validate);
|
|
}
|
|
|
|
sstables::shared_sstable make_sstable_containing(sstables::shared_sstable sst, utils::chunked_vector<mutation> muts, validate do_validate) {
|
|
schema_ptr s = muts[0].schema();
|
|
make_sstable_containing(sst, make_memtable(s, muts));
|
|
|
|
if (do_validate) {
|
|
tests::reader_concurrency_semaphore_wrapper semaphore;
|
|
|
|
std::set<mutation, mutation_decorated_key_less_comparator> merged;
|
|
for (auto&& m : muts) {
|
|
auto it = merged.find(m);
|
|
if (it == merged.end()) {
|
|
merged.insert(std::move(m));
|
|
} else {
|
|
auto old = merged.extract(it);
|
|
old.value().apply(std::move(m));
|
|
merged.insert(std::move(old));
|
|
}
|
|
}
|
|
|
|
// validate the sstable
|
|
auto rd = assert_that(sst->as_mutation_source().make_mutation_reader(s, semaphore.make_permit()));
|
|
for (auto&& m : merged) {
|
|
rd.produces(m);
|
|
}
|
|
rd.produces_end_of_stream();
|
|
}
|
|
return sst;
|
|
}
|
|
|
|
shared_sstable make_sstable_easy(test_env& env, mutation_reader rd, sstable_writer_config cfg,
|
|
sstables::generation_type gen, const sstables::sstable::version_types version, int expected_partition, db_clock::time_point query_time) {
|
|
auto s = rd.schema();
|
|
auto sst = env.make_sstable(s, gen, version, sstable_format_types::big, default_sstable_buffer_size, query_time);
|
|
sst->write_components(std::move(rd), expected_partition, s, cfg, encoding_stats{}).get();
|
|
sst->load(s->get_sharder()).get();
|
|
return sst;
|
|
}
|
|
|
|
shared_sstable make_sstable_easy(test_env& env, lw_shared_ptr<replica::memtable> mt, sstable_writer_config cfg,
|
|
sstables::generation_type gen, const sstable::version_types v, int estimated_partitions, db_clock::time_point query_time) {
|
|
return make_sstable_easy(env, mt->make_mutation_reader(mt->schema(), env.make_reader_permit()), std::move(cfg), gen, v, estimated_partitions, query_time);
|
|
}
|
|
|
|
future<compaction_result> compact_sstables(test_env& env, sstables::compaction_descriptor descriptor, table_for_tests t,
|
|
std::function<shared_sstable()> creator, sstables::compaction_sstable_replacer_fn replacer, can_purge_tombstones can_purge) {
|
|
auto& table_s = t.as_table_state();
|
|
descriptor.creator = [creator = std::move(creator)] (shard_id dummy) mutable {
|
|
return creator();
|
|
};
|
|
descriptor.replacer = std::move(replacer);
|
|
if (can_purge) {
|
|
descriptor.enable_garbage_collection(table_s.main_sstable_set());
|
|
}
|
|
sstables::compaction_result ret;
|
|
co_await run_compaction_task(env, descriptor.run_identifier, table_s, [&] (sstables::compaction_data& cdata) {
|
|
return do_with(compaction_progress_monitor{}, [&] (compaction_progress_monitor& progress_monitor) {
|
|
return sstables::compact_sstables(std::move(descriptor), cdata, table_s, progress_monitor).then([&] (sstables::compaction_result res) {
|
|
ret = std::move(res);
|
|
});
|
|
});
|
|
});
|
|
co_return ret;
|
|
}
|
|
|
|
class compaction_manager_test_task : public compaction::compaction_task_executor {
|
|
sstables::run_id _run_id;
|
|
noncopyable_function<future<> (sstables::compaction_data&)> _job;
|
|
gate::holder _hold;
|
|
|
|
public:
|
|
compaction_manager_test_task(compaction_manager& cm, table_state& table_s, sstables::run_id run_id, noncopyable_function<future<> (sstables::compaction_data&)> job)
|
|
: compaction::compaction_task_executor(cm, throw_if_stopping::no, &table_s, sstables::compaction_type::Compaction, "Test compaction")
|
|
, _run_id(run_id)
|
|
, _job(std::move(job))
|
|
, _hold(_compaction_state.gate.hold())
|
|
{ }
|
|
|
|
protected:
|
|
virtual future<compaction_manager::compaction_stats_opt> do_run() override {
|
|
setup_new_compaction(_run_id);
|
|
return _job(_compaction_data).then([] {
|
|
return make_ready_future<compaction_manager::compaction_stats_opt>(std::nullopt);
|
|
});
|
|
}
|
|
};
|
|
|
|
future<> run_compaction_task(test_env& env, sstables::run_id output_run_id, table_state& table_s, noncopyable_function<future<> (sstables::compaction_data&)> job) {
|
|
auto& tcm = env.test_compaction_manager();
|
|
auto task = make_shared<compaction_manager_test_task>(tcm.get_compaction_manager(), table_s, output_run_id, std::move(job));
|
|
co_await tcm.perform_compaction(std::move(task));
|
|
}
|
|
|
|
shared_sstable verify_mutation(test_env& env, shared_sstable sst, lw_shared_ptr<replica::memtable> mt, bytes key, std::function<void(mutation_opt&)> verify) {
|
|
auto sstp = make_sstable_containing(std::move(sst), mt);
|
|
return verify_mutation(env, std::move(sstp), std::move(key), std::move(verify));
|
|
}
|
|
|
|
shared_sstable verify_mutation(test_env& env, shared_sstable sstp, bytes key, std::function<void(mutation_opt&)> verify) {
|
|
auto s = sstp->get_schema();
|
|
auto pr = dht::partition_range::make_singular(make_dkey(s, key));
|
|
auto rd = sstp->make_reader(s, env.make_reader_permit(), pr, s->full_slice());
|
|
auto close_rd = deferred_close(rd);
|
|
auto mopt = read_mutation_from_mutation_reader(rd).get();
|
|
verify(mopt);
|
|
return sstp;
|
|
}
|
|
|
|
shared_sstable verify_mutation(test_env& env, shared_sstable sst, lw_shared_ptr<replica::memtable> mt, dht::partition_range pr, std::function<stop_iteration(mutation_opt&)> verify) {
|
|
auto sstp = make_sstable_containing(std::move(sst), mt);
|
|
return verify_mutation(env, std::move(sstp), std::move(pr), std::move(verify));
|
|
}
|
|
|
|
shared_sstable verify_mutation(test_env& env, shared_sstable sstp, dht::partition_range pr, std::function<stop_iteration(mutation_opt&)> verify) {
|
|
auto s = sstp->get_schema();
|
|
auto rd = sstp->make_reader(s, env.make_reader_permit(), std::move(pr), s->full_slice());
|
|
auto close_rd = deferred_close(rd);
|
|
while (auto mopt = read_mutation_from_mutation_reader(rd).get()) {
|
|
if (verify(mopt) == stop_iteration::yes) {
|
|
break;
|
|
}
|
|
}
|
|
return sstp;
|
|
}
|