mysql_ubench.cc 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674
  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 <iostream>
  15. #include <sstream>
  16. #include <stdio.h>
  17. #include <string.h>
  18. #include <stdlib.h>
  19. #include <time.h>
  20. #include <mysql.h>
  21. #include "benchmark.h"
  22. #include "mysql_ubench.h"
  23. using namespace std;
  24. MySQL_uBenchmark::MySQL_uBenchmark(const string& hostname, const string& user,
  25. const string& pass, const string& db,
  26. uint32_t num_iterations, bool sync,
  27. bool verbose)
  28. :uBenchmark(num_iterations, db, sync, verbose, hostname, user, pass),
  29. conn_(NULL) {
  30. }
  31. void MySQL_uBenchmark::stmt_failure(MYSQL_STMT * stmt, const char* operation) {
  32. stringstream tmp;
  33. tmp << "Error " << mysql_stmt_errno(stmt) << " during " << operation
  34. << ": " << mysql_stmt_error(stmt);
  35. throw tmp.str();
  36. }
  37. void MySQL_uBenchmark::failure(const char* operation) {
  38. stringstream tmp;
  39. tmp << "Error " << mysql_errno(conn_) << " during " << operation
  40. << ": " << mysql_error(conn_);
  41. throw tmp.str();
  42. }
  43. void MySQL_uBenchmark::connect() {
  44. conn_ = mysql_init(NULL);
  45. if (!conn_) {
  46. failure("initializing MySQL library");
  47. } else {
  48. cout << "MySQL library init successful." << endl;
  49. }
  50. if (!mysql_real_connect(conn_, hostname_.c_str(), user_.c_str(),
  51. passwd_.c_str(), dbname_.c_str(), 0, NULL, 0)) {
  52. failure("connecting to MySQL server");
  53. } else {
  54. cout << "MySQL connection established." << endl;
  55. }
  56. string q = "delete from lease4;";
  57. if (mysql_real_query(conn_, q.c_str(), strlen(q.c_str()))) {
  58. failure("dropping old lease4 entries.");
  59. }
  60. q = "ALTER TABLE lease4 engine=";
  61. if (sync_) {
  62. q += "InnoDB";
  63. } else {
  64. q += "MyISAM";
  65. }
  66. if (mysql_query(conn_, q.c_str())) {
  67. q = "Failed to run query:" + q;
  68. failure(q.c_str());
  69. }
  70. }
  71. void MySQL_uBenchmark::disconnect() {
  72. if (!conn_) {
  73. throw "NULL MySQL connection pointer.";
  74. }
  75. mysql_close(conn_);
  76. conn_ = NULL;
  77. }
  78. void MySQL_uBenchmark::createLease4Test() {
  79. if (!conn_) {
  80. throw "Not connected to MySQL server.";
  81. }
  82. uint32_t addr = BASE_ADDR4; // Let's start with 1.0.0.0 address
  83. char hwaddr[20];
  84. size_t hwaddr_len = 20; // Not a real field
  85. char client_id[128];
  86. size_t client_id_len = 128;
  87. uint32_t valid_lft = 1000; // We can use the same value for all leases
  88. uint32_t recycle_time = 7; // not supported in any foresable future,
  89. char cltt[48]; // timestamp (specified as text)
  90. size_t cltt_len;
  91. sprintf(cltt, "2012-07-11 15:43:00");
  92. cltt_len = strlen(cltt);
  93. uint32_t pool_id = 1000; // Let's use pool-ids greater than zero
  94. bool fixed = false;
  95. char hostname[] = "foo"; // Will generate it dynamically
  96. size_t hostname_len;
  97. hostname_len = strlen(hostname);
  98. bool fqdn_fwd = true; // Let's pretend to do AAAA update
  99. bool fqdn_rev = true; // Let's pretend to do PTR update
  100. cout << "CREATE: ";
  101. for (uint8_t i = 0; i < hwaddr_len; i++) {
  102. hwaddr[i] = 'A' + i; // let's make hwaddr consisting of letters
  103. }
  104. hwaddr[19] = 0; // make it is null-terminated
  105. for (uint8_t i = 0; i < client_id_len; i++) {
  106. client_id[i] = 33 + i; // 33 is being the first, non whitespace
  107. // printable ASCII character
  108. }
  109. client_id[127] = 0; // make it is null-terminated
  110. MYSQL_STMT * stmt = NULL;
  111. MYSQL_BIND bind[11]; // 11 parameters in the insert statement
  112. if (compiled_stmt_) {
  113. // create a statement once
  114. stmt = mysql_stmt_init(conn_);
  115. if (!stmt) {
  116. failure("Unable to create compiled statement, mysql_stmt_init() failed");
  117. }
  118. const char * statement = "INSERT INTO lease4(addr,hwaddr,client_id,"
  119. "valid_lft,recycle_time,cltt,pool_id,fixed,hostname,"
  120. "fqdn_fwd,fqdn_rev) VALUES(?,?,?,?,?,?,?,?,?,?,?)";
  121. if (mysql_stmt_prepare(stmt, statement, strlen(statement) )) {
  122. failure("Failed to prepare statement, mysql_stmt_prepare() returned non-zero");
  123. }
  124. int param_cnt = mysql_stmt_param_count(stmt);
  125. if (param_cnt != 11) {
  126. failure("Parameter count sanity check failed.");
  127. }
  128. memset(bind, 0, sizeof(bind));
  129. // 1st parameter: IPv4 address
  130. bind[0].buffer_type = MYSQL_TYPE_LONG;
  131. bind[0].buffer = (&addr);
  132. bind[0].is_null = 0;
  133. bind[0].length = 0;
  134. // 2nd parameter: Hardware address
  135. bind[1].buffer_type = MYSQL_TYPE_VARCHAR;
  136. bind[1].buffer = hwaddr;
  137. bind[1].buffer_length = hwaddr_len;
  138. bind[1].is_null = 0;
  139. bind[1].length = &hwaddr_len;
  140. // 3rd parameter: Client-id
  141. bind[2].buffer_type = MYSQL_TYPE_VARCHAR;
  142. bind[2].buffer = client_id;
  143. bind[2].buffer_length = client_id_len;
  144. bind[2].is_null = 0;
  145. bind[2].length = &client_id_len;
  146. // 4th parameter: valid-lifetime
  147. bind[3].buffer_type = MYSQL_TYPE_LONG;
  148. bind[3].buffer = (&valid_lft);
  149. bind[3].is_null = 0;
  150. bind[3].length = 0;
  151. // 5th parameter: recycle-time
  152. bind[4].buffer_type = MYSQL_TYPE_LONG;
  153. bind[4].buffer = (&recycle_time);
  154. bind[4].is_null = 0;
  155. bind[4].length = 0;
  156. // 6th parameter: cltt
  157. bind[5].buffer_type = MYSQL_TYPE_TIMESTAMP;
  158. bind[5].buffer = cltt;
  159. bind[2].buffer_length = cltt_len;
  160. bind[5].is_null = 0;
  161. bind[5].length = &cltt_len;
  162. // 7th parameter: pool-id
  163. bind[6].buffer_type = MYSQL_TYPE_LONG;
  164. bind[6].buffer = &pool_id;
  165. bind[6].is_null = 0;
  166. bind[6].length = 0;
  167. // 8th parameter: fixed
  168. bind[7].buffer_type = MYSQL_TYPE_TINY;
  169. bind[7].buffer = &fixed;
  170. bind[7].is_null = 0;
  171. bind[7].length = 0;
  172. // 9th parameter: hostname
  173. bind[8].buffer_type = MYSQL_TYPE_VARCHAR;
  174. bind[8].buffer = hostname;
  175. bind[8].buffer_length = strlen(hostname);
  176. bind[8].is_null = 0;
  177. bind[8].length = &hostname_len;
  178. // 10th parameter: fqdn_fwd
  179. bind[9].buffer_type = MYSQL_TYPE_TINY;
  180. bind[9].buffer = &fqdn_fwd;
  181. bind[9].is_null = 0;
  182. bind[9].length = 0;
  183. // 11th parameter: fqdn_rev
  184. bind[10].buffer_type = MYSQL_TYPE_TINY;
  185. bind[10].buffer = &fqdn_rev;
  186. bind[10].is_null = 0;
  187. bind[10].length = 0;
  188. }
  189. for (uint32_t i = 0; i < num_; i++) {
  190. sprintf(cltt, "2012-07-11 15:43:%02d", i % 60);
  191. addr++;
  192. if (!compiled_stmt_) {
  193. // the first address is 1.0.0.0.
  194. char query[2000], * end;
  195. strcpy(query, "INSERT INTO lease4(addr,hwaddr,client_id,"
  196. "valid_lft,recycle_time,cltt,pool_id,fixed,hostname,"
  197. "fqdn_fwd,fqdn_rev) VALUES(");
  198. end = query + strlen(query);
  199. end += sprintf(end, "%u,\'", addr);
  200. end += mysql_real_escape_string(conn_, end, hwaddr, hwaddr_len);
  201. end += sprintf(end,"\',\'");
  202. end += mysql_real_escape_string(conn_, end, client_id, client_id_len);
  203. end += sprintf(end, "\',%d,%d,'%s',%d,%s,\'%s\',%s,%s);",
  204. valid_lft, recycle_time, cltt,
  205. pool_id, (fixed?"true":"false"), hostname,
  206. (fqdn_fwd?"true":"false"), (fqdn_rev?"true":"false"));
  207. // lease_id field is set automatically
  208. // options and comments fields are not set
  209. unsigned int len = end - query;
  210. if (mysql_real_query(conn_, query, len)) {
  211. // something failed.
  212. failure("INSERT query");
  213. }
  214. } else {
  215. // compiled statement
  216. if (mysql_stmt_bind_param(stmt, bind)) {
  217. failure("Failed to bind parameters: mysql_stmt_bind_param() returned non-zero");
  218. }
  219. if (mysql_stmt_execute(stmt)) {
  220. failure("Failed to execute statement: mysql_stmt_execute() returned non-zero");
  221. }
  222. }
  223. if (verbose_) {
  224. cout << ".";
  225. }
  226. }
  227. if (compiled_stmt_) {
  228. if (mysql_stmt_close(stmt)) {
  229. failure("Failed to close compiled statement, mysql_stmt_close returned non-zero");
  230. }
  231. }
  232. cout << endl;
  233. }
  234. void MySQL_uBenchmark::searchLease4Test() {
  235. if (!conn_) {
  236. throw "Not connected to MySQL server.";
  237. }
  238. cout << "RETRIEVE: ";
  239. uint32_t addr = 0;
  240. MYSQL_STMT * stmt = NULL;
  241. MYSQL_BIND bind[1]; // just a single element
  242. if (compiled_stmt_) {
  243. stmt = mysql_stmt_init(conn_);
  244. if (!stmt) {
  245. failure("Unable to create compiled statement");
  246. }
  247. const char * statement = "SELECT lease_id,addr,hwaddr,client_id,"
  248. "valid_lft, cltt,pool_id,fixed,hostname,fqdn_fwd,fqdn_rev "
  249. "FROM lease4 where addr=?";
  250. if (mysql_stmt_prepare(stmt, statement, strlen(statement))) {
  251. failure("Failed to prepare statement, mysql_stmt_prepare() returned non-zero");
  252. }
  253. int param_cnt = mysql_stmt_param_count(stmt);
  254. if (param_cnt != 1) {
  255. failure("Parameter count sanity check failed.");
  256. }
  257. memset(bind, 0, sizeof(bind));
  258. // 1st parameter: IPv4 address
  259. bind[0].buffer_type = MYSQL_TYPE_LONG;
  260. bind[0].buffer = (&addr);
  261. bind[0].is_null = 0;
  262. bind[0].length = 0;
  263. }
  264. for (uint32_t i = 0; i < num_; i++) {
  265. addr = BASE_ADDR4 + random() % int(num_ / hitratio_);
  266. if (!compiled_stmt_) {
  267. char query[512];
  268. sprintf(query, "SELECT lease_id,addr,hwaddr,client_id,valid_lft,"
  269. "cltt,pool_id,fixed,hostname,fqdn_fwd,fqdn_rev "
  270. "FROM lease4 where addr=%d", addr);
  271. mysql_real_query(conn_, query, strlen(query));
  272. MYSQL_RES * result = mysql_store_result(conn_);
  273. int num_rows = mysql_num_rows(result);
  274. int num_fields = mysql_num_fields(result);
  275. if ( (num_rows > 1) ) {
  276. stringstream tmp;
  277. tmp << "Search: DB returned " << num_rows << " leases for address "
  278. << hex << addr << dec;
  279. failure(tmp.str().c_str());
  280. }
  281. if (num_rows) {
  282. if (num_fields == 0) {
  283. failure("Query returned empty set");
  284. }
  285. MYSQL_ROW row = mysql_fetch_row(result);
  286. // pretend to do something with it
  287. if (row[0] == NULL) {
  288. failure("SELECT returned NULL data.");
  289. }
  290. mysql_free_result(result);
  291. if (verbose_) {
  292. cout << "."; // hit
  293. }
  294. } else {
  295. if (verbose_) {
  296. cout << "x"; // miss
  297. }
  298. }
  299. } else {
  300. // compiled statement
  301. if (mysql_stmt_bind_param(stmt, bind)) {
  302. failure("Failed to bind parameters: mysql_stmt_bind_param() returned non-zero");
  303. }
  304. if (mysql_stmt_execute(stmt)) {
  305. failure("Failed to execute statement: mysql_stmt_execute() returned non-zero");
  306. }
  307. MYSQL_BIND response[11];
  308. size_t length[11];
  309. my_bool is_null[11];
  310. my_bool error[11];
  311. uint32_t lease_id;
  312. uint32_t lease_addr;
  313. char hwaddr[20];
  314. char client_id[128];
  315. uint32_t valid_lft; // We can use the same value for all leases
  316. MYSQL_TIME cltt;
  317. uint32_t pool_id;
  318. my_bool fixed;
  319. char hostname[255];
  320. my_bool fqdn_fwd;
  321. my_bool fqdn_rev;
  322. for (int j = 0; j < 11; j++) {
  323. response[j].is_null = &is_null[j];
  324. response[j].length = &length[j];
  325. response[j].error = &error[j];
  326. }
  327. // 1th parameter: lease_id
  328. response[0].buffer_type = MYSQL_TYPE_LONG;
  329. response[0].buffer = (&lease_id);
  330. // 2nd parameter: IPv4 address
  331. response[1].buffer_type = MYSQL_TYPE_LONG;
  332. response[1].buffer = (&lease_addr);
  333. // 3rd parameter: Hardware address
  334. response[2].buffer_type = MYSQL_TYPE_STRING;
  335. response[2].buffer = hwaddr;
  336. response[2].buffer_length = sizeof(hwaddr);
  337. // 4th parameter: Client-id
  338. response[3].buffer_type = MYSQL_TYPE_STRING;
  339. response[3].buffer = &client_id;
  340. response[3].buffer_length = sizeof(client_id);
  341. // 5th parameter: valid-lifetime
  342. response[4].buffer_type = MYSQL_TYPE_LONG;
  343. response[4].buffer = &valid_lft;
  344. // 6th parameter: cltt
  345. response[5].buffer_type = MYSQL_TYPE_TIMESTAMP;
  346. response[5].buffer = &cltt;
  347. // 7th parameter: pool-id
  348. response[6].buffer_type = MYSQL_TYPE_LONG;
  349. response[6].buffer = &pool_id;
  350. // 8th parameter: fixed
  351. response[7].buffer_type = MYSQL_TYPE_TINY;
  352. response[7].buffer = &fixed;
  353. // 9th parameter: hostname
  354. response[8].buffer_type = MYSQL_TYPE_STRING;
  355. response[8].buffer = &hostname;
  356. // 10th parameter: fqdn_fwd
  357. response[9].buffer_type = MYSQL_TYPE_TINY;
  358. response[9].buffer = &fqdn_fwd;
  359. // 11th parameter: fqdn_rev
  360. response[10].buffer_type = MYSQL_TYPE_TINY;
  361. response[10].buffer = &fqdn_rev;
  362. if (mysql_stmt_bind_result(stmt, response))
  363. {
  364. cout << "Error:" << mysql_stmt_error(stmt) << endl;
  365. failure("mysql_stmt_bind_result() failed");
  366. }
  367. int num_rows = 0;
  368. int result = mysql_stmt_fetch(stmt);
  369. switch (result) {
  370. case 0: {
  371. if (lease_addr != addr) {
  372. failure("Returned data is bogus!");
  373. }
  374. num_rows++;
  375. break;
  376. }
  377. case MYSQL_NO_DATA:
  378. {
  379. // that's ok. We randomized non-existing address
  380. break;
  381. }
  382. default: {
  383. stmt_failure(stmt, "RETRIEVE (mysql_stmt_fetch())");
  384. }
  385. }
  386. // we could call mysql_stmt_fetch again to check that there are no
  387. // other data for us. But there should be exactly one row of data
  388. // with specified address.
  389. if (num_rows) {
  390. if (verbose_) {
  391. cout << "."; // hit
  392. }
  393. } else {
  394. if (verbose_) {
  395. cout << "X"; // miss
  396. }
  397. }
  398. }
  399. }
  400. if (compiled_stmt_) {
  401. if (mysql_stmt_close(stmt)) {
  402. failure("Failed to close compiled statement, mysql_stmt_close returned non-zero");
  403. }
  404. }
  405. cout << endl;
  406. }
  407. void MySQL_uBenchmark::updateLease4Test() {
  408. if (!conn_) {
  409. throw "Not connected to MySQL server.";
  410. }
  411. cout << "UPDATE: ";
  412. uint32_t valid_lft = 1002; // just some dummy value
  413. char cltt[] = "now()";
  414. size_t cltt_len = strlen(cltt);
  415. uint32_t addr = 0;
  416. MYSQL_STMT * stmt = NULL;
  417. MYSQL_BIND bind[3];
  418. if (compiled_stmt_) {
  419. stmt = mysql_stmt_init(conn_);
  420. if (!stmt) {
  421. failure("Unable to create compiled statement");
  422. }
  423. const char * statement = "UPDATE lease4 SET valid_lft=?, cltt=? WHERE addr=?";
  424. if (mysql_stmt_prepare(stmt, statement, strlen(statement))) {
  425. failure("Failed to prepare statement, mysql_stmt_prepare() returned non-zero");
  426. }
  427. int param_cnt = mysql_stmt_param_count(stmt);
  428. if (param_cnt != 3) {
  429. failure("Parameter count sanity check failed.");
  430. }
  431. memset(bind, 0, sizeof(bind));
  432. // 1st parameter: valid lifetime
  433. bind[0].buffer_type = MYSQL_TYPE_LONG;
  434. bind[0].buffer = &valid_lft;
  435. // 2nd parameter: cltt
  436. bind[1].buffer_type = MYSQL_TYPE_STRING;
  437. bind[1].buffer = &cltt;
  438. bind[1].buffer_length = cltt_len;
  439. bind[2].buffer_type = MYSQL_TYPE_LONG;
  440. bind[2].buffer = &addr;
  441. }
  442. for (uint32_t i = 0; i < num_; i++) {
  443. addr = BASE_ADDR4 + random() % num_;
  444. if (!compiled_stmt_) {
  445. char query[128];
  446. sprintf(query, "UPDATE lease4 SET valid_lft=1002, cltt=now() WHERE addr=%d", addr);
  447. mysql_real_query(conn_, query, strlen(query));
  448. } else {
  449. // compiled statement
  450. if (mysql_stmt_bind_param(stmt, bind)) {
  451. failure("Failed to bind parameters: mysql_stmt_bind_param() returned non-zero");
  452. }
  453. if (mysql_stmt_execute(stmt)) {
  454. failure("Failed to execute statement: mysql_stmt_execute() returned non-zero");
  455. }
  456. }
  457. if (verbose_) {
  458. cout << ".";
  459. }
  460. }
  461. if (compiled_stmt_) {
  462. if (mysql_stmt_close(stmt)) {
  463. failure("Failed to close compiled statement, mysql_stmt_close returned non-zero");
  464. }
  465. }
  466. cout << endl;
  467. }
  468. void MySQL_uBenchmark::deleteLease4Test() {
  469. if (!conn_) {
  470. throw "Not connected to MySQL server.";
  471. }
  472. cout << "DELETE: ";
  473. uint32_t addr = 0;
  474. MYSQL_STMT * stmt = NULL;
  475. MYSQL_BIND bind[1]; // just a single element
  476. if (compiled_stmt_) {
  477. stmt = mysql_stmt_init(conn_);
  478. if (!stmt) {
  479. failure("Unable to create compiled statement, mysql_stmt_init() failed");
  480. }
  481. const char * statement = "DELETE FROM lease4 WHERE addr=?";
  482. if (mysql_stmt_prepare(stmt, statement, strlen(statement) )) {
  483. failure("Failed to prepare statement, mysql_stmt_prepare() returned non-zero");
  484. }
  485. int param_cnt = mysql_stmt_param_count(stmt);
  486. if (param_cnt != 1) {
  487. failure("Parameter count sanity check failed.");
  488. }
  489. memset(bind, 0, sizeof(bind));
  490. // 1st parameter: IPv4 address
  491. bind[0].buffer_type = MYSQL_TYPE_LONG;
  492. bind[0].buffer = (&addr);
  493. bind[0].is_null = 0;
  494. bind[0].length = 0;
  495. }
  496. for (uint32_t i = 0; i < num_; i++) {
  497. addr = BASE_ADDR4 + i;
  498. if (!compiled_stmt_) {
  499. char query[128];
  500. sprintf(query, "DELETE FROM lease4 WHERE addr=%d", addr);
  501. mysql_real_query(conn_, query, strlen(query));
  502. } else {
  503. // compiled statement
  504. if (mysql_stmt_bind_param(stmt, bind)) {
  505. failure("Failed to bind parameters: mysql_stmt_bind_param() returned non-zero");
  506. }
  507. if (mysql_stmt_execute(stmt)) {
  508. failure("Failed to execute statement: mysql_stmt_execute() returned non-zero");
  509. }
  510. }
  511. if (verbose_) {
  512. cout << ".";
  513. }
  514. }
  515. if (compiled_stmt_) {
  516. if (mysql_stmt_close(stmt)) {
  517. failure("Failed to close compiled statement, mysql_stmt_close returned non-zero");
  518. }
  519. }
  520. cout << endl;
  521. }
  522. void MySQL_uBenchmark::printInfo() {
  523. cout << "MySQL client version is " << mysql_get_client_info() << endl;
  524. }
  525. int main(int argc, char * const argv[]) {
  526. const char* hostname ="localhost"; // -m (MySQL server)
  527. const char* user = "root"; // -u
  528. const char* passwd = "secret"; // -p
  529. const char* dbname = "kea"; // -f
  530. uint32_t num = 100; // -n
  531. bool sync = true; // -s
  532. bool verbose = true; // -v
  533. MySQL_uBenchmark bench(hostname, user, passwd, dbname, num, sync, verbose);
  534. bench.parseCmdline(argc, argv);
  535. int result = bench.run();
  536. return (result);
  537. }