Skip to content

Commit 779eaae

Browse files
René ScheibeKarsten1987
René Scheibe
authored andcommitted
Benchmarks for SQLite write performance (#1)
1 parent 1701bca commit 779eaae

39 files changed

+2892
-52
lines changed

.gitignore

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.idea/
2+
.ipynb_checkpoints/
3+
cmake-build-debug/
4+
cmake-build-release/
5+
build/
6+
venv/

NOTICE

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
rosbag2
2+
3+
Copyright Holders:
4+
Copyright (c) 2018, Open Source Robotics Foundation, Inc.
5+
Copyright (c) 2018, Bosch Software Innovations GmbH
+80-34
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,81 @@
11
cmake_minimum_required(VERSION 3.5)
2-
project(rosbag2_storage_evaluation)
3-
4-
# Default to C99
5-
if(NOT CMAKE_C_STANDARD)
6-
set(CMAKE_C_STANDARD 99)
7-
endif()
8-
9-
# Default to C++14
10-
if(NOT CMAKE_CXX_STANDARD)
11-
set(CMAKE_CXX_STANDARD 14)
12-
endif()
13-
14-
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
15-
add_compile_options(-Wall -Wextra -Wpedantic)
16-
endif()
17-
18-
# find dependencies
19-
find_package(ament_cmake REQUIRED)
20-
# uncomment the following section in order to fill in
21-
# further dependencies manually.
22-
# find_package(<dependency> REQUIRED)
23-
24-
if(BUILD_TESTING)
25-
find_package(ament_lint_auto REQUIRED)
26-
# the following line skips the linter which checks for copyrights
27-
# remove the line when a copyright and license is present in all source files
28-
set(ament_cmake_copyright_FOUND TRUE)
29-
# the following line skips cpplint (only works in a git repo)
30-
# remove the line when this package is a git repo
31-
set(ament_cmake_cpplint_FOUND TRUE)
32-
ament_lint_auto_find_test_dependencies()
33-
endif()
34-
35-
ament_package()
2+
3+
project(ros2_rosbag_evaluation)
4+
5+
set(CMAKE_CXX_STANDARD 14)
6+
set(CMAKE_CXX_FLAGS "-O3")
7+
set(BUILD_SHARED_LIBS ON)
8+
9+
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin)
10+
11+
set(common_sources
12+
src/common/strings.cpp)
13+
14+
set(profiler_sources
15+
src/profiler/profiler.cpp)
16+
17+
set(sqlite_sources
18+
src/writer/sqlite/sqlite.cpp
19+
src/writer/sqlite/sqlite_writer.cpp
20+
src/writer/sqlite/one_table_sqlite_writer.cpp
21+
src/writer/sqlite/separate_topic_table_sqlite_writer.cpp)
22+
23+
set(trivial_writer_benchmark_sources
24+
src/benchmark/writer/trivial/trivial_writer_benchmark.cpp
25+
src/benchmark/benchmark.cpp
26+
src/writer/stream/message_stream_writer.cpp
27+
src/generators/message_generator.cpp)
28+
29+
set(sqlite_writer_benchmark_cmd_sources
30+
src/benchmark/writer/sqlite/sqlite_writer_benchmark_cmd.cpp
31+
src/benchmark/writer/sqlite/sqlite_writer_benchmark.cpp
32+
src/benchmark/benchmark.cpp
33+
src/generators/message_generator.cpp)
34+
35+
set(small_messages_benchmark_sources
36+
src/benchmark/small_messages_benchmark.cpp
37+
src/benchmark/writer/sqlite/sqlite_writer_benchmark.cpp
38+
src/benchmark/benchmark.cpp
39+
src/generators/message_generator.cpp)
40+
41+
set(big_messages_benchmark_sources
42+
src/benchmark/big_messages_benchmark.cpp
43+
src/benchmark/writer/sqlite/sqlite_writer_benchmark.cpp
44+
src/benchmark/benchmark.cpp
45+
src/generators/message_generator.cpp)
46+
47+
set(mixed_messages_benchmark_sources
48+
src/benchmark/mixed_messages_benchmark.cpp
49+
src/benchmark/writer/sqlite/sqlite_writer_benchmark.cpp
50+
src/benchmark/benchmark.cpp
51+
src/generators/message_generator.cpp)
52+
53+
add_library(common ${common_sources})
54+
target_include_directories(common PRIVATE src)
55+
56+
add_library(profiler ${profiler_sources})
57+
target_include_directories(profiler PRIVATE src)
58+
59+
add_library(sqlite ${sqlite_sources})
60+
target_include_directories(sqlite PRIVATE src)
61+
target_link_libraries(sqlite sqlite3 common)
62+
63+
add_executable(trivial_writer_benchmark ${trivial_writer_benchmark_sources})
64+
target_link_libraries(trivial_writer_benchmark profiler sqlite)
65+
target_include_directories(trivial_writer_benchmark PRIVATE src)
66+
67+
add_executable(sqlite_writer_benchmark_cmd ${sqlite_writer_benchmark_cmd_sources})
68+
target_link_libraries(sqlite_writer_benchmark_cmd profiler sqlite)
69+
target_include_directories(sqlite_writer_benchmark_cmd PRIVATE src)
70+
71+
add_executable(small_messages_benchmark ${small_messages_benchmark_sources})
72+
target_link_libraries(small_messages_benchmark profiler sqlite)
73+
target_include_directories(small_messages_benchmark PRIVATE src)
74+
75+
add_executable(big_messages_benchmark ${big_messages_benchmark_sources})
76+
target_link_libraries(big_messages_benchmark profiler sqlite)
77+
target_include_directories(big_messages_benchmark PRIVATE src)
78+
79+
add_executable(mixed_messages_benchmark ${mixed_messages_benchmark_sources})
80+
target_link_libraries(mixed_messages_benchmark profiler sqlite)
81+
target_include_directories(mixed_messages_benchmark PRIVATE src)

