Packages
rocksdb
2.4.0
3.1.1
3.1.0
3.0.0
2.6.2
2.6.1
retired
2.6.0
retired
2.5.0
2.4.1
2.4.0
2.3.0
2.2.0
2.1.0
2.0.0
1.9.0
1.8.0
1.7.0
1.6.0
1.5.1
1.5.0
1.4.0
1.3.2
1.3.1
1.3.0
1.2.0
1.1.1
1.1.0
1.0.0
0.26.2
0.26.1
0.26.0
0.25.0
0.24.0
0.23.3
0.23.2
0.23.1
0.23.0
0.22.0
0.21.0
0.20.1
0.20.0
0.19.0
0.18.0
0.17.0
0.16.0
0.15.0
0.14.0
0.13.1
0.13.0
0.12.0
0.11.0
0.10.0
0.9.1
0.9.0
0.8.2
0.8.1
0.8.0
0.7.1
0.7.0
0.6.4
0.6.3
0.6.2
0.6.1
0.6.0
RocksDB for Erlang
Current section
Files
Jump to
Current section
Files
test/io_histograms.erl
%% Copyright (c) 2025 Benoit Chesneau
%%
%% This file is provided to you under the Apache License,
%% Version 2.0 (the "License"); you may not use this file
%% except in compliance with the License. You may obtain
%% a copy of the License at
%%
%% http://www.apache.org/licenses/LICENSE-2.0
%%
%% Unless required by applicable law or agreed to in writing,
%% software distributed under the License is distributed on an
%% "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
%% KIND, either express or implied. See the License for the
%% specific language governing permissions and limitations
%% under the License.
-module(io_histograms).
-include_lib("eunit/include/eunit.hrl").
-define(rm_rf(Dir), rocksdb_test_util:rm_rf(Dir)).
sst_write_histogram_test() ->
?rm_rf("test_sst_write_hist"),
{ok, Stats} = rocksdb:new_statistics(),
{ok, Db} = rocksdb:open(
"test_sst_write_hist",
[{create_if_missing, true},
{statistics, Stats}]),
try
%% Write data to memtable
lists:foreach(
fun(I) ->
Key = <<$k, (integer_to_binary(I))/binary>>,
Value = list_to_binary(lists:duplicate(100, $v)),
ok = rocksdb:put(Db, Key, Value, [])
end,
lists:seq(1, 50)),
%% Flush to generate SST file
ok = rocksdb:flush(Db, []),
%% Check sst_write_micros histogram has recorded data
{ok, SstWriteHist} = rocksdb:statistics_histogram(Stats, sst_write_micros),
?assert(is_map(SstWriteHist)),
?assert(maps:get(count, SstWriteHist) > 0)
after
ok = rocksdb:close(Db),
ok = rocksdb:release_statistics(Stats),
?rm_rf("test_sst_write_hist")
end,
ok.
sst_read_histogram_test() ->
?rm_rf("test_sst_read_hist"),
{ok, Stats} = rocksdb:new_statistics(),
{ok, Db} = rocksdb:open(
"test_sst_read_hist",
[{create_if_missing, true},
{statistics, Stats}]),
try
%% Write and flush data to create SST file
lists:foreach(
fun(I) ->
Key = <<$k, (integer_to_binary(I))/binary>>,
Value = list_to_binary(lists:duplicate(100, $v)),
ok = rocksdb:put(Db, Key, Value, [])
end,
lists:seq(1, 50)),
ok = rocksdb:flush(Db, []),
%% Read data from SST file
lists:foreach(
fun(I) ->
Key = <<$k, (integer_to_binary(I))/binary>>,
{ok, _} = rocksdb:get(Db, Key, [])
end,
lists:seq(1, 50)),
%% Check sst_read_micros histogram has recorded data
{ok, SstReadHist} = rocksdb:statistics_histogram(Stats, sst_read_micros),
?assert(is_map(SstReadHist)),
?assert(maps:get(count, SstReadHist) >= 0)
after
ok = rocksdb:close(Db),
ok = rocksdb:release_statistics(Stats),
?rm_rf("test_sst_read_hist")
end,
ok.
wal_sync_histogram_test() ->
?rm_rf("test_wal_sync_hist"),
{ok, Stats} = rocksdb:new_statistics(),
{ok, Db} = rocksdb:open(
"test_wal_sync_hist",
[{create_if_missing, true},
{statistics, Stats}]),
try
%% Write with sync option to trigger WAL sync
lists:foreach(
fun(I) ->
Key = <<$k, (integer_to_binary(I))/binary>>,
Value = list_to_binary(lists:duplicate(100, $v)),
ok = rocksdb:put(Db, Key, Value, [{sync, true}])
end,
lists:seq(1, 10)),
%% Check wal_file_sync_micros histogram has recorded data
{ok, WalSyncHist} = rocksdb:statistics_histogram(Stats, wal_file_sync_micros),
?assert(is_map(WalSyncHist)),
?assert(maps:get(count, WalSyncHist) > 0)
after
ok = rocksdb:close(Db),
ok = rocksdb:release_statistics(Stats),
?rm_rf("test_wal_sync_hist")
end,
ok.
bytes_per_read_write_test() ->
?rm_rf("test_bytes_per_rw"),
{ok, Stats} = rocksdb:new_statistics(),
{ok, Db} = rocksdb:open(
"test_bytes_per_rw",
[{create_if_missing, true},
{statistics, Stats}]),
try
%% Write data
lists:foreach(
fun(I) ->
Key = <<$k, (integer_to_binary(I))/binary>>,
Value = list_to_binary(lists:duplicate(100, $v)),
ok = rocksdb:put(Db, Key, Value, [])
end,
lists:seq(1, 20)),
%% Flush to create SST file
ok = rocksdb:flush(Db, []),
%% Read data
lists:foreach(
fun(I) ->
Key = <<$k, (integer_to_binary(I))/binary>>,
{ok, _} = rocksdb:get(Db, Key, [])
end,
lists:seq(1, 20)),
%% Check bytes_per_write histogram
{ok, BytesWriteHist} = rocksdb:statistics_histogram(Stats, bytes_per_write),
?assert(is_map(BytesWriteHist)),
?assert(maps:get(count, BytesWriteHist) >= 0),
%% Check bytes_per_read histogram
{ok, BytesReadHist} = rocksdb:statistics_histogram(Stats, bytes_per_read),
?assert(is_map(BytesReadHist)),
?assert(maps:get(count, BytesReadHist) >= 0)
after
ok = rocksdb:close(Db),
ok = rocksdb:release_statistics(Stats),
?rm_rf("test_bytes_per_rw")
end,
ok.
table_sync_histogram_test() ->
?rm_rf("test_table_sync_hist"),
{ok, Stats} = rocksdb:new_statistics(),
{ok, Db} = rocksdb:open(
"test_table_sync_hist",
[{create_if_missing, true},
{statistics, Stats}]),
try
%% Write and flush data
lists:foreach(
fun(I) ->
Key = <<$k, (integer_to_binary(I))/binary>>,
Value = list_to_binary(lists:duplicate(100, $v)),
ok = rocksdb:put(Db, Key, Value, [])
end,
lists:seq(1, 50)),
ok = rocksdb:flush(Db, []),
%% Check table_sync_micros histogram is readable
{ok, TableSyncHist} = rocksdb:statistics_histogram(Stats, table_sync_micros),
?assert(is_map(TableSyncHist)),
?assert(is_integer(maps:get(count, TableSyncHist)))
after
ok = rocksdb:close(Db),
ok = rocksdb:release_statistics(Stats),
?rm_rf("test_table_sync_hist")
end,
ok.
all_io_histograms_readable_test() ->
?rm_rf("test_all_io_hist"),
{ok, Stats} = rocksdb:new_statistics(),
{ok, Db} = rocksdb:open(
"test_all_io_hist",
[{create_if_missing, true},
{statistics, Stats}]),
try
%% Test that all I/O histograms are readable
Histograms = [
sst_read_micros,
sst_write_micros,
table_sync_micros,
wal_file_sync_micros,
bytes_per_read,
bytes_per_write
],
lists:foreach(
fun(Histogram) ->
{ok, Data} = rocksdb:statistics_histogram(Stats, Histogram),
?assert(is_map(Data)),
?assert(is_float(maps:get(median, Data))),
?assert(is_float(maps:get(percentile95, Data))),
?assert(is_float(maps:get(percentile99, Data))),
?assert(is_float(maps:get(average, Data))),
?assert(is_float(maps:get(standard_deviation, Data))),
?assert(is_float(maps:get(max, Data))),
?assert(is_integer(maps:get(count, Data))),
?assert(is_integer(maps:get(sum, Data)))
end,
Histograms)
after
ok = rocksdb:close(Db),
ok = rocksdb:release_statistics(Stats),
?rm_rf("test_all_io_hist")
end,
ok.