Files
scylladb/dht/byte_ordered_partitioner.hh
Glauber Costa e1968c389e dht: use tri_compare for token comparisons
Loading data from memory tends to be the most expensive part of the comparison
operations. Because we don't have a tri_compare function for tokens, we end up
having to do an equality test, which will load the token's data in memory, and
then, because all we know is that they are not equal, we need to do another
one.

Having two dereferences is harmful, and shows up in my simple benchmark. This
is because before writing to sstables, we must order the keys in decorated key
order, which is heavy on the comparisons.

The proposed change speeds up index write benchmark by 8.6%:

Before:
41458.14 +- 1.49 partitions / sec (30 runs)

After:
45020.81 +- 3.60 partitions / sec (30 runs)

Parameters:
--smp 6 --partitions 500000

Signed-off-by: Glauber Costa <glommer@cloudius-systems.com>
2015-08-12 09:23:42 -05:00

43 lines
1.4 KiB
C++

/*
* Copyright (C) 2015 Cloudius Systems, Ltd.
*/
#pragma once
#include "i_partitioner.hh"
#include "bytes.hh"
#include "sstables/key.hh"
namespace dht {
class byte_ordered_partitioner final : public i_partitioner {
public:
virtual const sstring name() { return "org.apache.cassandra.dht.ByteOrderedPartitioner"; }
virtual token get_token(const schema& s, partition_key_view key) override {
auto&& legacy = key.legacy_form(s);
return token(token::kind::key, bytes(legacy.begin(), legacy.end()));
}
virtual token get_token(const sstables::key_view& key) override {
auto v = bytes_view(key);
if (v.empty()) {
return minimum_token();
}
return token(token::kind::key, bytes(v.begin(), v.end()));
}
virtual token get_random_token() override;
virtual bool preserves_order() override { return true; }
virtual std::map<token, float> describe_ownership(const std::vector<token>& sorted_tokens) override;
virtual data_type get_token_validator() override { return bytes_type; }
virtual int tri_compare(const token& t1, const token& t2) override {
return compare_unsigned(t1._data, t2._data);
}
virtual token midpoint(const token& t1, const token& t2) const;
virtual sstring to_sstring(const dht::token& t) const override {
return to_hex(t._data);
}
virtual unsigned shard_of(const token& t) const override;
};
}