rosbag2_storage_evaluation/README.md

+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# ROS 2.0 Rosbag Evaluation
2+
3+
## Benchmarks
4+
5+
This folder currently contains benchmarks which measure the write speed and disk usage of SQLite files.
6+
7+
The single table schema
8+
```
9+
sqlite::create_table(db, "MESSAGES", {
10+
"TIMESTAMP INTEGER NOT NULL",
11+
"TOPIC TEXT NOT NULL",
12+
"DATA BLOB NOT NULL"
13+
});
14+
```
15+
is compared with a foreign key schema storing topics in a separate table
16+
```
17+
sqlite::create_table(db, "TOPICS", {
18+
"ID INTEGER PRIMARY KEY",
19+
"TOPIC TEXT NOT NULL"
20+
});
21+
22+
sqlite::create_table(db, "MESSAGES", {
23+
"TIMESTAMP INTEGER NOT NULL",
24+
"TOPIC_ID INTEGER NOT NULL",
25+
"DATA BLOB NOT NULL"
26+
}, {sqlite::ForeignKeyDef{"TOPIC_ID", "TOPICS", "ID"}});
27+
```
28+
29+
It should be **easy to add additional bag file formats**, e.g. for writing directly to disk or writing the RosBag 2.0 format.
30+
31+
### Build from command line
32+
33+
The project is using cmake. The script `./build.sh` can be used to build it.
34+
35+
This will generate benchmark binaries in `./build/bin/`.
36+
37+
### Run
38+
39+
Individual benchmarks in `./build/bin` can be run by hand. To run the complete suite the script `./run_all_benchmarks.sh` can be used.
40+
41+
Each benchmark will generate a CSV file in `./build/bin` containing the measured data for further plotting with the Jupyter Notebook.
42+
43+
## Jupyter Notebook
44+
45+
It is used for data analysis and visualization.
46+
47+
### Setup
48+
49+
Prerequisites: Python 3.5+, [pip](https://pip.pypa.io/en/stable/), [virtualenv](https://virtualenv.pypa.io/en/stable/)
50+
51+
```
52+
virtualenv -p python3 venv
53+
. venv/bin/activate
54+
pip install -r requirements.txt
55+
```
56+
57+
### Usage
58+
59+
```
60+
. venv/bin/activate
61+
jupyter notebook data_analysis_and_visualization.ipynb
62+
```
63+
64+
A browser window should open. Click `Cell -> Run All`.
65+
66+
## Extending the benchmarks
67+
68+
### Read Tests
69+
70+
To measure retrieval time of the first message, extend the `MessageWriter` interface like so
71+
```
72+
virtual MessageStream::Ptr selectAll() = 0;
73+
virtual MessageStream::Ptr selectTopic(std::string const & topic) = 0;
74+
virtual MessageStream::Ptr selectFromTo(
75+
Message::Timestamp const & fromInclusive, Message::Timestamp const & toExclusive) = 0;
76+
```
77+
where `MessageStream` is a lazy data structure
78+
```
79+
virtual bool has_next() const = 0;
80+
virtual MessagePtr next() = 0;
81+
```
82+
implemented with a streaming SQLite `SELECT` statement.
83+
84+
The desired timings can then be measured with the `Profiler`.

rosbag2_storage_evaluation/build.sh

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/usr/bin/env sh
2+
# Copyright (c) 2018, Bosch Software Innovations GmbH.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
mkdir -p ./build
17+
18+
cd build
19+
20+
cmake ..
21+
make
22+
23+
cd ..
24+

0 commit comments

Comments
 (0)