aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDennis Brentjes <d.brentjes@gmail.com>2016-12-01 18:24:41 +0100
committerDennis Brentjes <d.brentjes@gmail.com>2016-12-01 18:24:41 +0100
commit7ee347e13ced7f1a84e7b325e65616b169e238a0 (patch)
tree316fbdba8a8526a3093157d2462ac8a55d6ca20b
parentbc39d05453340257fff986edfdd728f2a89d13ad (diff)
downloadcmix-7ee347e13ced7f1a84e7b325e65616b169e238a0.tar.gz
cmix-7ee347e13ced7f1a84e7b325e65616b169e238a0.tar.bz2
cmix-7ee347e13ced7f1a84e7b325e65616b169e238a0.zip
Use the new protobuf arena allocator.
Run script now takes a parameter tool to for instance "benchmark"
-rwxr-xr-xbenchmark.sh20
-rw-r--r--libcmix-common/CMakeLists.txt1
-rw-r--r--libcmix-protobuf/CMakeLists.txt4
-rw-r--r--node/node.cpp26
-rw-r--r--node/node.hpp10
-rw-r--r--node/node_node.cpp67
-rwxr-xr-xrun.sh24
7 files changed, 66 insertions, 86 deletions
diff --git a/benchmark.sh b/benchmark.sh
deleted file mode 100755
index e31ed4b..0000000
--- a/benchmark.sh
+++ /dev/null
@@ -1,20 +0,0 @@
-#!/bin/bash
-
-build_dir=/home/dennis/projects/cmix/build-cmix-Desktop-Default
-
-tmux new-session -s cmix -d
-tmux send-keys -t cmix:0 "cd ${build_dir} && valgrind --tool=cachegrind node/node -f -n node2.local:9201 -c ../certs/cert1.pem -k ../certs/key1.pem -d ../certs/dh.pem --certdir ../certs" Enter
-tmux send-keys -t cmix:0 "r" Enter
-
-tmux new-window -t cmix:1
-tmux send-keys -t cmix:1 "cd ${build_dir} && valgrind --tool=cachegrind node/node -l -p 9201 -n node1.local:9200 -c ../certs/cert2.pem -k ../certs/key2.pem -d ../certs/dh.pem --certdir ../certs/" Enter
-tmux send-keys -t cmix:1 "r" Enter
-
-tmux new-window -t cmix:2
-tmux send-keys -t cmix:2 "cd ${build_dir} && LSAN_OPTIONS=report_objects=1 valgrind --tool=cachegrind client/client --certdir ../certs -n node1.local:9200 node2.local:9201" Enter
-
-tmux new-window -t cmix:3
-tmux send-keys -t cmix:3 "cd ${build_dir} && LSAN_OPTIONS=report_objects=1 valgrind --tool=cachegrind client/client --certdir ../certs -n node1.local:9200 node2.local:9201" Enter
-
-tmux attach
-tmux kill-session -t cmix
diff --git a/libcmix-common/CMakeLists.txt b/libcmix-common/CMakeLists.txt
index defc00f..2324622 100644
--- a/libcmix-common/CMakeLists.txt
+++ b/libcmix-common/CMakeLists.txt
@@ -4,6 +4,7 @@ add_library(cmix-common
receiver.hpp
sender.hpp
senderreceiver.hpp
+ performanceclient.hpp
)
set_target_properties(cmix-common PROPERTIES LINKER_LANGUAGE CXX)
diff --git a/libcmix-protobuf/CMakeLists.txt b/libcmix-protobuf/CMakeLists.txt
index f2a8f3d..29dbb32 100644
--- a/libcmix-protobuf/CMakeLists.txt
+++ b/libcmix-protobuf/CMakeLists.txt
@@ -12,8 +12,8 @@ add_library(cmix-protobuf
)
target_include_directories(cmix-protobuf
- PUBLIC ${PROTOBUF_INCLUDE_DIRS}
+ PUBLIC ${Protobuf_INCLUDE_DIRS}
PUBLIC ${CMAKE_CURRENT_BINARY_DIR}
)
-target_link_libraries(cmix-protobuf ${PROTOBUF_LIBRARIES}) \ No newline at end of file
+target_link_libraries(cmix-protobuf ${Protobuf_LIBRARIES}) \ No newline at end of file
diff --git a/node/node.cpp b/node/node.cpp
index c17fe4f..aadc123 100644
--- a/node/node.cpp
+++ b/node/node.cpp
@@ -24,26 +24,6 @@ Node::Node(ListenSettings const& listen_settings, NodeNetworkSettings network_se
{
initialize_keypair(&cmix_ctx);
- std::string x = to_string(cmix_ctx.keypair.sec, cmix_ctx);
- std::string y = to_string(cmix_ctx.keypair.pub, cmix_ctx);
- {
- std::stringstream ss;
- ss << "sec: ";
- for(auto&& c : x) {
- ss << "\\" << std::setw(3) << std::setfill('0') << std::oct << (unsigned int) c;
- }
- BOOST_LOG_TRIVIAL(trace) << ss.str();
- }
-
- {
- std::stringstream ss;
- ss << "pub: ";
- for(auto&& c : y) {
- ss << "\\" << std::setw(3) << std::setfill('0') << std::oct << (unsigned int) c;
- }
- BOOST_LOG_TRIVIAL(trace) << ss.str();
- }
-
GOOGLE_PROTOBUF_VERIFY_VERSION;
if(network_settings.is_first) {
@@ -183,7 +163,8 @@ void Node::start_precomputation() {
}
BOOST_LOG_TRIVIAL(trace) << ss.str();
- cmix_proto::PrePre prepre;
+ ArenaMessage<cmix_proto::PrePre> arena;
+ cmix_proto::PrePre& prepre = arena.get();
size_t len = get_group_element_array_size(&cmix_ctx);
std::vector<char*> r_er(cmix_ctx.nr_participants, nullptr);
@@ -222,7 +203,8 @@ void Node::start_precomputation() {
void Node::start_realtime_phase() {
- cmix_proto::RealPre realpre;
+ ArenaMessage<cmix_proto::RealPre> arena;
+ cmix_proto::RealPre& realpre = arena.get();
size_t len = get_group_element_array_size(&cmix_ctx);
diff --git a/node/node.hpp b/node/node.hpp
index a058916..3233ba2 100644
--- a/node/node.hpp
+++ b/node/node.hpp
@@ -9,6 +9,7 @@
#include "cmix.h"
#include "cmix.pb.h"
+#include <google/protobuf/arena.h>
#include <boost/asio/io_service.hpp>
@@ -49,6 +50,15 @@ struct NodeNetworkSettings {
unsigned int minimum_nr_messages; ///< The minimum number of available messages before starting to run a mix;
};
+template <typename T>
+struct ArenaMessage {
+ google::protobuf::Arena arena;
+
+ T& get() {
+ return *google::protobuf::Arena::CreateMessage<T>(&arena);
+ }
+};
+
/*!
* \brief The Node class
*/
diff --git a/node/node_node.cpp b/node/node_node.cpp
index d859da9..27e8042 100644
--- a/node/node_node.cpp
+++ b/node/node_node.cpp
@@ -2,7 +2,7 @@
#include "node.hpp"
template <typename T>
-cmix_proto::PrePre fill_precomputation_pre_message(CMixContext& ctx, T const& rs, T const& ms) {
+void fill_precomputation_pre_message(CMixContext& ctx, cmix_proto::PrePre& prepre, T const& rs, T const& ms) {
if(start_mix(&ctx, rs.size()) != no_error) {
exit(-1);
}
@@ -18,8 +18,6 @@ cmix_proto::PrePre fill_precomputation_pre_message(CMixContext& ctx, T const& rs
}
BOOST_LOG_TRIVIAL(trace) << ss.str();
- cmix_proto::PrePre prepre;
-
size_t len = get_group_element_array_size(&ctx);
std::vector<char*> r_ers(ms.size(), nullptr);
std::vector<char*> m_ers(ms.size(), nullptr);
@@ -48,14 +46,10 @@ cmix_proto::PrePre fill_precomputation_pre_message(CMixContext& ctx, T const& rs
) != no_error) {
exit(-1);
}
-
- return prepre;
}
template <typename T>
-cmix_proto::PreMix fill_precomputation_mix_message(CMixContext const& ctx, T const& rs, T const& ms) {
- cmix_proto::PreMix premix;
-
+void fill_precomputation_mix_message(CMixContext const& ctx, cmix_proto::PreMix& premix, T const& rs, T const& ms) {
size_t el_len = get_group_element_array_size(&ctx);
std::vector<char*> r_epirs(ms.size(), nullptr);
std::vector<char*> m_epirs(ms.size(), nullptr);
@@ -81,13 +75,10 @@ cmix_proto::PreMix fill_precomputation_mix_message(CMixContext const& ctx, T con
rsv.data(),
msv.data()
);
- return premix;
}
template <typename T>
-cmix_proto::PrePost fill_precomputation_post_message(CMixContext& ctx, T const& rs, T const& ms) {
- cmix_proto::PrePost prepost;
-
+void fill_precomputation_post_message(CMixContext& ctx, cmix_proto::PrePost& prepost, T const& rs, T const& ms) {
size_t len = get_group_element_array_size(&ctx);
std::vector<char*> r_epirs(ms.size(), nullptr);
@@ -114,14 +105,10 @@ cmix_proto::PrePost fill_precomputation_post_message(CMixContext& ctx, T const&
rsv.data(),
msv.data()
);
-
- return prepost;
}
template <typename T>
-cmix_proto::RealPre fill_realtime_pre_message(CMixContext& ctx, T const& hs, T const& ms, Node::ClientData const& data) {
- cmix_proto::RealPre realpre;
-
+void fill_realtime_pre_message(CMixContext& ctx, cmix_proto::RealPre& realpre, T const& hs, T const& ms, Node::ClientData const& data) {
size_t len = get_group_element_array_size(&ctx);
std::vector<char*> msv1(ms.size(), nullptr);
@@ -146,14 +133,10 @@ cmix_proto::RealPre fill_realtime_pre_message(CMixContext& ctx, T const& hs, T c
msv2.data(),
gs.data()
);
-
- return realpre;
}
template <typename T>
-cmix_proto::RealMix fill_realtime_mix_message(CMixContext& ctx, T const& ms) {
- cmix_proto::RealMix realmix;
-
+void fill_realtime_mix_message(CMixContext& ctx, cmix_proto::RealMix& realmix, T const& ms) {
size_t len = get_group_element_array_size(&ctx);
std::vector<char*> mv(ms.size(), nullptr);
std::vector<char const*> msv(ms.size(), nullptr);
@@ -170,8 +153,6 @@ cmix_proto::RealMix fill_realtime_mix_message(CMixContext& ctx, T const& ms) {
mv.data(),
msv.data()
);
-
- return realmix;
}
void Node::handle_node_initialization(const cmix_proto::Initialization& init)
@@ -209,20 +190,28 @@ void Node::handle_node_secretkey(cmix_proto::SecretKey const& secret)
void Node::handle_node_prepre(cmix_proto::PrePre const& pre) {
if(network_settings.is_first) {
- cmix_proto::PreMix premix = fill_precomputation_mix_message(cmix_ctx, pre.r_er(), pre.m_er());
+ ArenaMessage<cmix_proto::PreMix> arena;
+ auto& premix = arena.get();
+ fill_precomputation_mix_message(cmix_ctx, premix, pre.r_er(), pre.m_er());
next_node.async_send(premix);
} else {
- cmix_proto::PrePre prepre = fill_precomputation_pre_message(cmix_ctx, pre.r_er(), pre.m_er());
+ ArenaMessage<cmix_proto::PrePre> arena;
+ auto& prepre = arena.get();
+ fill_precomputation_pre_message(cmix_ctx, prepre, pre.r_er(), pre.m_er());
next_node.async_send(prepre);
}
}
void Node::handle_node_premix(cmix_proto::PreMix const& premix) {
if(network_settings.is_first) {
- cmix_proto::PrePost prepost = fill_precomputation_post_message(cmix_ctx, premix.r_epirs(), premix.m_epirs());
+ ArenaMessage<cmix_proto::PrePost> arena;
+ auto& prepost = arena.get();
+ fill_precomputation_post_message(cmix_ctx, prepost, premix.r_epirs(), premix.m_epirs());
next_node.async_send(prepost);
} else {
- cmix_proto::PreMix n_premix = fill_precomputation_mix_message(cmix_ctx, premix.r_epirs(), premix.m_epirs());
+ ArenaMessage<cmix_proto::PreMix> arena;
+ auto& n_premix = arena.get();
+ fill_precomputation_mix_message(cmix_ctx, n_premix, premix.r_epirs(), premix.m_epirs());
next_node.async_send(n_premix);
}
}
@@ -231,17 +220,23 @@ void Node::handle_node_prepost(cmix_proto::PrePost const& prepost) {
if(network_settings.is_first) {
start_realtime_phase();
} else {
- cmix_proto::PrePost n_prepost = fill_precomputation_post_message(cmix_ctx, prepost.r_epirs(), prepost.m_epirs());
+ ArenaMessage<cmix_proto::PrePost> arena;
+ auto& n_prepost = arena.get();
+ fill_precomputation_post_message(cmix_ctx, n_prepost, prepost.r_epirs(), prepost.m_epirs());
next_node.async_send(n_prepost);
}
}
void Node::handle_node_realpre(cmix_proto::RealPre const& realpre) {
if(network_settings.is_first) {
- cmix_proto::RealMix n_realmix = fill_realtime_mix_message(cmix_ctx, realpre.m());
- next_node.async_send(n_realmix);
+ ArenaMessage<cmix_proto::RealMix> arena;
+ auto& realmix = arena.get();
+ fill_realtime_mix_message(cmix_ctx, realmix, realpre.m());
+ next_node.async_send(realmix);
} else {
- cmix_proto::RealPre n_realpre = fill_realtime_pre_message(cmix_ctx, realpre.h(), realpre.m(), data);
+ ArenaMessage<cmix_proto::RealPre> arena;
+ auto& n_realpre = arena.get();
+ fill_realtime_pre_message(cmix_ctx, n_realpre, realpre.h(), realpre.m(), data);
next_node.async_send(n_realpre);
}
}
@@ -250,7 +245,9 @@ void Node::handle_node_realmix(cmix_proto::RealMix const& realmix) {
if(network_settings.is_last) {
BOOST_LOG_TRIVIAL(trace) << "Doing the last step:";
- cmix_proto::RealMix n_realmix = fill_realtime_mix_message(cmix_ctx, realmix.m());
+ ArenaMessage<cmix_proto::RealMix> arena;
+ auto& n_realmix = arena.get();
+ fill_realtime_mix_message(cmix_ctx, n_realmix, realmix.m());
size_t len = get_group_element_array_size(&cmix_ctx);
std::string str;
@@ -284,7 +281,9 @@ void Node::handle_node_realmix(cmix_proto::RealMix const& realmix) {
free(payload);
}
} else {
- cmix_proto::RealMix n_realmix = fill_realtime_mix_message(cmix_ctx, realmix.m());
+ ArenaMessage<cmix_proto::RealMix> arena;
+ auto& n_realmix = arena.get();
+ fill_realtime_mix_message(cmix_ctx, n_realmix, realmix.m());
next_node.async_send(n_realmix);
}
}
diff --git a/run.sh b/run.sh
index 7592705..1adca4f 100755
--- a/run.sh
+++ b/run.sh
@@ -2,32 +2,40 @@
build_dir=/home/dennis/projects/cmix/build-cmix-Desktop-Default
+if [ $1 == "benchmark" ] ; then
+ tool="valgrind --tool=cachegrind"
+elif [ $1 == "valgrind" ] ; then
+ tool="valgrind --leak-check=yes --track-origins=yes"
+else
+ tool=""
+fi
+
tmux new-session -s cmix -d
-tmux send-keys -t cmix:0 "cd ${build_dir} && LSAN_OPTIONS=report_objects=1 node/node -f -m 5 -n node2.local:9201 -c ../certs/cert1.pem -k ../certs/key1.pem -d ../certs/dh.pem --certdir ../certs/" Enter
+tmux send-keys -t cmix:0 "cd ${build_dir} && LSAN_OPTIONS=report_objects=1 $tool node/node -f -m 5 -n node2.local:9201 -c ../certs/cert1.pem -k ../certs/key1.pem -d ../certs/dh.pem --certdir ../certs/" Enter
#tmux send-keys -t cmix:0 "r" Enter
tmux new-window -t cmix:1
-tmux send-keys -t cmix:1 "cd ${build_dir} && LSAN_OPTIONS=report_objects=1 node/node -p 9201 -n node3.local:9202 -c ../certs/cert2.pem -k ../certs/key2.pem -d ../certs/dh.pem --certdir ../certs/" Enter
+tmux send-keys -t cmix:1 "cd ${build_dir} && LSAN_OPTIONS=report_objects=1 $tool node/node -p 9201 -n node3.local:9202 -c ../certs/cert2.pem -k ../certs/key2.pem -d ../certs/dh.pem --certdir ../certs/" Enter
#tmux send-keys -t cmix:1 "r" Enter
tmux new-window -t cmix:2
-tmux send-keys -t cmix:2 "cd ${build_dir} && LSAN_OPTIONS=report_objects=1 node/node -l -p 9202 -n node1.local:9200 -c ../certs/cert3.pem -k ../certs/key3.pem -d ../certs/dh.pem --certdir ../certs/" Enter
+tmux send-keys -t cmix:2 "cd ${build_dir} && LSAN_OPTIONS=report_objects=1 $tool node/node -l -p 9202 -n node1.local:9200 -c ../certs/cert3.pem -k ../certs/key3.pem -d ../certs/dh.pem --certdir ../certs/" Enter
#tmux send-keys -t cmix:2 "r" Enter
tmux new-window -t cmix:3
-tmux send-keys -t cmix:3 "cd ${build_dir} && LSAN_OPTIONS=report_objects=1 client/client --certdir ../certs -n node1.local:9200 node2.local:9201 node3.local:9202" Enter
+tmux send-keys -t cmix:3 "cd ${build_dir} && LSAN_OPTIONS=report_objects=1 $tool client/client --certdir ../certs -n node1.local:9200 node2.local:9201 node3.local:9202" Enter
tmux new-window -t cmix:4
-tmux send-keys -t cmix:4 "cd ${build_dir} && LSAN_OPTIONS=report_objects=1 client/client --certdir ../certs -n node1.local:9200 node2.local:9201 node3.local:9202" Enter
+tmux send-keys -t cmix:4 "cd ${build_dir} && LSAN_OPTIONS=report_objects=1 $tool client/client --certdir ../certs -n node1.local:9200 node2.local:9201 node3.local:9202" Enter
tmux new-window -t cmix:5
-tmux send-keys -t cmix:5 "cd ${build_dir} && LSAN_OPTIONS=report_objects=1 client/client --certdir ../certs -n node1.local:9200 node2.local:9201 node3.local:9202" Enter
+tmux send-keys -t cmix:5 "cd ${build_dir} && LSAN_OPTIONS=report_objects=1 $tool client/client --certdir ../certs -n node1.local:9200 node2.local:9201 node3.local:9202" Enter
tmux new-window -t cmix:6
-tmux send-keys -t cmix:6 "cd ${build_dir} && LSAN_OPTIONS=report_objects=1 client/client --certdir ../certs -n node1.local:9200 node2.local:9201 node3.local:9202" Enter
+tmux send-keys -t cmix:6 "cd ${build_dir} && LSAN_OPTIONS=report_objects=1 $tool client/client --certdir ../certs -n node1.local:9200 node2.local:9201 node3.local:9202" Enter
tmux new-window -t cmix:7
-tmux send-keys -t cmix:7 "cd ${build_dir} && LSAN_OPTIONS=report_objects=1 client/client --certdir ../certs -n node1.local:9200 node2.local:9201 node3.local:9202" Enter
+tmux send-keys -t cmix:7 "cd ${build_dir} && LSAN_OPTIONS=report_objects=1 $tool client/client --certdir ../certs -n node1.local:9200 node2.local:9201 node3.local:9202" Enter
tmux attach