PageRenderTime 38ms CodeModel.GetById 28ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

/mordor/examples/netbench.h

http://github.com/mozy/mordor
C Header | 113 lines | 61 code | 26 blank | 26 comment | 0 complexity | 5387918e09cdeae617fdad04f984c18d MD5 | raw file
  1#ifndef NET_BENCH_SERVER_H__
  2#define NET_BENCH_SERVER_H__
  3
  4#include <boost/function.hpp>
  5#include <boost/date_time/posix_time/posix_time_types.hpp>
  6
  7class NetBenchServer
  8{
  9public:
 10    virtual ~NetBenchServer() {}
 11
 12    // start the implementation of the server to be benchmarked
 13    virtual void run(std::string& host,
 14                     size_t perConnToRead,
 15                     size_t perConnToWrite,
 16                     boost::function<void()> done) = 0;
 17
 18    // called when the test is over prior to destructor
 19    virtual void stop() = 0;
 20};
 21
 22class NetBenchClient
 23{
 24public:
 25    virtual ~NetBenchClient () {}
 26
 27    // initialize the client to be benchmarked
 28    virtual void init(std::string& host,
 29                      size_t perConnToRead, size_t perConnToWrite,
 30                      boost::function<void()> done) = 0;
 31
 32    // connect the requested number of clients and make some active.
 33    // each active client should run iters worth of iterations of
 34    // reads/writes using the parameters given in the init() call
 35    virtual void prepClientsForNextRound(size_t newClients,
 36                                         size_t newActive,
 37                                         size_t iters,
 38                                         boost::function<void()> done) = 0;
 39
 40    // implementers are encouraged to actually tally numOps in the done
 41    // callback so that we can check to make sure that we did the work
 42    // that we expected to
 43    virtual void startRound(boost::function<void(size_t numOps)> done) = 0;
 44
 45    // called when the test is over prior to destructor
 46    virtual void stop() = 0;
 47};
 48
 49class NetBench
 50{
 51public:
 52    NetBench(int argc, char* argv[]);
 53
 54    // Kick off the actual benchmark run
 55    void run(NetBenchServer* server, NetBenchClient* client);
 56
 57protected:
 58    void parseOptions(int argc, char* argv[]);
 59    void serverRunning();
 60    void runClient();
 61    void initRound();
 62    void clientsReady();
 63    void roundDone(size_t actualOps);
 64
 65public:
 66    // Benchmark parameters
 67    std::string m_host;
 68    bool m_runServer;
 69    bool m_runClient;
 70    bool m_powTwo;
 71    size_t m_maxConns;
 72    size_t m_maxActive;
 73    size_t m_numBytes;
 74
 75    // Benchmark state
 76
 77    // Server implementation
 78    NetBenchServer* m_server;
 79
 80    // Client implementation
 81    NetBenchClient* m_client;
 82
 83    // round that we are on, i.e. a batch of clients (both active
 84    // and inactive) connect to the server and do their work
 85    int m_round;
 86
 87    // Total number of connected clients
 88    size_t m_totalConns;
 89
 90    // Total number of active clients
 91    size_t m_totalActive;
 92
 93    // Total number of new connections to create in the next round
 94    size_t m_newConns;
 95
 96    // Number of new active connections to create in the next round
 97    size_t m_newActive;
 98
 99    // Number of iterations for each active client in the round
100    size_t m_iters;
101
102    // Total number of clients that have completed the round
103    size_t m_numDone;
104
105    // Total number of ops completed in the round (should be
106    // equal to m_maxActive * m_iters at the end)
107    size_t m_numOps;
108
109    // us at the start of the round
110    boost::posix_time::ptime m_start;
111};
112
113#endif