Permalink
Browse files

basic framework

  • Loading branch information...
1 parent 116a1e4 commit 2acf16c8483bc6004c88504fa4f75f3d41db9133 @erikfrey erikfrey committed Aug 8, 2012
Showing with 69 additions and 121 deletions.
  1. +1 −1 .gitignore
  2. +3 −7 CMakeLists.txt
  3. +65 −0 bench/db.cpp
  4. +0 −113 bench/queue_flood.cpp
View
2 .gitignore
@@ -8,7 +8,7 @@ cmake_install.cmake
# makefile output
darner
!include/darner
-bench_queue_flood
+db
test
# sublimetext 2 stuff
*.sublime-project
View
10 CMakeLists.txt
@@ -20,12 +20,8 @@ ADD_EXECUTABLE(darner
src/main
)
-ADD_EXECUTABLE(bench_queue_flood
- bench/queue_flood
- src/queue/iqstream
- src/queue/oqstream
- src/queue/queue
- src/util/log
+ADD_EXECUTABLE(db
+ bench/db
)
ADD_EXECUTABLE(test
@@ -42,5 +38,5 @@ ADD_EXECUTABLE(test
FIND_PACKAGE(Boost 1.46.1 COMPONENTS thread system program_options unit_test_framework filesystem)
TARGET_LINK_LIBRARIES(darner pthread ${Boost_LIBRARIES} leveldb)
-TARGET_LINK_LIBRARIES(bench_queue_flood pthread ${Boost_LIBRARIES} leveldb)
+TARGET_LINK_LIBRARIES(db ${Boost_LIBRARIES})
TARGET_LINK_LIBRARIES(test pthread ${Boost_LIBRARIES} leveldb)
View
65 bench/db.cpp
@@ -0,0 +1,65 @@
+#include <iostream>
+
+#include <boost/thread.hpp>
+#include <boost/program_options.hpp>
+
+using namespace std;
+using namespace boost;
+namespace po = boost::program_options;
+
+int main(int argc, char * argv[])
+{
+ po::options_description generic("Generic options");
+
+ size_t port, num_gets, num_sets, workers;
+
+ // options only available via command-line
+ generic.add_options()
+ ("version,v", "prints the version and exits")
+ ("help,h", "produce help message")
+ ("port,p", po::value<size_t>(&port), "port to establish connections")
+ ("gets,g", po::value<size_t>(&num_gets)->default_value(10000), "number of gets to issue")
+ ("sets,s", po::value<size_t>(&num_sets)->default_value(10000), "number of sets to issue")
+ ("concurrency,c", po::value<size_t>(&workers)->default_value(10), "number of concurrent workers");
+
+ po::options_description cmdline_options;
+ cmdline_options.add(generic);
+
+ po::variables_map vm;
+ try
+ {
+ po::store(po::command_line_parser(argc, argv).options(cmdline_options).run(), vm);
+ notify(vm);
+ }
+ catch (const po::error & e)
+ {
+ cout << "error parsing commandline options: " << e.what() << endl;
+ cout << cmdline_options << endl;
+ return 1;
+ }
+
+ if (vm.count("help"))
+ {
+ cout << "db: darner bench. performs benchmarks of concurrent gets and sets of a darner server." << endl;
+ cout << "usage: db -p <port>" << endl;
+ cout << cmdline_options << endl;
+ return 0;
+ }
+
+ if (vm.count("version"))
+ {
+ cout << DARNER_VERSION << endl;
+ return 0;
+ }
+
+ if (!vm.count("port"))
+ {
+ cout << "please specify a port (-p)" << endl;
+ cout << "db --help for help" << endl;
+ return 1;
+ }
+
+ cout << "woohoo" << endl;
+
+ return 0;
+}
View
113 bench/queue_flood.cpp
@@ -1,113 +0,0 @@
-#include <iostream>
-#include <sstream>
-
-#include <boost/lexical_cast.hpp>
-#include <boost/date_time/posix_time/posix_time.hpp>
-
-#include <darner/queue/queue.h>
-#include <darner/queue/iqstream.h>
-#include <darner/queue/oqstream.h>
-
-using namespace std;
-using namespace boost;
-using namespace boost::asio;
-using namespace darner;
-
-class event_loop
-{
-public:
-
- event_loop(size_t item_size, size_t num_pushpops)
- : q_(ios_, "tmp"),
- os_(q_, 1),
- is_(q_, 100),
- push_cb_(bind(&event_loop::push_cb, this, asio::placeholders::error)),
- pop_cb_(bind(&event_loop::pop_cb, this, asio::placeholders::error)),
- pop_end_cb_(bind(&event_loop::pop_end_cb, this, asio::placeholders::error)),
- pushes_(num_pushpops),
- pops_(num_pushpops)
- {
- string chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$^&*()";
- ostringstream oss;
- for (; item_size != 0; --item_size)
- oss << chars[rand() % chars.size()];
- value_ = oss.str();
- }
-
- void go()
- {
- os_.write(value_, push_cb_);
- is_.read(result_, pop_cb_);
- ios_.run();
- }
-
-private:
-
- void push_cb(const system::error_code& error)
- {
- if (--pushes_ > 0)
- {
- new (&os_) oqstream(q_, 1);
- ios_.post(bind(&oqstream::write, &os_, ref(value_), push_cb_));
- }
- }
-
- void pop_cb(const system::error_code& error)
- {
- if (!error)
- is_.close(true, pop_end_cb_);
- }
-
- void pop_end_cb(const system::error_code& error)
- {
- if (result_ != value_)
- std::cout << "WAAAA" << std::endl;
- if (--pops_ > 0)
- {
- new (&is_) iqstream(q_, 100);
- ios_.post(bind(&iqstream::read, &is_, ref(result_), pop_cb_));
- }
- }
-
- io_service ios_;
- queue q_;
-
- oqstream os_;
- iqstream is_;
- oqstream::success_callback push_cb_;
- iqstream::success_callback pop_cb_;
- iqstream::success_callback pop_end_cb_;
- string value_;
- string result_;
- size_t pushes_;
- size_t pops_;
-};
-
-// tests queue: simple flood, one producer one consumer
-int main(int argc, char * argv[])
-{
- if (argc != 3)
- {
- cerr << "queue-flood: reports in ms how long it takes to drive <num-pushpops> push/pops" << endl;
- cerr << "of items length <item-size> with one producer and one consumer" << endl;
- cerr << "usage: " << argv[0] << " <item-size> <num-pushpops>" << endl;
- return 1;
- }
-
- size_t item_size = lexical_cast<size_t>(argv[1]);
- size_t num_pushpops = lexical_cast<size_t>(argv[2]);
-
- event_loop e(item_size, num_pushpops);
-
- posix_time::ptime start(posix_time::microsec_clock::local_time());
-
- e.go();
-
- posix_time::ptime end(posix_time::microsec_clock::local_time());
-
- cout << "item size: " << item_size << endl;
- cout << num_pushpops << " pushes/pops took " << (end - start).total_milliseconds() << " ms" << endl;
- cout << static_cast<float>((end - start).total_microseconds()) / num_pushpops << " us per push/pop " << endl;
-
- return 0;
-}

0 comments on commit 2acf16c

Please sign in to comment.