mysql_ubench.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. // Copyright (C) 2012 Internet Systems Consortium, Inc. ("ISC")
  2. //
  3. // Permission to use, copy, modify, and/or distribute this software for any
  4. // purpose with or without fee is hereby granted, provided that the above
  5. // copyright notice and this permission notice appear in all copies.
  6. //
  7. // THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
  8. // REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  9. // AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
  10. // INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  11. // LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  12. // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  13. // PERFORMANCE OF THIS SOFTWARE.
  14. #include <string>
  15. #include "benchmark.h"
  16. /// @brief MySQL micro-benchmark.
  17. ///
  18. /// That is a specific backend implementation. See \ref uBenchmark class for
  19. /// detailed explanation of its operations. This class uses MySQL as database
  20. /// backend.
  21. class MySQL_uBenchmark: public uBenchmark {
  22. public:
  23. /// @brief The sole MySQL micro-benchmark constructor
  24. ///
  25. /// To avoid influence of network performance, it is highly recommended
  26. /// to run MySQL engine on the same host as benchmark. Thus hostname
  27. /// is likely to be "localhost". Make sure that the selected database
  28. /// is already created and that it follows expected schema. See mysql.schema
  29. /// and isc-dhcp-perf-guide.html for details.
  30. ///
  31. /// Synchronous operation means using InnDB, async is MyISAM.
  32. ///
  33. /// @param hostname Name of the host to connect to
  34. /// @param user usename used during MySQL connection
  35. /// @param pass password used during MySQL connection
  36. /// @param db name of the database to connect to
  37. /// @param num_iterations number of iterations for basic operations
  38. /// @param sync synchronous or asynchronous database writes
  39. /// @param verbose should extra information be logged?
  40. MySQL_uBenchmark(const std::string& hostname, const std::string& user,
  41. const std::string& pass, const std::string& db,
  42. uint32_t num_iterations, bool sync,
  43. bool verbose);
  44. /// @brief Prints MySQL version info.
  45. virtual void printInfo();
  46. /// @brief Opens connection to the MySQL database.
  47. virtual void connect();
  48. /// @brief Closes connection to the MySQL database.
  49. virtual void disconnect();
  50. /// @brief Creates new leases.
  51. ///
  52. /// See uBenchmark::createLease4Test() for detailed explanation.
  53. virtual void createLease4Test();
  54. /// @brief Searches for existing leases.
  55. ///
  56. /// See uBenchmark::searchLease4Test() for detailed explanation.
  57. virtual void searchLease4Test();
  58. /// @brief Updates existing leases.
  59. ///
  60. /// See uBenchmark::updateLease4Test() for detailed explanation.
  61. virtual void updateLease4Test();
  62. /// @brief Deletes existing leases.
  63. ///
  64. /// See uBenchmark::deleteLease4Test() for detailed explanation.
  65. virtual void deleteLease4Test();
  66. protected:
  67. /// @brief Used to report any database failures.
  68. ///
  69. /// Compared to its base version in uBenchmark class, this one logs additional
  70. /// MySQL specific information using mysql_errno() and mysql_error() functions.
  71. /// The outcome is the same: exception is thrown.
  72. void failure(const char* operation);
  73. /// Handle to MySQL database connection.
  74. MYSQL* conn_;
  75. };