Skip to content

Commit

Permalink
Merge pull request #58 from lysevi/dev
Browse files Browse the repository at this point in the history
release v0.0.3

* page is chunk container
* more tests
* Chunk pool
* speed up
  • Loading branch information
lysevi committed Apr 13, 2016
2 parents 9fc91f1 + a302dfb commit 496a0ed
Show file tree
Hide file tree
Showing 83 changed files with 4,358 additions and 1,252 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
tmp
packages.config
.vs
*.page
*.dll
*.lib
*-prefix
*.VC.db
*.opendb
Expand All @@ -18,6 +23,7 @@ CTestTestFile.cmake
*.ctestcase
Debug
Release
RelWithDebInfo
*.exe
*.dir
*.sdf
Expand Down
18 changes: 3 additions & 15 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,30 +1,18 @@
build_image: shippableimages/ubuntu1404_python
sudo: required
dist: trusty
language: cpp
compiler:
- clang
- gcc

before_install:
#- pip install --user cpp-coveralls
- sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test
- sudo add-apt-repository -y ppa:apokluda/boost1.53
- sudo apt-get update -qq
- sudo apt-get update
- sudo apt-get install libboost1.53-all-dev
- sudo apt-get install -y cmake
- sudo apt-get install -y libboost-dev libboost-filesystem-dev libboost-test-dev cmake

install:
- sudo apt-get install -qq g++-4.8
- export CXX="g++-4.8"
- cd ${TRAVIS_BUILD_DIR}
- gcc --version

before_script:
- cmake .

script:
- make -j2
#&& ctest .

#after_success:
# - coveralls --exclude libmemseries --exclude tests --gcov-options '\-lp'
38 changes: 33 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,20 @@ IF(WIN32)
MESSAGE(STATUS "+ boost root: " ${BOOST_ROOT})

if(MSVC)
find_package(Boost 1.57.0 REQUIRED unit_test_framework)
find_package(Boost 1.57.0 REQUIRED unit_test_framework system filesystem)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc")
add_cxx_compiler_flag(-W4)
add_definitions(-DMSVC)
else(MSVC)
find_package(Boost 1.57.0 REQUIRED unit_test_framework)
find_package(Boost 1.57.0 REQUIRED unit_test_framework system filesystem)
endif(MSVC)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_WIN32_WINNT=0x0501")
set(CMAKE_CXX_FLAGS_RELEASE "/Ox /GT /Ot -DNDEBUG")
else(WIN32)
set(BoostUSESTATIC_LIBS OFF)

find_package(Boost REQUIRED unit_test_framework)
find_package(Boost REQUIRED unit_test_framework system filesystem)

set(CMAKE_CXX_FLAGS_COVERAGE "${CMAKE_CXX_FLAGS_DEBUG}" CACHE STRING
"Flags used by the C++ compiler during coverage builds."
Expand Down Expand Up @@ -89,6 +89,7 @@ else(Boost_FOUND)
ENDIF(Boost_FOUND)

if(CMAKE_COMPILER_IS_GNUCXX)
MESSAGE(STATUS "gcc compiller")
add_definitions(-DGNU_CPP)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -ftemplate-backtrace-limit=0")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -pedantic -Werror -pedantic-errors")
Expand All @@ -110,14 +111,41 @@ if(CMAKE_COMPILER_IS_GNUCXX)
#set(CMAKE_SHARED_LINKER_FLAGS "-pg")
endif(CMAKE_COMPILER_IS_GNUCXX)

if(CMAKE_COMPILER_IS_CLANG)
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
MESSAGE(STATUS "clang compiller")
add_definitions(-DCLANG_CPP)
endif(CMAKE_COMPILER_IS_CLANG)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -ftemplate-backtrace-limit=0")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Weverything -Werror -pedantic-errors")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-error=deprecated-declarations -Wno-error=deprecated")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-c++98-compat -Wno-c++98-compat-pedantic")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-return-stack-address -Wno-undef")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-variable -Wno-unused-parameter")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-weak-vtables -Wno-padded")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-global-constructors -Wno-exit-time-destructors")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-shorten-64-to-32 -Wno-sign-conversion")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-missing-prototypes -Wno-missing-variable-declarations")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-shadow -Wno-old-style-cast")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-documentation -Wno-documentation-unknown-command")
#main
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-cast-align -Wno-disabled-macro-expansion")
set(CMAKE_CXX_FLAGS_DEBUG "-O0 -fno-inline -g3 -fstack-protector-all")
set(CMAKE_CXX_FLAGS_RELEASE "-Ofast -g0 -march=native -mtune=native -DNDEBUG")
endif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")

