diff options
author | Ben Caimano <ben.caimano@10gen.com> | 2021-03-08 17:12:12 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2021-03-09 00:26:13 +0000 |
commit | 8ca55acd6ef2be43b8cc29bbe19d2845ab464105 (patch) | |
tree | 7f602a63a260486c652ce09d7fbf1581c4b614b8 /src/mongo | |
parent | db2e46857ce1c2bf90fda9842287cc5940fce81c (diff) | |
download | mongo-8ca55acd6ef2be43b8cc29bbe19d2845ab464105.tar.gz |
SERVER-55041 Benchmark UUID generation and increase SecureRandom buffer size
Diffstat (limited to 'src/mongo')
-rw-r--r-- | src/mongo/platform/random.cpp | 8 | ||||
-rw-r--r-- | src/mongo/util/SConscript | 14 | ||||
-rw-r--r-- | src/mongo/util/uuid_bm.cpp | 52 |
3 files changed, 70 insertions, 4 deletions
diff --git a/src/mongo/platform/random.cpp b/src/mongo/platform/random.cpp index 2d19fc79b35..00c3cb2a068 100644 --- a/src/mongo/platform/random.cpp +++ b/src/mongo/platform/random.cpp @@ -69,8 +69,10 @@ namespace mongo { namespace { -template <size_t N> +template <size_t Bytes> struct Buffer { + static constexpr size_t kArraySize = Bytes / sizeof(uint64_t); + uint64_t pop() { return arr[--avail]; } @@ -84,7 +86,7 @@ struct Buffer { avail = arr.size(); } - std::array<uint64_t, N> arr; + std::array<uint64_t, kArraySize> arr; size_t avail = 0; }; @@ -205,7 +207,7 @@ public: private: Source _source; - Buffer<16> _buffer; + Buffer<4096> _buffer; }; SecureUrbg::SecureUrbg() : _state{std::make_unique<State>()} {} diff --git a/src/mongo/util/SConscript b/src/mongo/util/SConscript index 1bff532b04b..f3aa885ab3c 100644 --- a/src/mongo/util/SConscript +++ b/src/mongo/util/SConscript @@ -778,4 +778,16 @@ env.Benchmark( env.Benchmark( target='cancelation_bm', source='cancelation_bm.cpp', -)
\ No newline at end of file +) + +env.Benchmark( + target='uuid_bm', + source=[ + 'uuid_bm.cpp', + ], + LIBDEPS=[ + '$BUILD_DIR/mongo/base', + 'processinfo', + ], +) + diff --git a/src/mongo/util/uuid_bm.cpp b/src/mongo/util/uuid_bm.cpp new file mode 100644 index 00000000000..0489294707a --- /dev/null +++ b/src/mongo/util/uuid_bm.cpp @@ -0,0 +1,52 @@ +/** + * Copyright (C) 2011-present MongoDB, Inc. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the Server Side Public License, version 1, + * as published by MongoDB, Inc. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * Server Side Public License for more details. + * + * You should have received a copy of the Server Side Public License + * along with this program. If not, see + * <http://www.mongodb.com/licensing/server-side-public-license>. + * + * As a special exception, the copyright holders give permission to link the + * code of portions of this program with the OpenSSL library under certain + * conditions as described in each individual source file and distribute + * linked combinations including the program with the OpenSSL library. You + * must comply with the Server Side Public License in all respects for + * all of the code used other than as permitted herein. If you modify file(s) + * with this exception, you may extend this exception to your version of the + * file(s), but you are not obligated to do so. If you do not wish to do so, + * delete this exception statement from your version. If you delete this + * exception statement from all source files in the program, then also delete + * it in the license file. + */ + +#include "mongo/platform/basic.h" + +#include <benchmark/benchmark.h> + +#include "mongo/util/uuid.h" + +#include "mongo/util/processinfo.h" + +namespace mongo { +namespace { + +void BM_UuidGen(benchmark::State& state) { + for (auto keepRunning : state) { + benchmark::DoNotOptimize(UUID::gen()); + } +} + +const auto kConcurrencyLimit = 2 * ProcessInfo::getNumAvailableCores(); + +BENCHMARK(BM_UuidGen)->ThreadRange(1, kConcurrencyLimit); + +} // namespace +} // namespace mongo |