Skip to content
This repository
Browse code

basic framework

  • Loading branch information...
commit 2acf16c8483bc6004c88504fa4f75f3d41db9133 1 parent 116a1e4
Erik Frey erikfrey authored
2  .gitignore
@@ -8,7 +8,7 @@ cmake_install.cmake
8 8 # makefile output
9 9 darner
10 10 !include/darner
11   -bench_queue_flood
  11 +db
12 12 test
13 13 # sublimetext 2 stuff
14 14 *.sublime-project
10 CMakeLists.txt
@@ -20,12 +20,8 @@ ADD_EXECUTABLE(darner
20 20 src/main
21 21 )
22 22
23   -ADD_EXECUTABLE(bench_queue_flood
24   - bench/queue_flood
25   - src/queue/iqstream
26   - src/queue/oqstream
27   - src/queue/queue
28   - src/util/log
  23 +ADD_EXECUTABLE(db
  24 + bench/db
29 25 )
30 26
31 27 ADD_EXECUTABLE(test
@@ -42,5 +38,5 @@ ADD_EXECUTABLE(test
42 38 FIND_PACKAGE(Boost 1.46.1 COMPONENTS thread system program_options unit_test_framework filesystem)
43 39
44 40 TARGET_LINK_LIBRARIES(darner pthread ${Boost_LIBRARIES} leveldb)
45   -TARGET_LINK_LIBRARIES(bench_queue_flood pthread ${Boost_LIBRARIES} leveldb)
  41 +TARGET_LINK_LIBRARIES(db ${Boost_LIBRARIES})
46 42 TARGET_LINK_LIBRARIES(test pthread ${Boost_LIBRARIES} leveldb)
65 bench/db.cpp
... ... @@ -0,0 +1,65 @@
  1 +#include <iostream>
  2 +
  3 +#include <boost/thread.hpp>
  4 +#include <boost/program_options.hpp>
  5 +
  6 +using namespace std;
  7 +using namespace boost;
  8 +namespace po = boost::program_options;
  9 +
  10 +int main(int argc, char * argv[])
  11 +{
  12 + po::options_description generic("Generic options");
  13 +
  14 + size_t port, num_gets, num_sets, workers;
  15 +
  16 + // options only available via command-line
  17 + generic.add_options()
  18 + ("version,v", "prints the version and exits")
  19 + ("help,h", "produce help message")
  20 + ("port,p", po::value<size_t>(&port), "port to establish connections")
  21 + ("gets,g", po::value<size_t>(&num_gets)->default_value(10000), "number of gets to issue")
  22 + ("sets,s", po::value<size_t>(&num_sets)->default_value(10000), "number of sets to issue")
  23 + ("concurrency,c", po::value<size_t>(&workers)->default_value(10), "number of concurrent workers");
  24 +
  25 + po::options_description cmdline_options;
  26 + cmdline_options.add(generic);
  27 +
  28 + po::variables_map vm;
  29 + try
  30 + {
  31 + po::store(po::command_line_parser(argc, argv).options(cmdline_options).run(), vm);
  32 + notify(vm);
  33 + }
  34 + catch (const po::error & e)
  35 + {
  36 + cout << "error parsing commandline options: " << e.what() << endl;
  37 + cout << cmdline_options << endl;
  38 + return 1;
  39 + }
  40 +
  41 + if (vm.count("help"))
  42 + {
  43 + cout << "db: darner bench. performs benchmarks of concurrent gets and sets of a darner server." << endl;
  44 + cout << "usage: db -p <port>" << endl;
  45 + cout << cmdline_options << endl;
  46 + return 0;
  47 + }
  48 +
  49 + if (vm.count("version"))
  50 + {
  51 + cout << DARNER_VERSION << endl;
  52 + return 0;
  53 + }
  54 +
  55 + if (!vm.count("port"))
  56 + {
  57 + cout << "please specify a port (-p)" << endl;
  58 + cout << "db --help for help" << endl;
  59 + return 1;
  60 + }
  61 +
  62 + cout << "woohoo" << endl;
  63 +
  64 + return 0;
  65 +}
113 bench/queue_flood.cpp
... ... @@ -1,113 +0,0 @@
1   -#include <iostream>
2   -#include <sstream>
3   -
4   -#include <boost/lexical_cast.hpp>
5   -#include <boost/date_time/posix_time/posix_time.hpp>
6   -
7   -#include <darner/queue/queue.h>
8   -#include <darner/queue/iqstream.h>
9   -#include <darner/queue/oqstream.h>
10   -
11   -using namespace std;
12   -using namespace boost;
13   -using namespace boost::asio;
14   -using namespace darner;
15   -
16   -class event_loop
17   -{
18   -public:
19   -
20   - event_loop(size_t item_size, size_t num_pushpops)
21   - : q_(ios_, "tmp"),
22   - os_(q_, 1),
23   - is_(q_, 100),
24   - push_cb_(bind(&event_loop::push_cb, this, asio::placeholders::error)),
25   - pop_cb_(bind(&event_loop::pop_cb, this, asio::placeholders::error)),
26   - pop_end_cb_(bind(&event_loop::pop_end_cb, this, asio::placeholders::error)),
27   - pushes_(num_pushpops),
28   - pops_(num_pushpops)
29   - {
30   - string chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$^&*()";
31   - ostringstream oss;
32   - for (; item_size != 0; --item_size)
33   - oss << chars[rand() % chars.size()];
34   - value_ = oss.str();
35   - }
36   -
37   - void go()
38   - {
39   - os_.write(value_, push_cb_);
40   - is_.read(result_, pop_cb_);
41   - ios_.run();
42   - }
43   -
44   -private:
45   -
46   - void push_cb(const system::error_code& error)
47   - {
48   - if (--pushes_ > 0)
49   - {
50   - new (&os_) oqstream(q_, 1);
51   - ios_.post(bind(&oqstream::write, &os_, ref(value_), push_cb_));
52   - }
53   - }
54   -
55   - void pop_cb(const system::error_code& error)
56   - {
57   - if (!error)
58   - is_.close(true, pop_end_cb_);
59   - }
60   -
61   - void pop_end_cb(const system::error_code& error)
62   - {
63   - if (result_ != value_)
64   - std::cout << "WAAAA" << std::endl;
65   - if (--pops_ > 0)
66   - {
67   - new (&is_) iqstream(q_, 100);
68   - ios_.post(bind(&iqstream::read, &is_, ref(result_), pop_cb_));
69   - }
70   - }
71   -
72   - io_service ios_;
73   - queue q_;
74   -
75   - oqstream os_;
76   - iqstream is_;
77   - oqstream::success_callback push_cb_;
78   - iqstream::success_callback pop_cb_;
79   - iqstream::success_callback pop_end_cb_;
80   - string value_;
81   - string result_;
82   - size_t pushes_;
83   - size_t pops_;
84   -};
85   -
86   -// tests queue: simple flood, one producer one consumer
87   -int main(int argc, char * argv[])
88   -{
89   - if (argc != 3)
90   - {
91   - cerr << "queue-flood: reports in ms how long it takes to drive <num-pushpops> push/pops" << endl;
92   - cerr << "of items length <item-size> with one producer and one consumer" << endl;
93   - cerr << "usage: " << argv[0] << " <item-size> <num-pushpops>" << endl;
94   - return 1;
95   - }
96   -
97   - size_t item_size = lexical_cast<size_t>(argv[1]);
98   - size_t num_pushpops = lexical_cast<size_t>(argv[2]);
99   -
100   - event_loop e(item_size, num_pushpops);
101   -
102   - posix_time::ptime start(posix_time::microsec_clock::local_time());
103   -
104   - e.go();
105   -
106   - posix_time::ptime end(posix_time::microsec_clock::local_time());
107   -
108   - cout << "item size: " << item_size << endl;
109   - cout << num_pushpops << " pushes/pops took " << (end - start).total_milliseconds() << " ms" << endl;
110   - cout << static_cast<float>((end - start).total_microseconds()) / num_pushpops << " us per push/pop " << endl;
111   -
112   - return 0;
113   -}

0 comments on commit 2acf16c

Please sign in to comment.
Something went wrong with that request. Please try again.