option(ENABLE_TESTING "Enable testing of the dariadb." ON)
option(USE_MUTEX "use mutex or Locker (OFF value)" ON)

if(USE_MUTEX)
MESSAGE(STATUS "def USE_MUTEX")
add_definitions(-DUSE_MUTEX)
else(USE_MUTEX)
MESSAGE(STATUS "undef USE_MUTEX")
endif(USE_MUTEX)

add_subdirectory (libdariadb)

set_property(GLOBAL PROPERTY USE_FOLDERS ON)

if (ENABLE_TESTING)
enable_testing()
add_subdirectory(tests)
Expand Down
12 changes: 8 additions & 4 deletions benchmarks/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,20 @@ MESSAGE(STATUS "Benchmarks: ")

macro(ADD_BENCHARK name src)
MESSAGE(STATUS " +" ${name})
add_executable(${name} ${src})
add_executable(${name} ${src} bench_common.h)

target_link_libraries(${name}
${Boost_LIBRARIES}
libdariadb)

set_target_properties(${name} PROPERTIES FOLDER Benchmarks)
endmacro(ADD_BENCHARK)

ADD_BENCHARK(compression_bench compression_bench.cpp)
ADD_BENCHARK(storage_bench storage_bench.cpp)
ADD_BENCHARK(memstorage_bench memstorage_bench.cpp)
ADD_BENCHARK(hard_benchmark hard_benchmark.cpp)
ADD_BENCHARK(capacitor_bench capacitor_bench.cpp)
ADD_BENCHARK(caches_bench caches_bench.cpp)
ADD_BENCHARK(page_benchmark page_benchmark.cpp)
ADD_BENCHARK(statistic_bench statistic_bench.cpp)
ADD_BENCHARK(thread_bench thread_bench.cpp)
ADD_BENCHARK(storage_hard_benchmark storage_hard_benchmark.cpp)
ADD_BENCHARK(perf_benchmark perf_benchmark.cpp)
31 changes: 31 additions & 0 deletions benchmarks/bench_common.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#pragma once
#include <dariadb.h>
#include <atomic>

namespace dariadb_bench
{
//TODO use cmd line params
const size_t total_threads_count = 5;
const size_t iteration_count = 3000000;

void thread_writer_rnd_stor(
dariadb::Id id,
dariadb::Time sleep_time,
std::atomic_long *append_count,
dariadb::storage::BaseStorage_ptr ms)
{
auto m = dariadb::Meas::empty();
m.time = dariadb::timeutil::current_time();
for (size_t i = 0; i < dariadb_bench::iteration_count; i++) {

m.id = id;
m.flag = dariadb::Flag(id);
m.src = dariadb::Flag(id);
m.time += sleep_time;
m.value = dariadb::Value(i);
ms->append(m);
(*append_count)++;
//std::this_thread::sleep_for(sleep_duration);
}
}
}
175 changes: 175 additions & 0 deletions benchmarks/caches_bench.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
#include <ctime>
#include <iostream>
#include <cstdlib>
#include <iterator>

#include <dariadb.h>
#include <utils/fs.h>
#include <storage/memstorage.h>
#include <storage/capacitor.h>
#include <ctime>
#include <limits>
#include <cmath>
#include <chrono>
#include <thread>
#include <atomic>
#include "bench_common.h"

class BenchCallback :public dariadb::storage::ReaderClb {
public:
void call(const dariadb::Meas&) {
count++;
}
size_t count;
};

std::atomic_long append_count{ 0 }, read_all_times{ 0 };
bool stop_info = false;


bool stop_read_all{ false };

void thread_read_all(
dariadb::Time from,
dariadb::Time to,
dariadb::storage::BaseStorage_ptr ms)
{
auto clb = std::make_shared<BenchCallback>();
while (!stop_read_all) {
auto rdr = ms->readInterval(from, to);
rdr->readAll(clb.get());
read_all_times++;
}
}

