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