75 #include "client/client_priv.h"
77 #include "client/option_string.h"
78 #include "client/stats.h"
79 #include "client/thread_context.h"
80 #include "client/conclusions.h"
81 #include "client/wakeup.h"
85 #include <sys/types.h>
87 #ifdef HAVE_SYS_STAT_H
88 # include <sys/stat.h>
97 #include <drizzled/configmake.h>
101 #include <drizzled/gettext.h>
103 #include <boost/algorithm/string.hpp>
104 #include <boost/thread.hpp>
105 #include <boost/thread/mutex.hpp>
106 #include <boost/thread/condition_variable.hpp>
107 #include <boost/program_options.hpp>
108 #include <boost/scoped_ptr.hpp>
109 #include <drizzled/atomics.h>
111 #define SLAP_NAME "drizzleslap"
112 #define SLAP_VERSION "1.5"
114 #define HUGE_STRING_LENGTH 8196
115 #define RAND_STRING_SIZE 126
116 #define DEFAULT_BLOB_SIZE 1024
119 using namespace drizzled;
120 namespace po= boost::program_options;
123 static char *shared_memory_base_name=0;
129 static bool timer_alarm=
false;
130 boost::mutex timer_alarm_mutex;
131 boost::condition_variable_any timer_alarm_threshold;
133 std::vector < std::string > primary_keys;
142 user_supplied_pre_statements,
143 user_supplied_post_statements,
148 static vector<string> user_supplied_queries;
149 static string opt_verbose;
150 std::string opt_protocol;
153 string create_schema_string;
155 static bool use_drizzle_protocol=
false;
156 static bool opt_preserve=
true;
157 static bool opt_only_print;
158 static bool opt_burnin;
159 static bool opt_ignore_sql_errors=
false;
160 static bool opt_silent,
161 auto_generate_sql_autoincrement,
162 auto_generate_sql_guid_primary,
164 std::string opt_auto_generate_sql_type;
166 static int32_t verbose= 0;
167 static uint32_t delimiter_length;
168 static uint32_t commit_rate;
169 static uint32_t detach_rate;
170 static uint32_t opt_timer_length;
171 static uint32_t opt_delayed_start;
172 string num_blob_cols_opt,
176 static uint32_t opt_set_random_seed;
178 string auto_generate_selected_columns_opt;
181 static uint32_t num_int_cols= 1;
182 static uint32_t num_char_cols= 1;
183 static uint32_t num_blob_cols= 0;
184 static uint32_t num_blob_cols_size;
185 static uint32_t num_blob_cols_size_min;
186 static uint32_t num_int_cols_index= 0;
187 static uint32_t num_char_cols_index= 0;
188 static uint32_t iterations;
189 static uint64_t actual_queries= 0;
190 static uint64_t auto_actual_queries;
191 static uint64_t auto_generate_sql_unique_write_number;
192 static uint64_t auto_generate_sql_unique_query_number;
193 static uint32_t auto_generate_sql_secondary_indexes;
194 static uint64_t num_of_query;
195 static uint64_t auto_generate_sql_number;
196 string concurrency_str;
197 string create_string;
198 std::vector <uint32_t> concurrency;
200 std::string opt_csv_str;
203 static int process_options(
void);
204 static uint32_t opt_drizzle_port= 0;
210 static Statement *create_statements= NULL;
212 static std::vector <Statement *> query_statements;
213 static uint32_t query_statements_count;
220 uint32_t parse_comma(
const char *
string, std::vector <uint32_t> &range);
221 uint32_t parse_delimiter(
const char *script,
Statement **stmt,
char delm);
222 uint32_t parse_option(
const char *origin,
OptionString **stmt,
char delm);
223 static void drop_schema(drizzle_con_st &con,
const char *db);
224 uint32_t get_random_string(
char *buf,
size_t size);
225 static Statement *build_table_string(
void);
226 static Statement *build_insert_string(
void);
227 static Statement *build_update_string(
void);
228 static Statement * build_select_string(
bool key);
229 static int generate_primary_key_list(drizzle_con_st &con,
OptionString *engine_stmt);
231 static void run_scheduler(
Stats *sptr,
Statement **stmts, uint32_t concur, uint64_t limit);
234 void concurrency_loop(drizzle_con_st &con, uint32_t current,
OptionString *eptr);
235 static void run_statements(drizzle_con_st &con,
Statement *stmt);
236 drizzle_con_st *slap_connect(
bool connect_to_schema);
237 void slap_close(drizzle_con_st *con);
238 static int run_query(drizzle_con_st &con, drizzle_result_st *result,
const char *query,
int len);
241 static const char ALPHANUMERICS[]=
242 "0123456789ABCDEFGHIJKLMNOPQRSTWXYZabcdefghijklmnopqrstuvwxyz";
244 #define ALPHANUMERICS_SIZE (sizeof(ALPHANUMERICS)-1)
247 static long int timedif(
struct timeval a,
struct timeval b)
251 us = a.tv_usec - b.tv_usec;
253 s = a.tv_sec - b.tv_sec;
258 static void combine_queries(vector<string> queries)
260 user_supplied_query.erase();
261 for (vector<string>::iterator it= queries.begin();
265 user_supplied_query.append(*it);
266 user_supplied_query.append(delimiter);
273 uint64_t counter= 0, queries;
274 uint64_t detach_counter;
275 uint32_t commit_counter;
276 drizzle_result_st result;
280 master_wakeup.wait();
282 drizzle_con_st *con= slap_connect(
true);
286 printf(
"connected!\n");
293 run_query(*con, NULL,
"SET AUTOCOMMIT=0", strlen(
"SET AUTOCOMMIT=0"));
297 for (ptr= ctx->getStmt(), detach_counter= 0;
298 ptr && ptr->getLength();
299 ptr= ptr->getNext(), detach_counter++)
301 if (not opt_only_print && detach_rate && !(detach_counter % detach_rate))
304 con= slap_connect(
true);
310 bool is_failed_update=
false;
311 if ((ptr->getType() == UPDATE_TYPE_REQUIRES_PREFIX) ||
312 (ptr->getType() == SELECT_TYPE_REQUIRES_PREFIX))
315 char buffer[HUGE_STRING_LENGTH];
324 assert(primary_keys.size());
325 if (primary_keys.size())
327 key_val= (uint32_t)(random() % primary_keys.size());
328 const char *key= primary_keys[key_val].c_str();
332 int length= snprintf(buffer, HUGE_STRING_LENGTH,
"%.*s '%s'", (
int)ptr->getLength(), ptr->getString(), key);
334 if (run_query(*con, &result, buffer, length))
336 if ((ptr->getType() == UPDATE_TYPE_REQUIRES_PREFIX) and commit_rate)
341 is_failed_update=
true;
342 failed_update_for_transaction.fetch_and_increment();
346 fprintf(stderr,
"%s: Cannot run query %.*s ERROR : %s\n",
347 SLAP_NAME, (uint32_t)length, buffer, drizzle_con_error(con));
355 if (run_query(*con, &result, ptr->getString(), ptr->getLength()))
357 if ((ptr->getType() == UPDATE_TYPE_REQUIRES_PREFIX) and commit_rate)
362 is_failed_update=
true;
363 failed_update_for_transaction.fetch_and_increment();
367 fprintf(stderr,
"%s: Cannot run query %.*s ERROR : %s\n",
368 SLAP_NAME, (uint32_t)ptr->getLength(), ptr->getString(), drizzle_con_error(con));
374 if (not opt_only_print and not is_failed_update)
376 while ((row = drizzle_row_next(&result)))
378 drizzle_result_free(&result);
382 if (commit_rate && (++commit_counter == commit_rate) and not is_failed_update)
385 run_query(*con, NULL,
"COMMIT", strlen(
"COMMIT"));
389 if (opt_timer_length && timer_alarm ==
false)
393 if (ctx->getLimit() && queries == ctx->getLimit() && timer_alarm ==
false)
397 if (opt_timer_length && timer_alarm ==
true)
400 if (ctx->getLimit() && queries < ctx->getLimit())
407 run_query(*con, NULL,
"COMMIT", strlen(
"COMMIT"));
434 int main(
int argc,
char **argv)
436 std::string stpassword;
440 po::options_description commandline_options(
"Options used only in command line");
441 commandline_options.add_options()
442 (
"help,?",
"Display this help and exit")
443 (
"info",
"Gives information and exit")
444 (
"burnin",po::value<bool>(&opt_burnin)->default_value(
false)->zero_tokens(),
445 "Run full test case in infinite loop")
446 (
"ignore-sql-errors", po::value<bool>(&opt_ignore_sql_errors)->default_value(
false)->zero_tokens(),
447 "Ignore SQL errors in query run")
448 (
"create-schema",po::value<string>(&create_schema_string)->default_value(
"drizzleslap"),
449 "Schema to run tests in")
450 (
"create",po::value<string>(&create_string)->default_value(
""),
451 "File or string to use to create tables")
452 (
"detach",po::value<uint32_t>(&detach_rate)->default_value(0),
453 "Detach (close and re open) connections after X number of requests")
454 (
"iterations,i",po::value<uint32_t>(&iterations)->default_value(1),
455 "Number of times to run the tests")
456 (
"label",po::value<string>(&opt_label)->default_value(
""),
457 "Label to use for print and csv")
458 (
"number-blob-cols",po::value<string>(&num_blob_cols_opt)->default_value(
""),
459 "Number of BLOB columns to create table with if specifying --auto-generate-sql. Example --number-blob-cols=3:1024/2048 would give you 3 blobs with a random size between 1024 and 2048. ")
460 (
"number-char-cols,x",po::value<string>(&num_char_cols_opt)->default_value(
""),
461 "Number of VARCHAR columns to create in table if specifying --auto-generate-sql.")
462 (
"number-int-cols,y",po::value<string>(&num_int_cols_opt)->default_value(
""),
463 "Number of INT columns to create in table if specifying --auto-generate-sql.")
464 (
"number-of-queries",
465 po::value<uint64_t>(&num_of_query)->default_value(0),
466 "Limit each client to this number of queries(this is not exact)")
467 (
"only-print",po::value<bool>(&opt_only_print)->default_value(
false)->zero_tokens(),
468 "This causes drizzleslap to not connect to the database instead print out what it would have done instead")
469 (
"post-query", po::value<string>(&user_supplied_post_statements)->default_value(
""),
470 "Query to run or file containing query to execute after tests have completed.")
471 (
"post-system",po::value<string>(&post_system)->default_value(
""),
472 "system() string to execute after tests have completed")
474 po::value<string>(&user_supplied_pre_statements)->default_value(
""),
475 "Query to run or file containing query to execute before running tests.")
476 (
"pre-system",po::value<string>(&pre_system)->default_value(
""),
477 "system() string to execute before running tests.")
478 (
"query,q",po::value<vector<string> >(&user_supplied_queries)->composing()->notifier(&combine_queries),
479 "Query to run or file containing query")
480 (
"verbose,v", po::value<string>(&opt_verbose)->default_value(
"v"),
"Increase verbosity level by one.")
481 (
"version,V",
"Output version information and exit")
484 po::options_description slap_options(
"Options specific to drizzleslap");
485 slap_options.add_options()
486 (
"auto-generate-sql-select-columns",
487 po::value<string>(&auto_generate_selected_columns_opt)->default_value(
""),
488 "Provide a string to use for the select fields used in auto tests")
489 (
"auto-generate-sql,a",po::value<bool>(&auto_generate_sql)->default_value(
false)->zero_tokens(),
490 "Generate SQL where not supplied by file or command line")
491 (
"auto-generate-sql-add-autoincrement",
492 po::value<bool>(&auto_generate_sql_autoincrement)->default_value(
false)->zero_tokens(),
493 "Add an AUTO_INCREMENT column to auto-generated tables")
494 (
"auto-generate-sql-execute-number",
495 po::value<uint64_t>(&auto_actual_queries)->default_value(0),
496 "See this number and generate a set of queries to run")
497 (
"auto-generate-sql-guid-primary",
498 po::value<bool>(&auto_generate_sql_guid_primary)->default_value(
false)->zero_tokens(),
499 "Add GUID based primary keys to auto-generated tables")
500 (
"auto-generate-sql-load-type",
501 po::value<string>(&opt_auto_generate_sql_type)->default_value(
"mixed"),
502 "Specify test load type: mixed, update, write, key or read; default is mixed")
503 (
"auto-generate-sql-secondary-indexes",
504 po::value<uint32_t>(&auto_generate_sql_secondary_indexes)->default_value(0),
505 "Number of secondary indexes to add to auto-generated tables")
506 (
"auto-generated-sql-unique-query-number",
507 po::value<uint64_t>(&auto_generate_sql_unique_query_number)->default_value(10),
508 "Number of unique queries to generate for automatic tests")
509 (
"auto-generate-sql-unique-write-number",
510 po::value<uint64_t>(&auto_generate_sql_unique_write_number)->default_value(10),
511 "Number of unique queries to generate for auto-generate-sql-write-number")
512 (
"auto-generate-sql-write-number",
513 po::value<uint64_t>(&auto_generate_sql_number)->default_value(100),
514 "Number of row inserts to perform for each thread (default is 100).")
515 (
"commit",po::value<uint32_t>(&commit_rate)->default_value(0),
516 "Commit records every X number of statements")
517 (
"concurrency,c",po::value<string>(&concurrency_str)->default_value(
""),
518 "Number of clients to simulate for query to run")
519 (
"csv",po::value<std::string>(&opt_csv_str)->default_value(
""),
520 "Generate CSV output to named file or to stdout if no file is name.")
521 (
"delayed-start",po::value<uint32_t>(&opt_delayed_start)->default_value(0),
522 "Delay the startup of threads by a random number of microsends (the maximum of the delay")
523 (
"delimiter,F",po::value<string>(&delimiter)->default_value(
"\n"),
524 "Delimiter to use in SQL statements supplied in file or command line")
525 (
"engine,e",po::value<string>(&default_engine)->default_value(
""),
526 "Storage engine to use for creating the table")
528 po::value<uint32_t>(&opt_set_random_seed)->default_value(0),
529 "Seed for random number generator (srandom(3)) ")
530 (
"silent,s",po::value<bool>(&opt_silent)->default_value(
false)->zero_tokens(),
531 "Run program in silent mode - no output. ")
532 (
"timer-length",po::value<uint32_t>(&opt_timer_length)->default_value(0),
533 "Require drizzleslap to run each specific test a certain amount of time in seconds")
536 po::options_description client_options(
"Options specific to the client");
537 client_options.add_options()
538 (
"host,h",po::value<string>(&host)->default_value(
"localhost"),
"Connect to the host")
539 (
"password,P",po::value<std::string >(&stpassword),
540 "Password to use when connecting to server. If password is not given it's asked from the tty")
541 (
"port,p",po::value<uint32_t>(),
"Port number to use for connection")
542 (
"protocol",po::value<string>(&opt_protocol)->default_value(
"mysql"),
543 "The protocol of connection (mysql or drizzle).")
544 (
"user,u",po::value<string>(&user)->default_value(
""),
545 "User for login if not current user")
548 po::options_description long_options(
"Allowed Options");
549 long_options.add(commandline_options).add(slap_options).add(client_options);
551 std::string system_config_dir_slap(SYSCONFDIR);
552 system_config_dir_slap.append(
"/drizzle/drizzleslap.cnf");
554 std::string system_config_dir_client(SYSCONFDIR);
555 system_config_dir_client.append(
"/drizzle/client.cnf");
557 std::string user_config_dir((getenv(
"XDG_CONFIG_HOME")? getenv(
"XDG_CONFIG_HOME"):
"~/.config"));
559 if (user_config_dir.compare(0, 2,
"~/") == 0)
562 homedir= getenv(
"HOME");
564 user_config_dir.replace(0, 1, homedir);
567 uint64_t temp_drizzle_port= 0;
568 boost::scoped_ptr<drizzle_con_st> con_ap(
new drizzle_con_st);
572 int style = po::command_line_style::default_style & ~po::command_line_style::allow_guessing;
574 po::variables_map vm;
575 po::store(po::command_line_parser(argc, argv).options(long_options).
576 style(style).extra_parser(parse_password_arg).run(), vm);
578 std::string user_config_dir_slap(user_config_dir);
579 user_config_dir_slap.append(
"/drizzle/drizzleslap.cnf");
581 std::string user_config_dir_client(user_config_dir);
582 user_config_dir_client.append(
"/drizzle/client.cnf");
584 ifstream user_slap_ifs(user_config_dir_slap.c_str());
585 po::store(parse_config_file(user_slap_ifs, slap_options), vm);
587 ifstream user_client_ifs(user_config_dir_client.c_str());
588 po::store(parse_config_file(user_client_ifs, client_options), vm);
590 ifstream system_slap_ifs(system_config_dir_slap.c_str());
591 store(parse_config_file(system_slap_ifs, slap_options), vm);
593 ifstream system_client_ifs(system_config_dir_client.c_str());
594 store(parse_config_file(system_client_ifs, client_options), vm);
598 if (process_options())
601 if ( vm.count(
"help") || vm.count(
"info"))
603 printf(
"%s Ver %s Distrib %s, for %s-%s (%s)\n",SLAP_NAME, SLAP_VERSION,
604 drizzle_version(),HOST_VENDOR,HOST_OS,HOST_CPU);
605 puts(
"Copyright (C) 2008 Sun Microsystems");
606 puts(
"This software comes with ABSOLUTELY NO WARRANTY. "
607 "This is free software,\n"
608 "and you are welcome to modify and redistribute it under the GPL "
610 puts(
"Run a query multiple times against the server\n");
611 cout << long_options << endl;
615 if (vm.count(
"protocol"))
617 boost::to_lower(opt_protocol);
618 if (not opt_protocol.compare(
"mysql"))
619 use_drizzle_protocol=
false;
620 else if (not opt_protocol.compare(
"drizzle"))
621 use_drizzle_protocol=
true;
624 cout << _(
"Error: Unknown protocol") <<
" '" << opt_protocol <<
"'" << endl;
628 if (vm.count(
"port"))
630 temp_drizzle_port= vm[
"port"].as<uint32_t>();
632 if ((temp_drizzle_port == 0) || (temp_drizzle_port > 65535))
634 fprintf(stderr, _(
"Value supplied for port is not valid.\n"));
639 opt_drizzle_port= (uint32_t) temp_drizzle_port;
643 if ( vm.count(
"password") )
645 if (not opt_password.empty())
646 opt_password.erase();
647 if (stpassword == PASSWORD_SENTINEL)
653 opt_password= stpassword;
664 if ( vm.count(
"version") )
666 printf(
"%s Ver %s Distrib %s, for %s-%s (%s)\n",SLAP_NAME, SLAP_VERSION,
667 drizzle_version(),HOST_VENDOR,HOST_OS,HOST_CPU);
672 if (auto_generate_sql)
674 if (opt_set_random_seed == 0)
675 opt_set_random_seed= (uint32_t)time(NULL);
676 srandom(opt_set_random_seed);
680 delimiter_length= delimiter.length();
682 drizzle_con_st *con= slap_connect(
false);
686 eptr= engine_options;
693 printf(
"Starting Concurrency Test\n");
695 if (concurrency.size())
697 for (current= &concurrency[0]; current && *current; current++)
698 concurrency_loop(*con, *current, eptr);
702 uint32_t infinite= 1;
704 concurrency_loop(*con, infinite, eptr);
709 if (not opt_preserve)
710 drop_schema(*con, create_schema_string.c_str());
712 }
while (eptr ? (eptr= eptr->getNext()) : 0);
722 if (not opt_password.empty())
723 opt_password.erase();
727 statement_cleanup(create_statements);
728 for (uint32_t x= 0; x < query_statements_count; x++)
729 statement_cleanup(query_statements[x]);
730 query_statements.clear();
731 statement_cleanup(pre_statements);
732 statement_cleanup(post_statements);
733 option_cleanup(engine_options);
734 option_cleanup(query_options);
737 free(shared_memory_base_name);
742 catch(std::exception &err)
744 cerr<<
"Error:"<<err.what()<<endl;
747 if (csv_file != fileno(stdout))
753 void concurrency_loop(drizzle_con_st &con, uint32_t current,
OptionString *eptr)
758 uint64_t client_limit;
760 head_sptr=
new Stats[iterations];
761 if (head_sptr == NULL)
763 fprintf(stderr,
"Error allocating memory in concurrency_loop\n");
767 if (auto_actual_queries)
768 client_limit= auto_actual_queries;
769 else if (num_of_query)
770 client_limit= num_of_query / current;
772 client_limit= actual_queries;
775 for (x= 0, sptr= head_sptr; x < iterations; x++, sptr++)
782 if (opt_preserve ==
false)
783 drop_schema(con, create_schema_string.c_str());
786 if (create_statements)
787 create_schema(con, create_schema_string.c_str(), create_statements, eptr, sptr);
794 printf(
"Generating primary key list\n");
795 if (auto_generate_sql_autoincrement || auto_generate_sql_guid_primary)
796 generate_primary_key_list(con, eptr);
798 if (not pre_system.empty())
800 int ret= system(pre_system.c_str());
809 run_statements(con, pre_statements);
811 run_scheduler(sptr, &query_statements[0], current, client_limit);
814 run_statements(con, post_statements);
816 if (not post_system.empty())
818 int ret= system(post_system.c_str());
823 if (auto_generate_sql_autoincrement || auto_generate_sql_guid_primary)
824 primary_keys.clear();
828 printf(
"Generating stats\n");
830 generate_stats(&conclusion, eptr, head_sptr);
833 print_conclusions(conclusion);
834 if (not opt_csv_str.empty())
835 print_conclusions_csv(conclusion);
841 uint32_t get_random_string(
char *buf,
size_t size)
845 for (
size_t x= size; x > 0; x--)
846 *buf_ptr++= ALPHANUMERICS[random() % ALPHANUMERICS_SIZE];
847 return(buf_ptr - buf);
858 build_table_string(
void)
860 char buf[HUGE_STRING_LENGTH];
865 table_string.reserve(HUGE_STRING_LENGTH);
867 table_string=
"CREATE TABLE `t1` (";
869 if (auto_generate_sql_autoincrement)
871 table_string.append(
"id serial");
873 if (num_int_cols || num_char_cols)
874 table_string.append(
",");
877 if (auto_generate_sql_guid_primary)
879 table_string.append(
"id varchar(128) primary key");
881 if (num_int_cols || num_char_cols || auto_generate_sql_guid_primary)
882 table_string.append(
",");
885 if (auto_generate_sql_secondary_indexes)
887 for (uint32_t count= 0; count < auto_generate_sql_secondary_indexes; count++)
890 table_string.append(
",");
892 if (snprintf(buf, HUGE_STRING_LENGTH,
"id%d varchar(32) unique key", count)
893 > HUGE_STRING_LENGTH)
895 fprintf(stderr,
"Memory Allocation error in create table\n");
898 table_string.append(buf);
901 if (num_int_cols || num_char_cols)
902 table_string.append(
",");
906 for (col_count= 1; col_count <= num_int_cols; col_count++)
908 if (num_int_cols_index)
910 if (snprintf(buf, HUGE_STRING_LENGTH,
"intcol%d INT, INDEX(intcol%d)",
911 col_count, col_count) > HUGE_STRING_LENGTH)
913 fprintf(stderr,
"Memory Allocation error in create table\n");
919 if (snprintf(buf, HUGE_STRING_LENGTH,
"intcol%d INT ", col_count)
920 > HUGE_STRING_LENGTH)
922 fprintf(stderr,
"Memory Allocation error in create table\n");
926 table_string.append(buf);
928 if (col_count < num_int_cols || num_char_cols > 0)
929 table_string.append(
",");
933 for (col_count= 1; col_count <= num_char_cols; col_count++)
935 if (num_char_cols_index)
937 if (snprintf(buf, HUGE_STRING_LENGTH,
938 "charcol%d VARCHAR(128), INDEX(charcol%d) ",
939 col_count, col_count) > HUGE_STRING_LENGTH)
941 fprintf(stderr,
"Memory Allocation error in creating table\n");
947 if (snprintf(buf, HUGE_STRING_LENGTH,
"charcol%d VARCHAR(128)",
948 col_count) > HUGE_STRING_LENGTH)
950 fprintf(stderr,
"Memory Allocation error in creating table\n");
954 table_string.append(buf);
956 if (col_count < num_char_cols || num_blob_cols > 0)
957 table_string.append(
",");
961 for (col_count= 1; col_count <= num_blob_cols; col_count++)
963 if (snprintf(buf, HUGE_STRING_LENGTH,
"blobcol%d blob",
964 col_count) > HUGE_STRING_LENGTH)
966 fprintf(stderr,
"Memory Allocation error in creating table\n");
969 table_string.append(buf);
971 if (col_count < num_blob_cols)
972 table_string.append(
",");
975 table_string.append(
")");
977 ptr->setString(table_string.length());
978 if (ptr->getString()==NULL)
980 fprintf(stderr,
"Memory Allocation error in creating table\n");
983 ptr->setType(CREATE_TABLE_TYPE);
984 strcpy(ptr->getString(), table_string.c_str());
995 build_update_string(
void)
997 char buf[HUGE_STRING_LENGTH];
1000 string update_string;
1002 update_string.reserve(HUGE_STRING_LENGTH);
1004 update_string=
"UPDATE t1 SET ";
1007 for (col_count= 1; col_count <= num_int_cols; col_count++)
1009 if (snprintf(buf, HUGE_STRING_LENGTH,
"intcol%d = %ld", col_count,
1010 random()) > HUGE_STRING_LENGTH)
1012 fprintf(stderr,
"Memory Allocation error in creating update\n");
1015 update_string.append(buf);
1017 if (col_count < num_int_cols || num_char_cols > 0)
1018 update_string.append(
",", 1);
1022 for (col_count= 1; col_count <= num_char_cols; col_count++)
1024 char rand_buffer[RAND_STRING_SIZE];
1025 int buf_len= get_random_string(rand_buffer, RAND_STRING_SIZE);
1027 if (snprintf(buf, HUGE_STRING_LENGTH,
"charcol%d = '%.*s'", col_count,
1028 buf_len, rand_buffer)
1029 > HUGE_STRING_LENGTH)
1031 fprintf(stderr,
"Memory Allocation error in creating update\n");
1034 update_string.append(buf);
1036 if (col_count < num_char_cols)
1037 update_string.append(
",", 1);
1040 if (auto_generate_sql_autoincrement || auto_generate_sql_guid_primary)
1041 update_string.append(
" WHERE id = ");
1046 ptr->setString(update_string.length());
1047 if (ptr->getString() == NULL)
1049 fprintf(stderr,
"Memory Allocation error in creating update\n");
1052 if (auto_generate_sql_autoincrement || auto_generate_sql_guid_primary)
1053 ptr->setType(UPDATE_TYPE_REQUIRES_PREFIX);
1055 ptr->setType(UPDATE_TYPE);
1056 strncpy(ptr->getString(), update_string.c_str(), ptr->getLength());
1068 build_insert_string(
void)
1070 char buf[HUGE_STRING_LENGTH];
1073 string insert_string;
1075 insert_string.reserve(HUGE_STRING_LENGTH);
1077 insert_string=
"INSERT INTO t1 VALUES (";
1079 if (auto_generate_sql_autoincrement)
1081 insert_string.append(
"NULL");
1083 if (num_int_cols || num_char_cols)
1084 insert_string.append(
",");
1087 if (auto_generate_sql_guid_primary)
1089 insert_string.append(
"uuid()");
1091 if (num_int_cols || num_char_cols)
1092 insert_string.append(
",");
1095 if (auto_generate_sql_secondary_indexes)
1099 for (count= 0; count < auto_generate_sql_secondary_indexes; count++)
1102 insert_string.append(
",");
1104 insert_string.append(
"uuid()");
1107 if (num_int_cols || num_char_cols)
1108 insert_string.append(
",");
1112 for (col_count= 1; col_count <= num_int_cols; col_count++)
1114 if (snprintf(buf, HUGE_STRING_LENGTH,
"%ld", random()) > HUGE_STRING_LENGTH)
1116 fprintf(stderr,
"Memory Allocation error in creating insert\n");
1119 insert_string.append(buf);
1121 if (col_count < num_int_cols || num_char_cols > 0)
1122 insert_string.append(
",");
1126 for (col_count= 1; col_count <= num_char_cols; col_count++)
1128 int buf_len= get_random_string(buf, RAND_STRING_SIZE);
1129 insert_string.append(
"'", 1);
1130 insert_string.append(buf, buf_len);
1131 insert_string.append(
"'", 1);
1133 if (col_count < num_char_cols || num_blob_cols > 0)
1134 insert_string.append(
",", 1);
1139 vector <char> blob_ptr;
1141 blob_ptr.resize(num_blob_cols_size);
1143 for (col_count= 1; col_count <= num_blob_cols; col_count++)
1147 uint32_t difference= num_blob_cols_size - num_blob_cols_size_min;
1149 size= difference ? (num_blob_cols_size_min + (random() % difference)) :
1152 buf_len= get_random_string(&blob_ptr[0], size);
1154 insert_string.append(
"'", 1);
1155 insert_string.append(&blob_ptr[0], buf_len);
1156 insert_string.append(
"'", 1);
1158 if (col_count < num_blob_cols)
1159 insert_string.append(
",", 1);
1163 insert_string.append(
")", 1);
1166 ptr->setString(insert_string.length());
1167 if (ptr->getString()==NULL)
1169 fprintf(stderr,
"Memory Allocation error in creating select\n");
1172 ptr->setType(INSERT_TYPE);
1173 strcpy(ptr->getString(), insert_string.c_str());
1185 build_select_string(
bool key)
1187 char buf[HUGE_STRING_LENGTH];
1190 string query_string;
1192 query_string.reserve(HUGE_STRING_LENGTH);
1194 query_string.append(
"SELECT ", 7);
1195 if (not auto_generate_selected_columns_opt.empty())
1197 query_string.append(auto_generate_selected_columns_opt.c_str());
1201 for (col_count= 1; col_count <= num_int_cols; col_count++)
1203 if (snprintf(buf, HUGE_STRING_LENGTH,
"intcol%d", col_count)
1204 > HUGE_STRING_LENGTH)
1206 fprintf(stderr,
"Memory Allocation error in creating select\n");
1209 query_string.append(buf);
1211 if (col_count < num_int_cols || num_char_cols > 0)
1212 query_string.append(
",", 1);
1215 for (col_count= 1; col_count <= num_char_cols; col_count++)
1217 if (snprintf(buf, HUGE_STRING_LENGTH,
"charcol%d", col_count)
1218 > HUGE_STRING_LENGTH)
1220 fprintf(stderr,
"Memory Allocation error in creating select\n");
1223 query_string.append(buf);
1225 if (col_count < num_char_cols || num_blob_cols > 0)
1226 query_string.append(
",", 1);
1229 for (col_count= 1; col_count <= num_blob_cols; col_count++)
1231 if (snprintf(buf, HUGE_STRING_LENGTH,
"blobcol%d", col_count)
1232 > HUGE_STRING_LENGTH)
1234 fprintf(stderr,
"Memory Allocation error in creating select\n");
1237 query_string.append(buf);
1239 if (col_count < num_blob_cols)
1240 query_string.append(
",", 1);
1243 query_string.append(
" FROM t1");
1246 (auto_generate_sql_autoincrement || auto_generate_sql_guid_primary))
1247 query_string.append(
" WHERE id = ");
1250 ptr->setString(query_string.length());
1251 if (ptr->getString() == NULL)
1253 fprintf(stderr,
"Memory Allocation error in creating select\n");
1257 (auto_generate_sql_autoincrement || auto_generate_sql_guid_primary))
1258 ptr->setType(SELECT_TYPE_REQUIRES_PREFIX);
1260 ptr->setType(SELECT_TYPE);
1261 strcpy(ptr->getString(), query_string.c_str());
1266 process_options(
void)
1269 ssize_t bytes_read= 0;
1274 verbose= opt_verbose.length();
1277 if ( (not create_string.empty()) || auto_generate_sql)
1278 opt_preserve=
false;
1280 if (auto_generate_sql && (not create_string.empty() || !user_supplied_query.empty()))
1283 "%s: Can't use --auto-generate-sql when create and query strings are specified!\n",
1288 if (auto_generate_sql && auto_generate_sql_guid_primary &&
1289 auto_generate_sql_autoincrement)
1292 "%s: Either auto-generate-sql-guid-primary or auto-generate-sql-add-autoincrement can be used!\n",
1297 if (auto_generate_sql && num_of_query && auto_actual_queries)
1300 "%s: Either auto-generate-sql-execute-number or number-of-queries can be used!\n",
1305 parse_comma(not concurrency_str.empty() ? concurrency_str.c_str() :
"1", concurrency);
1307 if (not opt_csv_str.empty())
1311 if (opt_csv_str[0] ==
'-')
1313 csv_file= fileno(stdout);
1317 if ((csv_file= open(opt_csv_str.c_str(), O_CREAT|O_WRONLY|O_APPEND,
1318 S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH)) == -1)
1320 fprintf(stderr,
"%s: Could not open csv file: %sn\n",
1321 SLAP_NAME, opt_csv_str.c_str());
1330 if (not num_int_cols_opt.empty())
1333 parse_option(num_int_cols_opt.c_str(), &str,
',');
1334 num_int_cols= atoi(str->getString());
1335 if (str->getOption())
1336 num_int_cols_index= atoi(str->getOption());
1337 option_cleanup(str);
1340 if (not num_char_cols_opt.empty())
1343 parse_option(num_char_cols_opt.c_str(), &str,
',');
1344 num_char_cols= atoi(str->getString());
1345 if (str->getOption())
1346 num_char_cols_index= atoi(str->getOption());
1348 num_char_cols_index= 0;
1349 option_cleanup(str);
1352 uint32_t sql_type_count= 0;
1353 if (not num_blob_cols_opt.empty())
1356 parse_option(num_blob_cols_opt.c_str(), &str,
',');
1357 num_blob_cols= atoi(str->getString());
1358 if (str->getOption())
1362 if ((sep_ptr= strchr(str->getOption(),
'/')))
1364 num_blob_cols_size_min= atoi(str->getOption());
1365 num_blob_cols_size= atoi(sep_ptr+1);
1369 num_blob_cols_size_min= num_blob_cols_size= atoi(str->getOption());
1374 num_blob_cols_size= DEFAULT_BLOB_SIZE;
1375 num_blob_cols_size_min= DEFAULT_BLOB_SIZE;
1377 option_cleanup(str);
1381 if (auto_generate_sql)
1387 printf(
"Building Create Statements for Auto\n");
1389 create_statements= build_table_string();
1393 for (ptr_statement= create_statements, x= 0;
1394 x < auto_generate_sql_unique_write_number;
1395 x++, ptr_statement= ptr_statement->getNext())
1397 ptr_statement->setNext(build_insert_string());
1401 printf(
"Building Query Statements for Auto\n");
1403 if (opt_auto_generate_sql_type.empty())
1404 opt_auto_generate_sql_type=
"mixed";
1406 query_statements_count=
1407 parse_option(opt_auto_generate_sql_type.c_str(), &query_options,
',');
1409 query_statements.resize(query_statements_count);
1414 if (sql_type->getString()[0] ==
'r')
1417 printf(
"Generating SELECT Statements for Auto\n");
1419 query_statements[sql_type_count]= build_select_string(
false);
1420 for (ptr_statement= query_statements[sql_type_count], x= 0;
1421 x < auto_generate_sql_unique_query_number;
1422 x++, ptr_statement= ptr_statement->getNext())
1424 ptr_statement->setNext(build_select_string(
false));
1427 else if (sql_type->getString()[0] ==
'k')
1430 printf(
"Generating SELECT for keys Statements for Auto\n");
1432 if ( auto_generate_sql_autoincrement ==
false &&
1433 auto_generate_sql_guid_primary ==
false)
1436 "%s: Can't perform key test without a primary key!\n",
1441 query_statements[sql_type_count]= build_select_string(
true);
1442 for (ptr_statement= query_statements[sql_type_count], x= 0;
1443 x < auto_generate_sql_unique_query_number;
1444 x++, ptr_statement= ptr_statement->getNext())
1446 ptr_statement->setNext(build_select_string(
true));
1449 else if (sql_type->getString()[0] ==
'w')
1457 printf(
"Generating INSERT Statements for Auto\n");
1458 query_statements[sql_type_count]= build_insert_string();
1459 for (ptr_statement= query_statements[sql_type_count], x= 0;
1460 x < auto_generate_sql_unique_query_number;
1461 x++, ptr_statement= ptr_statement->getNext())
1463 ptr_statement->setNext(build_insert_string());
1466 else if (sql_type->getString()[0] ==
'u')
1468 if ( auto_generate_sql_autoincrement ==
false &&
1469 auto_generate_sql_guid_primary ==
false)
1472 "%s: Can't perform update test without a primary key!\n",
1477 query_statements[sql_type_count]= build_update_string();
1478 for (ptr_statement= query_statements[sql_type_count], x= 0;
1479 x < auto_generate_sql_unique_query_number;
1480 x++, ptr_statement= ptr_statement->getNext())
1482 ptr_statement->setNext(build_update_string());
1489 query_statements[sql_type_count]= build_insert_string();
1494 for (ptr_statement= query_statements[sql_type_count], x= 0;
1495 x < auto_generate_sql_unique_query_number;
1496 x++, ptr_statement= ptr_statement->getNext())
1500 ptr_statement->setNext(build_insert_string());
1505 ptr_statement->setNext(build_select_string(
true));
1511 }
while (sql_type ? (sql_type= sql_type->getNext()) : 0);
1515 if (not create_string.empty() && !stat(create_string.c_str(), &sbuf))
1518 std::vector<char> tmp_string;
1519 if (not S_ISREG(sbuf.st_mode))
1521 fprintf(stderr,
"%s: Create file was not a regular file\n",
1525 if ((data_file= open(create_string.c_str(), O_RDWR)) == -1)
1527 fprintf(stderr,
"%s: Could not open create file\n", SLAP_NAME);
1530 if ((uint64_t)(sbuf.st_size + 1) > SIZE_MAX)
1532 fprintf(stderr,
"Request for more memory than architecture supports\n");
1535 tmp_string.resize(sbuf.st_size + 1);
1536 bytes_read= read(data_file, (
unsigned char*) &tmp_string[0],
1537 (
size_t)sbuf.st_size);
1539 if (bytes_read != sbuf.st_size)
1541 fprintf(stderr,
"Problem reading file: read less bytes than requested\n");
1543 parse_delimiter(&tmp_string[0], &create_statements, delimiter[0]);
1545 else if (not create_string.empty())
1547 parse_delimiter(create_string.c_str(), &create_statements, delimiter[0]);
1551 if (not user_supplied_query.empty())
1553 query_statements_count=
1554 parse_option(
"default", &query_options,
',');
1556 query_statements.resize(query_statements_count);
1559 if (not user_supplied_query.empty() && !stat(user_supplied_query.c_str(), &sbuf))
1562 std::vector<char> tmp_string;
1564 if (not S_ISREG(sbuf.st_mode))
1566 fprintf(stderr,
"%s: User query supplied file was not a regular file\n",
1570 if ((data_file= open(user_supplied_query.c_str(), O_RDWR)) == -1)
1572 fprintf(stderr,
"%s: Could not open query supplied file\n", SLAP_NAME);
1575 if ((uint64_t)(sbuf.st_size + 1) > SIZE_MAX)
1577 fprintf(stderr,
"Request for more memory than architecture supports\n");
1580 tmp_string.resize((
size_t)(sbuf.st_size + 1));
1581 bytes_read= read(data_file, (
unsigned char*) &tmp_string[0],
1582 (
size_t)sbuf.st_size);
1584 if (bytes_read != sbuf.st_size)
1586 fprintf(stderr,
"Problem reading file: read less bytes than requested\n");
1588 if (not user_supplied_query.empty())
1589 actual_queries= parse_delimiter(&tmp_string[0], &query_statements[0],
1592 else if (not user_supplied_query.empty())
1594 actual_queries= parse_delimiter(user_supplied_query.c_str(), &query_statements[0],
1599 if (not user_supplied_pre_statements.empty()
1600 && !stat(user_supplied_pre_statements.c_str(), &sbuf))
1603 std::vector<char> tmp_string;
1605 if (not S_ISREG(sbuf.st_mode))
1607 fprintf(stderr,
"%s: User query supplied file was not a regular file\n",
1611 if ((data_file= open(user_supplied_pre_statements.c_str(), O_RDWR)) == -1)
1613 fprintf(stderr,
"%s: Could not open query supplied file\n", SLAP_NAME);
1616 if ((uint64_t)(sbuf.st_size + 1) > SIZE_MAX)
1618 fprintf(stderr,
"Request for more memory than architecture supports\n");
1621 tmp_string.resize((
size_t)(sbuf.st_size + 1));
1622 bytes_read= read(data_file, (
unsigned char*) &tmp_string[0],
1623 (
size_t)sbuf.st_size);
1625 if (bytes_read != sbuf.st_size)
1627 fprintf(stderr,
"Problem reading file: read less bytes than requested\n");
1629 if (not user_supplied_pre_statements.empty())
1630 (
void)parse_delimiter(&tmp_string[0], &pre_statements,
1633 else if (not user_supplied_pre_statements.empty())
1635 (void)parse_delimiter(user_supplied_pre_statements.c_str(),
1640 if (not user_supplied_post_statements.empty()
1641 && !stat(user_supplied_post_statements.c_str(), &sbuf))
1644 std::vector<char> tmp_string;
1646 if (not S_ISREG(sbuf.st_mode))
1648 fprintf(stderr,
"%s: User query supplied file was not a regular file\n",
1652 if ((data_file= open(user_supplied_post_statements.c_str(), O_RDWR)) == -1)
1654 fprintf(stderr,
"%s: Could not open query supplied file\n", SLAP_NAME);
1658 if ((uint64_t)(sbuf.st_size + 1) > SIZE_MAX)
1660 fprintf(stderr,
"Request for more memory than architecture supports\n");
1663 tmp_string.resize((
size_t)(sbuf.st_size + 1));
1665 bytes_read= read(data_file, (
unsigned char*) &tmp_string[0],
1666 (
size_t)(sbuf.st_size));
1668 if (bytes_read != sbuf.st_size)
1670 fprintf(stderr,
"Problem reading file: read less bytes than requested\n");
1672 if (not user_supplied_post_statements.empty())
1673 (
void)parse_delimiter(&tmp_string[0], &post_statements,
1676 else if (not user_supplied_post_statements.empty())
1678 (void)parse_delimiter(user_supplied_post_statements.c_str(), &post_statements,
1683 printf(
"Parsing engines to use.\n");
1685 if (not default_engine.empty())
1686 parse_option(default_engine.c_str(), &engine_options,
',');
1689 opt_password= client_get_tty_password(NULL);
1694 static int run_query(drizzle_con_st &con, drizzle_result_st *result,
1695 const char *query,
int len)
1697 drizzle_return_t ret;
1698 drizzle_result_st result_buffer;
1702 printf(
"/* CON: %" PRIu64
" */ %.*s;\n",
1703 (uint64_t)drizzle_context(drizzle_con_drizzle(&con)),
1709 printf(
"%.*s;\n", len, query);
1712 result= &result_buffer;
1714 result= drizzle_query(&con, result, query, len, &ret);
1716 if (ret == DRIZZLE_RETURN_OK)
1717 ret= drizzle_result_buffer(result);
1719 if (result == &result_buffer)
1720 drizzle_result_free(result);
1727 generate_primary_key_list(drizzle_con_st &con,
OptionString *engine_stmt)
1729 drizzle_result_st result;
1738 if (opt_only_print || (engine_stmt &&
1739 strstr(engine_stmt->getString(),
"blackhole")))
1742 primary_keys.push_back(
"796c4422-1d94-102a-9d6d-00e0812d");
1746 if (run_query(con, &result,
"SELECT id from t1", strlen(
"SELECT id from t1")))
1748 fprintf(stderr,
"%s: Cannot select GUID primary keys. (%s)\n", SLAP_NAME,
1749 drizzle_con_error(&con));
1753 uint64_t num_rows_ret= drizzle_result_row_count(&result);
1754 if (num_rows_ret > SIZE_MAX)
1756 fprintf(stderr,
"More primary keys than than architecture supports\n");
1759 size_t primary_keys_number_of;
1760 primary_keys_number_of= (size_t)num_rows_ret;
1763 if (primary_keys_number_of)
1768 row= drizzle_row_next(&result);
1769 for (counter= 0; counter < primary_keys_number_of;
1770 counter++, row= drizzle_row_next(&result))
1772 primary_keys.push_back(row[0]);
1776 drizzle_result_free(&result);
1784 char query[HUGE_STRING_LENGTH];
1788 struct timeval start_time, end_time;
1791 gettimeofday(&start_time, NULL);
1793 len= snprintf(query, HUGE_STRING_LENGTH,
"CREATE SCHEMA `%s`", db);
1796 printf(
"Loading Pre-data\n");
1798 if (run_query(con, NULL, query, len))
1800 fprintf(stderr,
"%s: Cannot create schema %s : %s\n", SLAP_NAME, db,
1801 drizzle_con_error(&con));
1806 sptr->setCreateCount(sptr->getCreateCount()+1);
1811 printf(
"/* CON: %" PRIu64
" */ use %s;\n",
1812 (uint64_t)drizzle_context(drizzle_con_drizzle(&con)),
1817 drizzle_result_st result;
1818 drizzle_return_t ret;
1821 printf(
"%s;\n", query);
1823 if (drizzle_select_db(&con, &result, db, &ret) == NULL ||
1824 ret != DRIZZLE_RETURN_OK)
1826 fprintf(stderr,
"%s: Cannot select schema '%s': %s\n",SLAP_NAME, db,
1827 ret == DRIZZLE_RETURN_ERROR_CODE ?
1828 drizzle_result_error(&result) : drizzle_con_error(&con));
1831 drizzle_result_free(&result);
1832 sptr->setCreateCount(sptr->getCreateCount()+1);
1837 len= snprintf(query, HUGE_STRING_LENGTH,
"set storage_engine=`%s`",
1838 engine_stmt->getString());
1839 if (run_query(con, NULL, query, len))
1841 fprintf(stderr,
"%s: Cannot set default engine: %s\n", SLAP_NAME,
1842 drizzle_con_error(&con));
1845 sptr->setCreateCount(sptr->getCreateCount()+1);
1852 for (ptr= after_create; ptr && ptr->getLength(); ptr= ptr->getNext(), count++)
1854 if (auto_generate_sql && ( auto_generate_sql_number == count))
1857 if (engine_stmt && engine_stmt->getOption() && ptr->getType() == CREATE_TABLE_TYPE)
1859 char buffer[HUGE_STRING_LENGTH];
1861 snprintf(buffer, HUGE_STRING_LENGTH,
"%s %s", ptr->getString(),
1862 engine_stmt->getOption());
1863 if (run_query(con, NULL, buffer, strlen(buffer)))
1865 fprintf(stderr,
"%s: Cannot run query %.*s ERROR : %s\n",
1866 SLAP_NAME, (uint32_t)ptr->getLength(), ptr->getString(), drizzle_con_error(&con));
1867 if (not opt_ignore_sql_errors)
1870 sptr->setCreateCount(sptr->getCreateCount()+1);
1874 if (run_query(con, NULL, ptr->getString(), ptr->getLength()))
1876 fprintf(stderr,
"%s: Cannot run query %.*s ERROR : %s\n",
1877 SLAP_NAME, (uint32_t)ptr->getLength(), ptr->getString(), drizzle_con_error(&con));
1878 if (not opt_ignore_sql_errors)
1881 sptr->setCreateCount(sptr->getCreateCount()+1);
1885 if (auto_generate_sql && (auto_generate_sql_number > count ))
1888 after_create= stmt->getNext();
1892 gettimeofday(&end_time, NULL);
1894 sptr->setCreateTiming(timedif(end_time, start_time));
1897 static void drop_schema(drizzle_con_st &con,
const char *db)
1899 char query[HUGE_STRING_LENGTH];
1902 len= snprintf(query, HUGE_STRING_LENGTH,
"DROP SCHEMA IF EXISTS `%s`", db);
1904 if (run_query(con, NULL, query, len))
1906 fprintf(stderr,
"%s: Cannot drop database '%s' ERROR : %s\n",
1907 SLAP_NAME, db, drizzle_con_error(&con));
1912 static void run_statements(drizzle_con_st &con,
Statement *stmt)
1914 for (
Statement *ptr= stmt; ptr && ptr->getLength(); ptr= ptr->getNext())
1916 if (run_query(con, NULL, ptr->getString(), ptr->getLength()))
1918 fprintf(stderr,
"%s: Cannot run query %.*s ERROR : %s\n",
1919 SLAP_NAME, (uint32_t)ptr->getLength(), ptr->getString(), drizzle_con_error(&con));
1926 static void timer_thread()
1932 master_wakeup.wait();
1935 boost::mutex::scoped_lock scopedLock(timer_alarm_mutex);
1938 xtime_get(&xt, boost::TIME_UTC_);
1939 xt.sec += opt_timer_length;
1941 (void)timer_alarm_threshold.timed_wait(scopedLock, xt);
1945 boost::mutex::scoped_lock scopedLock(timer_alarm_mutex);
1950 typedef boost::shared_ptr<boost::thread> Thread;
1951 typedef std::vector <Thread> Threads;
1952 static void run_scheduler(
Stats *sptr,
Statement **stmts, uint32_t concur, uint64_t limit)
1954 uint32_t real_concurrency;
1955 struct timeval start_time, end_time;
1962 master_wakeup.reset();
1964 real_concurrency= 0;
1967 for (y= 0, sql_type= query_options;
1968 y < query_statements_count;
1969 y++, sql_type= sql_type->getNext())
1971 uint32_t options_loop= 1;
1973 if (sql_type->getOption())
1975 options_loop= strtol(sql_type->getOption(),
1977 options_loop= options_loop ? options_loop : 1;
1980 while (options_loop--)
1982 for (uint32_t x= 0; x < concur; x++)
1988 fprintf(stderr,
"Memory Allocation error in scheduler\n");
1991 con->setStmt(stmts[y]);
1992 con->setLimit(limit);
1998 thread= Thread(
new boost::thread(boost::bind(&run_task, con)));
1999 threads.push_back(thread);
2009 if (opt_timer_length)
2012 boost::mutex::scoped_lock alarmLock(timer_alarm_mutex);
2017 thread= Thread(
new boost::thread(&timer_thread));
2018 threads.push_back(thread);
2022 master_wakeup.start();
2024 gettimeofday(&start_time, NULL);
2029 for (Threads::iterator iter= threads.begin(); iter != threads.end(); iter++)
2034 gettimeofday(&end_time, NULL);
2036 sptr->setTiming(timedif(end_time, start_time));
2037 sptr->setUsers(concur);
2038 sptr->setRealUsers(real_concurrency);
2039 sptr->setRows(limit);
2046 uint32_t parse_option(
const char *origin,
OptionString **stmt,
char delm)
2051 uint32_t length= strlen(origin);
2054 end_ptr= (
char *)origin + length;
2059 for (begin_ptr= (
char *)origin;
2060 begin_ptr != end_ptr;
2061 tmp= tmp->getNext())
2063 char buffer[HUGE_STRING_LENGTH];
2066 memset(buffer, 0, HUGE_STRING_LENGTH);
2068 string= strchr(begin_ptr, delm);
2072 memcpy(buffer, begin_ptr,
string - begin_ptr);
2073 begin_ptr=
string+1;
2077 size_t begin_len= strlen(begin_ptr);
2078 memcpy(buffer, begin_ptr, begin_len);
2082 if ((buffer_ptr= strchr(buffer,
':')))
2089 tmp->setOption(buffer_ptr);
2092 tmp->setString(strdup(buffer));
2093 if (tmp->getString() == NULL)
2095 fprintf(stderr,
"Error allocating memory while parsing options\n");
2099 if (isspace(*begin_ptr))
2104 if (begin_ptr != end_ptr)
2119 uint32_t parse_delimiter(
const char *script,
Statement **stmt,
char delm)
2122 char *ptr= (
char *)script;
2125 uint32_t length= strlen(script);
2129 (retstr= strchr(ptr, delm));
2131 tmp= tmp->getNext())
2135 fprintf(stderr,
"Error allocating memory while parsing delimiter\n");
2140 tmp->setString((
size_t)(retstr - ptr));
2142 if (tmp->getString() == NULL)
2144 fprintf(stderr,
"Error allocating memory while parsing delimiter\n");
2148 memcpy(tmp->getString(), ptr, tmp->getLength());
2149 ptr+= retstr - ptr + 1;
2154 if (ptr != script+length)
2156 tmp->setString((
size_t)((script + length) - ptr));
2157 if (tmp->getString() == NULL)
2159 fprintf(stderr,
"Error allocating memory while parsing delimiter\n");
2162 memcpy(tmp->getString(), ptr, tmp->getLength());
2175 uint32_t parse_comma(
const char *
string, std::vector <uint32_t> &range)
2179 char *ptr= (
char *)
string;
2183 if (*ptr ==
',') count++;
2186 range.resize(count +1);
2189 ptr= (
char *)
string;
2191 while ((retstr= strchr(ptr,
',')))
2193 nptr[x++]= atoi(ptr);
2194 ptr+= retstr - ptr + 1;
2196 nptr[x++]= atoi(ptr);
2203 printf(
"Benchmark\n");
2204 if (con.getEngine())
2205 printf(
"\tRunning for engine %s\n", con.getEngine());
2207 if (not opt_label.empty() || !opt_auto_generate_sql_type.empty())
2209 const char *ptr= opt_auto_generate_sql_type.c_str() ? opt_auto_generate_sql_type.c_str() :
"query";
2210 printf(
"\tLoad: %s\n", !opt_label.empty() ? opt_label.c_str() : ptr);
2212 printf(
"\tAverage Time took to generate schema and initial data: %ld.%03ld seconds\n",
2213 con.getCreateAvgTiming() / 1000, con.getCreateAvgTiming() % 1000);
2214 printf(
"\tAverage number of seconds to run all queries: %ld.%03ld seconds\n",
2215 con.getAvgTiming() / 1000, con.getAvgTiming() % 1000);
2216 printf(
"\tMinimum number of seconds to run all queries: %ld.%03ld seconds\n",
2217 con.getMinTiming() / 1000, con.getMinTiming() % 1000);
2218 printf(
"\tMaximum number of seconds to run all queries: %ld.%03ld seconds\n",
2219 con.getMaxTiming() / 1000, con.getMaxTiming() % 1000);
2220 printf(
"\tTotal time for tests: %ld.%03ld seconds\n",
2221 con.getSumOfTime() / 1000, con.getSumOfTime() % 1000);
2222 printf(
"\tStandard Deviation: %ld.%03ld\n", con.getStdDev() / 1000, con.getStdDev() % 1000);
2223 printf(
"\tNumber of queries in create queries: %"PRIu64
"\n", con.getCreateCount());
2224 printf(
"\tNumber of clients running queries: %u/%u\n",
2225 con.getUsers(), con.getRealUsers());
2226 printf(
"\tNumber of times test was run: %u\n", iterations);
2227 printf(
"\tAverage number of queries per client: %"PRIu64
"\n", con.getAvgRows());
2229 uint64_t temp_val= failed_update_for_transaction;
2231 printf(
"\tFailed number of updates %"PRIu64
"\n", temp_val);
2238 char buffer[HUGE_STRING_LENGTH];
2239 char label_buffer[HUGE_STRING_LENGTH];
2241 const char *temp_label= opt_label.c_str();
2243 memset(label_buffer, 0,
sizeof(label_buffer));
2245 if (not opt_label.empty())
2247 string_len= opt_label.length();
2249 for (uint32_t x= 0; x < string_len; x++)
2251 if (temp_label[x] ==
',')
2252 label_buffer[x]=
'-';
2254 label_buffer[x]= temp_label[x] ;
2257 else if (not opt_auto_generate_sql_type.empty())
2259 string_len= opt_auto_generate_sql_type.length();
2261 for (uint32_t x= 0; x < string_len; x++)
2263 if (opt_auto_generate_sql_type[x] ==
',')
2264 label_buffer[x]=
'-';
2266 label_buffer[x]= opt_auto_generate_sql_type[x] ;
2271 snprintf(label_buffer, HUGE_STRING_LENGTH,
"query");
2274 snprintf(buffer, HUGE_STRING_LENGTH,
2275 "%s,%s,%ld.%03ld,%ld.%03ld,%ld.%03ld,%ld.%03ld,%ld.%03ld,"
2276 "%u,%u,%u,%"PRIu64
"\n",
2277 con.getEngine() ? con.getEngine() :
"",
2279 con.getAvgTiming() / 1000, con.getAvgTiming() % 1000,
2280 con.getMinTiming() / 1000, con.getMinTiming() % 1000,
2281 con.getMaxTiming() / 1000, con.getMaxTiming() % 1000,
2282 con.getSumOfTime() / 1000, con.getSumOfTime() % 1000,
2283 con.getStdDev() / 1000, con.getStdDev() % 1000,
2289 size_t buff_len= strlen(buffer);
2290 ssize_t write_ret= write(csv_file, (
unsigned char*) buffer, buff_len);
2291 if (write_ret != (ssize_t)buff_len)
2293 fprintf(stderr, _(
"Unable to fully write %"PRIu64
" bytes. "
2294 "Could only write %"PRId64
"."), (uint64_t)write_ret,
2305 con->setMinTiming(sptr->getTiming());
2306 con->setMaxTiming(sptr->getTiming());
2307 con->setMinRows(sptr->getRows());
2308 con->setMaxRows(sptr->getRows());
2311 con->setUsers(sptr->getUsers());
2312 con->setRealUsers(sptr->getRealUsers());
2313 con->setAvgRows(sptr->getRows());
2316 for (ptr= sptr, x= 0; x < iterations; ptr++, x++)
2318 con->setAvgTiming(ptr->getTiming()+con->getAvgTiming());
2320 if (ptr->getTiming() > con->getMaxTiming())
2321 con->setMaxTiming(ptr->getTiming());
2322 if (ptr->getTiming() < con->getMinTiming())
2323 con->setMinTiming(ptr->getTiming());
2325 con->setSumOfTime(con->getAvgTiming());
2326 con->setAvgTiming(con->getAvgTiming()/iterations);
2328 if (eng && eng->getString())
2329 con->setEngine(eng->getString());
2331 con->setEngine(NULL);
2333 standard_deviation(*con, sptr);
2336 con->setCreateMinTiming(sptr->getCreateTiming());
2337 con->setCreateMaxTiming(sptr->getCreateTiming());
2340 con->setCreateCount(sptr->getCreateCount());
2343 for (ptr= sptr, x= 0; x < iterations; ptr++, x++)
2345 con->setCreateAvgTiming(ptr->getCreateTiming()+con->getCreateAvgTiming());
2347 if (ptr->getCreateTiming() > con->getCreateMaxTiming())
2348 con->setCreateMaxTiming(ptr->getCreateTiming());
2349 if (ptr->getCreateTiming() < con->getCreateMinTiming())
2350 con->setCreateMinTiming(ptr->getCreateTiming());
2352 con->setCreateAvgTiming(con->getCreateAvgTiming()/iterations);
2362 for (ptr= stmt; ptr; ptr= nptr)
2364 nptr= ptr->getNext();
2375 for (ptr= stmt; ptr; ptr= nptr)
2377 nptr= ptr->getNext();
2382 void slap_close(drizzle_con_st *con)
2384 drizzle_free(drizzle_con_drizzle(con));
2387 drizzle_con_st* slap_connect(
bool connect_to_schema)
2390 static uint32_t connection_retry_sleep= 100000;
2391 int connect_error= 1;
2392 drizzle_return_t ret;
2393 drizzle_st *drizzle;
2395 if (opt_delayed_start)
2396 usleep(random()%opt_delayed_start);
2398 drizzle_con_st* con;
2399 if ((drizzle= drizzle_create()) == NULL or
2400 (con= drizzle_con_add_tcp(drizzle,
2401 host.c_str(), opt_drizzle_port,
2402 user.c_str(), opt_password.c_str(),
2403 connect_to_schema ? create_schema_string.c_str() : NULL,
2404 use_drizzle_protocol ? DRIZZLE_CON_EXPERIMENTAL : DRIZZLE_CON_MYSQL)) == NULL)
2406 fprintf(stderr,
"%s: Error creating drizzle object\n", SLAP_NAME);
2410 drizzle_set_context(drizzle, (
void*)(connection_count.fetch_and_increment()));
2417 for (uint32_t x= 0; x < 10; x++)
2419 if ((ret= drizzle_con_connect(con)) == DRIZZLE_RETURN_OK)
2425 usleep(connection_retry_sleep);
2429 fprintf(stderr,
"%s: Error when connecting to server: %d %s\n", SLAP_NAME,
2430 ret, drizzle_con_error(con));
2439 long int sum_of_squares;
2443 if (iterations == 1 || iterations == 0)
2450 for (ptr= sptr, x= 0, sum_of_squares= 0; x < iterations; ptr++, x++)
2454 deviation= ptr->getTiming() - con.getAvgTiming();
2455 sum_of_squares+= deviation*deviation;
2458 the_catch= sqrt((
double)(sum_of_squares/(iterations -1)));
2459 con.setStdDev((
long int)the_catch);
Primary template for atomic.