void show_info() {
clock_t t0 = clock();
auto all_writes = dariadb_bench::total_threads_count*dariadb_bench::iteration_count;
while (true) {
std::this_thread::sleep_for(std::chrono::milliseconds(300));

clock_t t1 = clock();
auto writes_per_sec = append_count.load() / double((t1 - t0) / CLOCKS_PER_SEC);
//auto read_per_sec = read_all_times.load() / double((t1 - t0) / CLOCKS_PER_SEC);
std::cout << "\rwrites: " << writes_per_sec
<< "/sec progress:" << (100 * append_count) / all_writes
<< "% ";
/*if (!stop_read_all) {
std::cout << " read_all_times: " << read_per_sec <<"/sec ";
}*/
std::cout.flush();
if (stop_info) {
/*std::cout << "\rwrites: " << writes_per_sec
<< "/sec progress:" << (100 * append_count) / all_writes
<< "% ";
if (!stop_read_all) {
std::cout << " read_all_times: " << read_per_sec << "/sec ";
}*/
std::cout.flush();
break;
}
}
std::cout << "\n";
}

int main(int argc, char *argv[]) {
(void)argc;
(void)argv;
{
std::cout << "MemStorage" << std::endl;
dariadb::storage::BaseStorage_ptr ms{ new dariadb::storage::MemoryStorage{ 2000000 } };
std::thread info_thread(show_info);
std::vector<std::thread> writers(dariadb_bench::total_threads_count);
size_t pos = 0;
for (size_t i = 0; i < dariadb_bench::total_threads_count; i++) {
std::thread t{ dariadb_bench::thread_writer_rnd_stor, i,dariadb::Time(i+1),&append_count, ms };
writers[pos++] = std::move(t);
}
//std::thread read_all_t{ thread_read_all, 0, dariadb::Time(iteration_count), ms };

pos = 0;
for (size_t i = 0; i < dariadb_bench::total_threads_count; i++) {
std::thread t = std::move(writers[pos++]);
t.join();
}
stop_info = true;
stop_read_all = true;
info_thread.join();
//read_all_t.join();
}
{
std::cout << "Capacitor" << std::endl;
dariadb::storage::BaseStorage_ptr ms{ new dariadb::storage::MemoryStorage{ 2000000 } };
std::unique_ptr<dariadb::storage::Capacitor> cp{
new dariadb::storage::Capacitor(ms, dariadb::storage::Capacitor::Params(1000,1000))
};

append_count = 0;
stop_info = false;

std::thread info_thread(show_info);
std::vector<std::thread> writers(dariadb_bench::total_threads_count);
size_t pos = 0;
for (size_t i = 0; i < dariadb_bench::total_threads_count; i++) {
std::thread t{ dariadb_bench::thread_writer_rnd_stor, i,dariadb::Time(i),&append_count, ms };
writers[pos++] = std::move(t);
}

pos = 0;
for (size_t i = 0; i < dariadb_bench::total_threads_count; i++) {
std::thread t = std::move(writers[pos++]);
t.join();
}
stop_info = true;
info_thread.join();
cp->flush();
}
{
std::cout << "Union" << std::endl;
const std::string storage_path = "testStorage";
const size_t chunk_per_storage = 1024;
const size_t chunk_size = 512;
const size_t cap_max_size = 10000;
const dariadb::Time write_window_deep = 2000;
const dariadb::Time old_mem_chunks = 0;
const size_t max_mem_chunks = 0;

if (dariadb::utils::fs::path_exists(storage_path)) {
dariadb::utils::fs::rm(storage_path);
}

dariadb::storage::BaseStorage_ptr ms{
new dariadb::storage::UnionStorage(
dariadb::storage::PageManager::Params(storage_path, dariadb::storage::MODE::SINGLE, chunk_per_storage, chunk_size),
dariadb::storage::Capacitor::Params(cap_max_size,write_window_deep),
dariadb::storage::UnionStorage::Limits(max_mem_chunks, old_mem_chunks)) };

append_count = 0;
stop_info = false;
stop_read_all = false;

std::thread info_thread(show_info);
std::vector<std::thread> writers(dariadb_bench::total_threads_count);

size_t pos = 0;
for (size_t i = 0; i < dariadb_bench::total_threads_count; i++) {
std::thread t{ dariadb_bench::thread_writer_rnd_stor, i,dariadb::Time(i),&append_count, ms };
writers[pos++] = std::move(t);
}
//std::thread read_all_t{ thread_read_all, 0, dariadb::Time(iteration_count), ms };

pos = 0;
for (size_t i = 0; i < dariadb_bench::total_threads_count; i++) {
std::thread t = std::move(writers[pos++]);
t.join();
}
stop_info = true;
stop_read_all = true;
info_thread.join();
//read_all_t.join();
ms = nullptr;
if (dariadb::utils::fs::path_exists(storage_path)) {
dariadb::utils::fs::rm(storage_path);
}
}
}
Loading

0 comments on commit 496a0ed

Please sign in to comment.