mirror of
https://github.com/scylladb/scylladb.git
synced 2026-04-20 00:20:47 +00:00
To prevent large memory allocations.
This series shows over 3% improvement in perf-simple-query throughput.
```
$ build/release/scylla perf-simple-query --default-log-level=error --smp=1 --random-seed=1855519715
random-seed=1855519715
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...
Before:
random-seed=1775976514
enable-cache=1
enable-index-cache=1
sstable-summary-ratio=0.0005
sstable-format=me
Running test with config: {partitions=10000, concurrency=100, mode=read, query_single_key=no, counters=no}
Disabling auto compaction
Creating 10000 partitions...
336345.11 tps ( 58.1 allocs/op, 0.0 logallocs/op, 14.1 tasks/op, 32788 insns/op, 12430 cycles/op, 0 errors)
348748.14 tps ( 58.1 allocs/op, 0.0 logallocs/op, 14.1 tasks/op, 32794 insns/op, 12335 cycles/op, 0 errors)
349012.63 tps ( 58.1 allocs/op, 0.0 logallocs/op, 14.1 tasks/op, 32800 insns/op, 12326 cycles/op, 0 errors)
350629.97 tps ( 58.1 allocs/op, 0.0 logallocs/op, 14.1 tasks/op, 32770 insns/op, 12270 cycles/op, 0 errors)
348585.00 tps ( 58.1 allocs/op, 0.0 logallocs/op, 14.1 tasks/op, 32804 insns/op, 12338 cycles/op, 0 errors)
throughput:
mean= 346664.17 standard-deviation=5825.77
median= 348748.14 median-absolute-deviation=2348.46
maximum=350629.97 minimum=336345.11
instructions_per_op:
mean= 32791.35 standard-deviation=13.60
median= 32794.47 median-absolute-deviation=8.65
maximum=32804.45 minimum=32769.57
cpu_cycles_per_op:
mean= 12340.05 standard-deviation=57.57
median= 12335.05 median-absolute-deviation=13.94
maximum=12430.42 minimum=12270.28
After:
random-seed=1775976514
enable-cache=1
enable-index-cache=1
sstable-summary-ratio=0.0005
sstable-format=me
Running test with config: {partitions=10000, concurrency=100, mode=read, query_single_key=no, counters=no}
Disabling auto compaction
Creating 10000 partitions...
353770.85 tps ( 58.1 allocs/op, 0.0 logallocs/op, 14.1 tasks/op, 32762 insns/op, 11893 cycles/op, 0 errors)
364447.98 tps ( 58.1 allocs/op, 0.0 logallocs/op, 14.1 tasks/op, 32738 insns/op, 11818 cycles/op, 0 errors)
365268.97 tps ( 58.1 allocs/op, 0.0 logallocs/op, 14.1 tasks/op, 32734 insns/op, 11788 cycles/op, 0 errors)
344304.87 tps ( 58.1 allocs/op, 0.0 logallocs/op, 14.1 tasks/op, 32746 insns/op, 12506 cycles/op, 0 errors)
362263.57 tps ( 58.1 allocs/op, 0.0 logallocs/op, 14.1 tasks/op, 32756 insns/op, 11888 cycles/op, 0 errors)
throughput:
mean= 358011.25 standard-deviation=8916.76
median= 362263.57 median-absolute-deviation=6436.74
maximum=365268.97 minimum=344304.87
instructions_per_op:
mean= 32747.06 standard-deviation=11.85
median= 32745.80 median-absolute-deviation=9.36
maximum=32762.18 minimum=32734.01
cpu_cycles_per_op:
mean= 11978.65 standard-deviation=298.06
median= 11887.96 median-absolute-deviation=160.96
maximum=12505.72 minimum=11788.49
```
Refs #28511
(Refs rather than Fixes for the lack of a reproducer unit test)
* No backport needed as the issue is rare and not severe
Closes scylladb/scylladb#28631
* github.com:scylladb/scylladb:
query: result_set: change row member to a chunked vector
query: result_set_row: make noexcept
query: non_null_data_value: assert is_nothrow_move_constructible and assignable
types: data_value: assert is_nothrow_move_constructible and assignable
146 lines
4.3 KiB
C++
146 lines
4.3 KiB
C++
/*
|
|
* Copyright (C) 2015-present ScyllaDB
|
|
*/
|
|
|
|
/*
|
|
* SPDX-License-Identifier: LicenseRef-ScyllaDB-Source-Available-1.1
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
|
#include <seastar/core/shared_ptr.hh>
|
|
#include <fmt/ostream.h>
|
|
#include "types/types.hh"
|
|
#include "schema/schema.hh"
|
|
|
|
#include <optional>
|
|
#include <stdexcept>
|
|
|
|
class mutation;
|
|
|
|
namespace query {
|
|
|
|
class result;
|
|
|
|
class no_value : public std::runtime_error {
|
|
public:
|
|
using runtime_error::runtime_error;
|
|
};
|
|
|
|
class non_null_data_value {
|
|
data_value _v;
|
|
|
|
public:
|
|
explicit non_null_data_value(data_value&& v);
|
|
operator const data_value&() const {
|
|
return _v;
|
|
}
|
|
};
|
|
|
|
inline bool operator==(const non_null_data_value& x, const non_null_data_value& y) {
|
|
return static_cast<const data_value&>(x) == static_cast<const data_value&>(y);
|
|
}
|
|
|
|
// Result set row is a set of cells that are associated with a row
|
|
// including regular column cells, partition keys, as well as static values.
|
|
class result_set_row {
|
|
schema_ptr _schema;
|
|
std::unordered_map<sstring, non_null_data_value> _cells;
|
|
public:
|
|
result_set_row(schema_ptr schema, std::unordered_map<sstring, non_null_data_value>&& cells)
|
|
: _schema{schema}
|
|
, _cells{std::move(cells)}
|
|
{ }
|
|
result_set_row(result_set_row&&) = default;
|
|
result_set_row(const result_set_row&) = delete;
|
|
result_set_row& operator=(result_set_row&&) = default;
|
|
result_set_row& operator=(const result_set_row&) = delete;
|
|
result_set_row copy() const {
|
|
return {_schema, std::unordered_map{cells()}};
|
|
}
|
|
// Look up a deserialized row cell value by column name
|
|
const data_value*
|
|
get_data_value(const sstring& column_name) const {
|
|
auto it = cells().find(column_name);
|
|
if (it == cells().end()) {
|
|
return nullptr;
|
|
}
|
|
return &static_cast<const data_value&>(it->second);
|
|
}
|
|
// Look up a deserialized row cell value by column name
|
|
template<typename T>
|
|
std::optional<T>
|
|
get(const sstring& column_name) const {
|
|
if (const auto *value = get_ptr<T>(column_name)) {
|
|
return std::optional(*value);
|
|
}
|
|
return std::nullopt;
|
|
}
|
|
template<typename T>
|
|
const T*
|
|
get_ptr(const sstring& column_name) const {
|
|
const auto *value = get_data_value(column_name);
|
|
if (value == nullptr) {
|
|
return nullptr;
|
|
}
|
|
return &value_cast<T>(*value);
|
|
}
|
|
// throws no_value on error
|
|
template<typename T>
|
|
const T& get_nonnull(const sstring& column_name) const {
|
|
auto v = get_ptr<std::remove_reference_t<T>>(column_name);
|
|
if (v) {
|
|
return *v;
|
|
}
|
|
throw no_value(column_name);
|
|
}
|
|
const std::unordered_map<sstring, non_null_data_value>& cells() const { return _cells; }
|
|
friend inline bool operator==(const result_set_row& x, const result_set_row& y) = default;
|
|
friend std::ostream& operator<<(std::ostream& out, const result_set_row& row);
|
|
};
|
|
|
|
// Result set is an in-memory representation of query results in
|
|
// deserialized format. To obtain a result set, use the result_set_builder
|
|
// class as a visitor to query_result::consume() function.
|
|
class result_set {
|
|
public:
|
|
using rows_type = utils::chunked_vector<result_set_row>;
|
|
private:
|
|
schema_ptr _schema;
|
|
rows_type _rows;
|
|
public:
|
|
static result_set from_raw_result(schema_ptr, const partition_slice&, const result&);
|
|
result_set(schema_ptr s, rows_type&& rows)
|
|
: _schema(std::move(s)), _rows{std::move(rows)}
|
|
{ }
|
|
explicit result_set(const mutation&);
|
|
bool empty() const {
|
|
return _rows.empty();
|
|
}
|
|
// throws std::out_of_range on error
|
|
const result_set_row& row(size_t idx) const {
|
|
if (idx >= _rows.size()) {
|
|
throw std::out_of_range("no such row in result set: " + std::to_string(idx));
|
|
}
|
|
return _rows[idx];
|
|
}
|
|
const rows_type& rows() const {
|
|
return _rows;
|
|
}
|
|
const schema_ptr& schema() const {
|
|
return _schema;
|
|
}
|
|
friend inline bool operator==(const result_set& x, const result_set& y);
|
|
friend std::ostream& operator<<(std::ostream& out, const result_set& rs);
|
|
};
|
|
|
|
inline bool operator==(const result_set& x, const result_set& y) {
|
|
return x._rows == y._rows;
|
|
}
|
|
|
|
}
|
|
|
|
template <> struct fmt::formatter<query::result_set> : fmt::ostream_formatter {};
|
|
template <> struct fmt::formatter<query::result_set_row> : fmt::ostream_formatter {};
|