From 566cd2c02142741adbcd3288632f717887db1caf Mon Sep 17 00:00:00 2001 From: v-kaywon Date: Mon, 31 Jul 2017 15:33:11 -0700 Subject: [PATCH 01/11] change the number of CRUD performed per iteration --- test/Performance/README.md | 4 ++-- .../benchmark/pdo_sqlsrv/regular/PDODeleteBench.php | 4 ++-- .../benchmark/pdo_sqlsrv/regular/PDOFetchBench.php | 2 +- .../benchmark/pdo_sqlsrv/regular/PDOInsertBench.php | 2 +- .../benchmark/pdo_sqlsrv/regular/PDOSelectVersionBench.php | 4 +++- .../benchmark/pdo_sqlsrv/regular/PDOUpdateBench.php | 2 +- .../benchmark/sqlsrv/regular/SqlsrvDeleteBench.php | 4 ++-- .../Performance/benchmark/sqlsrv/regular/SqlsrvFetchBench.php | 2 +- .../benchmark/sqlsrv/regular/SqlsrvInsertBench.php | 2 +- .../benchmark/sqlsrv/regular/SqlsrvSelectVersionBench.php | 4 +++- .../benchmark/sqlsrv/regular/SqlsrvUpdateBench.php | 2 +- 11 files changed, 18 insertions(+), 14 deletions(-) diff --git a/test/Performance/README.md b/test/Performance/README.md index deb0e34b..fc27dc13 100644 --- a/test/Performance/README.md +++ b/test/Performance/README.md @@ -22,11 +22,11 @@ PHPBench is used to run the benchmarks. Visit http://phpbench.readthedocs.io/en/ ### 1. Modify lib/connect.php with the test database credentials ### 2. Execute run-perf_tests.py. ### Windows - py.exe run-perf_tests.py -platform -iterations -iterations-large -result-server -result-db -result-uid -result-pwd -iterations -iterations-large -result-server -result-db -result-uid -result-pwd >> run-perf_output.txt ### Linux and Mac On Linux and Mac, the script must be executed with `sudo python3` because to enable pooling it needs to modify odbcinst.ini system file. As an improvement, the location of the odbcinst.ini file can be changed so that, sudo is not requiered. - python3 run-perf_tests.py -platform -iterations -iterations-large -result-server -result-db -result-uid -result-pwd + python3 run-perf_tests.py -platform -iterations -iterations-large -result-server -result-db -result-uid -result-pwd >> run-perf_output.txt `-platform` - The platform that the tests are ran on. Must be one of the following: Windows10, WindowsServer2016 WindowsServer2012 Ubuntu16 RedHat7 Sierra `-iterations` - The number of iterations for regular tests. diff --git a/test/Performance/benchmark/pdo_sqlsrv/regular/PDODeleteBench.php b/test/Performance/benchmark/pdo_sqlsrv/regular/PDODeleteBench.php index b3eb788e..4bd44995 100644 --- a/test/Performance/benchmark/pdo_sqlsrv/regular/PDODeleteBench.php +++ b/test/Performance/benchmark/pdo_sqlsrv/regular/PDODeleteBench.php @@ -28,7 +28,7 @@ class PDODeleteBench{ } public function insertWithPrepare(){ - for( $i=0; $i<1000; $i++ ){ + for( $i=0; $i<100; $i++ ){ PDOSqlsrvUtil::insertWithPrepare( $this->conn, $this->tableName, $this->insertValues ); } } @@ -37,7 +37,7 @@ class PDODeleteBench{ * Note that, every delete calls prepare and execute APIs. */ public function benchDelete(){ - for( $i=0; $i<1000; $i++ ){ + for( $i=0; $i<100; $i++ ){ PDOSqlsrvUtil::deleteWithPrepare( $this->conn, $this->tableName ); } } diff --git a/test/Performance/benchmark/pdo_sqlsrv/regular/PDOFetchBench.php b/test/Performance/benchmark/pdo_sqlsrv/regular/PDOFetchBench.php index e7e17b4d..1d28fcb7 100644 --- a/test/Performance/benchmark/pdo_sqlsrv/regular/PDOFetchBench.php +++ b/test/Performance/benchmark/pdo_sqlsrv/regular/PDOFetchBench.php @@ -35,7 +35,7 @@ class PDOFetchBench{ * Note that, every fetch calls prepare, execute and fetch APIs. */ public function benchFetchWithPrepare(){ - for( $i=0; $i<1000; $i++){ + for( $i=0; $i<100; $i++){ PDOSqlsrvUtil::fetchWithPrepare( $this->conn, $this->tableName ); } } diff --git a/test/Performance/benchmark/pdo_sqlsrv/regular/PDOInsertBench.php b/test/Performance/benchmark/pdo_sqlsrv/regular/PDOInsertBench.php index 73b0e191..5610028c 100644 --- a/test/Performance/benchmark/pdo_sqlsrv/regular/PDOInsertBench.php +++ b/test/Performance/benchmark/pdo_sqlsrv/regular/PDOInsertBench.php @@ -30,7 +30,7 @@ class PDOInsertBench{ * Note that, every insertion calls prepare, bindParam and execute APIs. */ public function benchInsertWithPrepare(){ - for ( $i=0; $i<1000; $i++){ + for ( $i=0; $i<100; $i++){ PDOSqlsrvUtil::insertWithPrepare( $this->conn, $this->tableName, $this->insertValues ); } } diff --git a/test/Performance/benchmark/pdo_sqlsrv/regular/PDOSelectVersionBench.php b/test/Performance/benchmark/pdo_sqlsrv/regular/PDOSelectVersionBench.php index 10bc5a77..5de7ec26 100644 --- a/test/Performance/benchmark/pdo_sqlsrv/regular/PDOSelectVersionBench.php +++ b/test/Performance/benchmark/pdo_sqlsrv/regular/PDOSelectVersionBench.php @@ -16,7 +16,9 @@ class PDOSelectVersionBench{ * Each iteration calls execDirect API to fetch @@Version */ public function benchSelectVersion(){ - $version = PDOSqlsrvUtil::selectVersion( $this->conn ); + for( $i=0; $i<10; $i++ ){ + $version = PDOSqlsrvUtil::selectVersion( $this->conn ); + } } public function disconnect(){ diff --git a/test/Performance/benchmark/pdo_sqlsrv/regular/PDOUpdateBench.php b/test/Performance/benchmark/pdo_sqlsrv/regular/PDOUpdateBench.php index 2a582f0b..a590066a 100644 --- a/test/Performance/benchmark/pdo_sqlsrv/regular/PDOUpdateBench.php +++ b/test/Performance/benchmark/pdo_sqlsrv/regular/PDOUpdateBench.php @@ -45,7 +45,7 @@ class PDOUpdateBench{ * Note that, every update calls prepare, bindParam and execute APIs. */ public function benchUpdateWithPrepare(){ - for( $i=0; $i<1000; $i++ ){ + for( $i=0; $i<100; $i++ ){ $stmt = PDOSqlsrvUtil::updateWithPrepare( $this->conn, $this->tableName, $this->updateValues, $this->updateParams ); } } diff --git a/test/Performance/benchmark/sqlsrv/regular/SqlsrvDeleteBench.php b/test/Performance/benchmark/sqlsrv/regular/SqlsrvDeleteBench.php index e47070a5..819fbd91 100644 --- a/test/Performance/benchmark/sqlsrv/regular/SqlsrvDeleteBench.php +++ b/test/Performance/benchmark/sqlsrv/regular/SqlsrvDeleteBench.php @@ -28,7 +28,7 @@ class SqlsrvDeleteBench{ } public function insertWithPrepare(){ - for ( $i=0; $i<1000; $i++ ){ + for ( $i=0; $i<100; $i++ ){ SqlsrvUtil::insertWithPrepare( $this->conn, $this->tableName, $this->insertValues ); } } @@ -37,7 +37,7 @@ class SqlsrvDeleteBench{ * Note that, every delete calls prepare and execute APIs. */ public function benchDelete(){ - for( $i=0; $i<1000; $i++ ){ + for( $i=0; $i<100; $i++ ){ SqlsrvUtil::delete( $this->conn, $this->tableName ); } } diff --git a/test/Performance/benchmark/sqlsrv/regular/SqlsrvFetchBench.php b/test/Performance/benchmark/sqlsrv/regular/SqlsrvFetchBench.php index 035903c2..ddc748cc 100644 --- a/test/Performance/benchmark/sqlsrv/regular/SqlsrvFetchBench.php +++ b/test/Performance/benchmark/sqlsrv/regular/SqlsrvFetchBench.php @@ -38,7 +38,7 @@ class SqlsrvFetchBench{ * Note that, every fetch calls prepare, execute and fetch APIs. */ public function benchFetchWithPrepare(){ - for( $i=0; $i<1000; $i++){ + for( $i=0; $i<100; $i++){ SqlsrvUtil::fetchWithPrepare( $this->conn, $this->tableName ); } } diff --git a/test/Performance/benchmark/sqlsrv/regular/SqlsrvInsertBench.php b/test/Performance/benchmark/sqlsrv/regular/SqlsrvInsertBench.php index 43a451fd..2e67c2a7 100644 --- a/test/Performance/benchmark/sqlsrv/regular/SqlsrvInsertBench.php +++ b/test/Performance/benchmark/sqlsrv/regular/SqlsrvInsertBench.php @@ -31,7 +31,7 @@ class SqlsrvInsertBench{ * Note that, every insertion calls prepare, bindParam and execute APIs. */ public function benchInsertWithPrepare(){ - for( $i=0; $i<1000; $i++ ){ + for( $i=0; $i<100; $i++ ){ SqlsrvUtil::insertWithPrepare( $this->conn, $this->tableName, $this->insertValues ); } } diff --git a/test/Performance/benchmark/sqlsrv/regular/SqlsrvSelectVersionBench.php b/test/Performance/benchmark/sqlsrv/regular/SqlsrvSelectVersionBench.php index 9567a093..3d7a282f 100644 --- a/test/Performance/benchmark/sqlsrv/regular/SqlsrvSelectVersionBench.php +++ b/test/Performance/benchmark/sqlsrv/regular/SqlsrvSelectVersionBench.php @@ -16,7 +16,9 @@ class SqlsrvSelectVersionBench{ * Each iteration calls execDirect API to fetch @@Version */ public function benchSelectVersion(){ - $version = SqlsrvUtil::selectVersion( $this->conn ); + for( $i=0; $i<10; $i++ ){ + $version = SqlsrvUtil::selectVersion( $this->conn ); + } } public function disconnect(){ diff --git a/test/Performance/benchmark/sqlsrv/regular/SqlsrvUpdateBench.php b/test/Performance/benchmark/sqlsrv/regular/SqlsrvUpdateBench.php index 806c336a..51e1f2a0 100644 --- a/test/Performance/benchmark/sqlsrv/regular/SqlsrvUpdateBench.php +++ b/test/Performance/benchmark/sqlsrv/regular/SqlsrvUpdateBench.php @@ -45,7 +45,7 @@ class SqlsrvUpdateBench{ * Note that, every update calls prepare, bindParam and execute APIs. */ public function benchUpdateWithPrepare(){ - for( $i=0; $i<1000; $i++ ){ + for( $i=0; $i<100; $i++ ){ $stmt = SqlsrvUtil::updateWithPrepare( $this->conn, $this->tableName, $this->updateValues, $this->updateParams ); } } From 49b445a8e904f1e1e74b29e1af5f7cce46f7ded3 Mon Sep 17 00:00:00 2001 From: v-kaywon Date: Wed, 9 Aug 2017 13:25:29 -0700 Subject: [PATCH 02/11] refactored run-perf_tests.py to have less arguments and restructured benchmark folder (got rid of regular and large folders) --- .../{regular => }/PDOConnectionBench.php | 4 +- .../PDOCreateDbTableProcBench.php | 1 + .../{regular => }/PDODeleteBench.php | 1 + .../{regular => }/PDOFetchBench.php | 1 + .../{large => }/PDOFetchLargeBench.php | 1 + .../{regular => }/PDOInsertBench.php | 1 + .../{regular => }/PDOSelectVersionBench.php | 5 +- .../{regular => }/PDOUpdateBench.php | 1 + .../{regular => }/SqlsrvConnectionBench.php | 4 +- .../SqlsrvCreateDbTableProcBench.php | 1 + .../{regular => }/SqlsrvDeleteBench.php | 1 + .../sqlsrv/{regular => }/SqlsrvFetchBench.php | 1 + .../{large => }/SqlsrvFetchLargeBench.php | 1 + .../{regular => }/SqlsrvInsertBench.php | 1 + .../SqlsrvSelectVersionBench.php | 5 +- .../{regular => }/SqlsrvUpdateBench.php | 1 + test/Performance/lib/result_db.php | 6 ++ test/Performance/run-perf_tests.py | 69 +++++++++---------- 18 files changed, 62 insertions(+), 43 deletions(-) rename test/Performance/benchmark/pdo_sqlsrv/{regular => }/PDOConnectionBench.php (90%) rename test/Performance/benchmark/pdo_sqlsrv/{regular => }/PDOCreateDbTableProcBench.php (97%) rename test/Performance/benchmark/pdo_sqlsrv/{regular => }/PDODeleteBench.php (98%) rename test/Performance/benchmark/pdo_sqlsrv/{regular => }/PDOFetchBench.php (98%) rename test/Performance/benchmark/pdo_sqlsrv/{large => }/PDOFetchLargeBench.php (97%) rename test/Performance/benchmark/pdo_sqlsrv/{regular => }/PDOInsertBench.php (98%) rename test/Performance/benchmark/pdo_sqlsrv/{regular => }/PDOSelectVersionBench.php (80%) rename test/Performance/benchmark/pdo_sqlsrv/{regular => }/PDOUpdateBench.php (98%) rename test/Performance/benchmark/sqlsrv/{regular => }/SqlsrvConnectionBench.php (90%) rename test/Performance/benchmark/sqlsrv/{regular => }/SqlsrvCreateDbTableProcBench.php (97%) rename test/Performance/benchmark/sqlsrv/{regular => }/SqlsrvDeleteBench.php (98%) rename test/Performance/benchmark/sqlsrv/{regular => }/SqlsrvFetchBench.php (98%) rename test/Performance/benchmark/sqlsrv/{large => }/SqlsrvFetchLargeBench.php (97%) rename test/Performance/benchmark/sqlsrv/{regular => }/SqlsrvInsertBench.php (98%) rename test/Performance/benchmark/sqlsrv/{regular => }/SqlsrvSelectVersionBench.php (80%) rename test/Performance/benchmark/sqlsrv/{regular => }/SqlsrvUpdateBench.php (98%) create mode 100644 test/Performance/lib/result_db.php diff --git a/test/Performance/benchmark/pdo_sqlsrv/regular/PDOConnectionBench.php b/test/Performance/benchmark/pdo_sqlsrv/PDOConnectionBench.php similarity index 90% rename from test/Performance/benchmark/pdo_sqlsrv/regular/PDOConnectionBench.php rename to test/Performance/benchmark/pdo_sqlsrv/PDOConnectionBench.php index f6244bac..ed907ae9 100644 --- a/test/Performance/benchmark/pdo_sqlsrv/regular/PDOConnectionBench.php +++ b/test/Performance/benchmark/pdo_sqlsrv/PDOConnectionBench.php @@ -1,7 +1,9 @@ conn ); - } + $version = PDOSqlsrvUtil::selectVersion( $this->conn ); } public function disconnect(){ diff --git a/test/Performance/benchmark/pdo_sqlsrv/regular/PDOUpdateBench.php b/test/Performance/benchmark/pdo_sqlsrv/PDOUpdateBench.php similarity index 98% rename from test/Performance/benchmark/pdo_sqlsrv/regular/PDOUpdateBench.php rename to test/Performance/benchmark/pdo_sqlsrv/PDOUpdateBench.php index a590066a..cac76e26 100644 --- a/test/Performance/benchmark/pdo_sqlsrv/regular/PDOUpdateBench.php +++ b/test/Performance/benchmark/pdo_sqlsrv/PDOUpdateBench.php @@ -2,6 +2,7 @@ use PDOSqlsrvPerfTest\PDOSqlsrvUtil; /** + * @Iterations(1000) * @BeforeMethods({"connect", "setTableName", "createTable", "generateInsertValues", "insertWithPrepare", "generateUpdateValues", "generateUpdateParams"}) * @AfterMethods({"dropTable", "disconnect"}) */ diff --git a/test/Performance/benchmark/sqlsrv/regular/SqlsrvConnectionBench.php b/test/Performance/benchmark/sqlsrv/SqlsrvConnectionBench.php similarity index 90% rename from test/Performance/benchmark/sqlsrv/regular/SqlsrvConnectionBench.php rename to test/Performance/benchmark/sqlsrv/SqlsrvConnectionBench.php index 1a59f6db..f8fb0211 100644 --- a/test/Performance/benchmark/sqlsrv/regular/SqlsrvConnectionBench.php +++ b/test/Performance/benchmark/sqlsrv/SqlsrvConnectionBench.php @@ -1,7 +1,9 @@ conn ); - } + $version = SqlsrvUtil::selectVersion( $this->conn ); } public function disconnect(){ diff --git a/test/Performance/benchmark/sqlsrv/regular/SqlsrvUpdateBench.php b/test/Performance/benchmark/sqlsrv/SqlsrvUpdateBench.php similarity index 98% rename from test/Performance/benchmark/sqlsrv/regular/SqlsrvUpdateBench.php rename to test/Performance/benchmark/sqlsrv/SqlsrvUpdateBench.php index 51e1f2a0..0d31b881 100644 --- a/test/Performance/benchmark/sqlsrv/regular/SqlsrvUpdateBench.php +++ b/test/Performance/benchmark/sqlsrv/SqlsrvUpdateBench.php @@ -2,6 +2,7 @@ use SqlsrvPerfTest\SqlsrvUtil; /** + * @Iterations(1000) * @BeforeMethods({"connect", "setTableName", "createTable", "generateInsertValues", "insertWithPrepare", "generateUpdateValues", "generateUpdateParams"}) * @AfterMethods({ "dropTable", "disconnect"}) */ diff --git a/test/Performance/lib/result_db.php b/test/Performance/lib/result_db.php new file mode 100644 index 00000000..79415bff --- /dev/null +++ b/test/Performance/lib/result_db.php @@ -0,0 +1,6 @@ + diff --git a/test/Performance/run-perf_tests.py b/test/Performance/run-perf_tests.py index 0821011e..b2f45e32 100644 --- a/test/Performance/run-perf_tests.py +++ b/test/Performance/run-perf_tests.py @@ -28,16 +28,15 @@ import hashlib Paths to current benchmarks. These constants should be modified if there are any changes in folder structure of the project. "regular" folder contains the benchmarks that can be run for any iterations. "large" folder contains the benchmarks ( currently the benchmark that fetches large amount of data ) that take long time to run and meant to have less number of iterations than the regular ones. """ -sqlsrv_regular_path = "benchmark" + os.sep + "sqlsrv" + os.sep + "regular" -sqlsrv_large_path = "benchmark" + os.sep + "sqlsrv" + os.sep + "large" -pdo_regular_path = "benchmark" + os.sep + "pdo_sqlsrv" + os.sep + "regular" -pdo_large_path = "benchmark" + os.sep + "pdo_sqlsrv" + os.sep + "large" +sqlsrv_path = "benchmark" + os.sep + "sqlsrv" +pdo_path = "benchmark" + os.sep + "pdo_sqlsrv" """ Path to the connect.php file that contains test database credentials. Note that, the benchmarks are run against this database and it is different from Result database. """ connect_file = "lib" + os.sep + "connect.php" connect_file_bak = connect_file + ".bak" +result_file = "lib" + os.sep + "result_db.php" """ Global data format used across the script @@ -139,18 +138,17 @@ def get_test_name( name ): } return test_name_dict[ name ] -def get_run_command( path_to_tests, iterations, dump_file ): +def get_run_command( path_to_tests, dump_file ): """ This module returns the command to run the tests Args: path_to_tests (str): The folder that contains the tests to be run - iterations (str): Number of iterations dump_file (str): The name of the XML file to output the results Returns: The command to run the tests """ - command = "vendor" + os.sep + "bin" + os.sep + "phpbench run {0} --iterations {1} --dump-file={2}" - return command.format( path_to_tests, iterations, dump_file ) + command = "vendor" + os.sep + "bin" + os.sep + "phpbench run {0} --dump-file={1}" + return command.format( path_to_tests, dump_file ) def get_id( conn, id_field, table, name_field, value ): """ @@ -196,14 +194,14 @@ def get_id_no_quote( conn, id_field, table, name_field, value ): return id[0] return id -def get_test_database(): +def get_test_database( database_file ): """ This module reads test database details from connect.php and stores them into an instance of DB class Returns: A DB object that contains database credentials """ test_db = DB() - for line in open( connect_file ): + for line in open( database_file ): if "server" in line: test_db.server_name = line.split("=")[1].strip()[1:-2] elif "database" in line: @@ -611,21 +609,23 @@ def disable_pooling(): copyfile( odbcinst_bak, odbcinst ) os.remove( odbcinst_bak ) -def run_tests( iterations, iterations_large ): +def run_tests( php_driver, test_name ): """ This module runs the tests using PHPBench Args: - iterations (int): Number of iterations the tests in "regular" folder are run for - iterations_large (int): Number of iterations the tests in "large" folder are run for + php_driver (str): Name of the driver to be tested: sqlsrv, pdo_sqlsrv, or both + test_name (str): File name of the test or all Returns: N/A """ print("Running the tests...") - call( get_run_command( sqlsrv_regular_path, iterations, "sqlsrv-regular.xml" ), shell=True ) - call( get_run_command( sqlsrv_large_path, iterations_large, "sqlsrv-large.xml" ), shell=True ) - - call( get_run_command( pdo_regular_path, iterations, "pdo_sqlsrv-regular.xml" ), shell=True ) - call( get_run_command( pdo_large_path, iterations_large, "pdo_sqlsrv-large.xml" ), shell=True ) + add_to_path = '' + if test_name != 'all': + add_to_path = os.sep + test_name + if php_driver == 'sqlsrv' or php_driver == 'both': + call( get_run_command( sqlsrv_path + add_to_path, "sqlsrv-results.xml" ), shell=True ) + if php_driver == 'pdo_sqlsrv' or php_driver == 'both': + call( get_run_command( pdo_path + add_to_path, "pdo_sqlsrv-results.xml" ), shell=True ) def parse_results( dump_file ): """ @@ -685,6 +685,11 @@ def parse_and_store_results( dump_file, test_db, result_db, platform, driver, st Returns: N/A """ + # Check if the xml file actually exist + if not os.path.exists(dump_file): + print(dump_file + " does not exist") + return + # Connect to the Result Database conn = connect( result_db ) @@ -742,20 +747,14 @@ def parse_and_store_results_all( test_db, result_db, platform, start_time, mars, """ print("Parsing and storing the results...") - parse_and_store_results( "sqlsrv-regular.xml", test_db, result_db, platform, "sqlsrv", start_time, mars, pooling ) - parse_and_store_results( "sqlsrv-large.xml", test_db, result_db, platform, "sqlsrv", start_time, mars, pooling ) - parse_and_store_results( "pdo_sqlsrv-regular.xml", test_db, result_db, platform, "pdo_sqlsrv", start_time, mars, pooling ) - parse_and_store_results( "pdo_sqlsrv-large.xml", test_db, result_db, platform, "pdo_sqlsrv", start_time, mars, pooling ) + parse_and_store_results( "sqlsrv-results.xml", test_db, result_db, platform, "sqlsrv", start_time, mars, pooling ) + parse_and_store_results( "pdo_sqlsrv-results.xml", test_db, result_db, platform, "pdo_sqlsrv", start_time, mars, pooling ) if __name__ == '__main__': parser = argparse.ArgumentParser() - parser.add_argument( '-platform', '--PLATFORM', required=True, help='The name of the platform the tests run on' ) - parser.add_argument( '-iterations', '--ITERATIONS', required=True, help='Number of iterations for regular tests', type=int ) - parser.add_argument( '-iterations-large', '--ITERATIONS_LARGE', required=True, help='Number of iterations for regular tests', type=int ) - parser.add_argument( '-result-server', '--RESULT_SERVER', required=True, help='IP address of the Result Server' ) - parser.add_argument( '-result-db', '--RESULT_DB', required=True, help='Name of the Result Database' ) - parser.add_argument( '-result-uid', '--RESULT_UID', required=True, help='Username to connect to the Result Database' ) - parser.add_argument( '-result-pwd', '--RESULT_PWD', required=True, help='Password to connect to the Result Database' ) + parser.add_argument( '-platform', '--PLATFORM', required=True, help='The name of the platform the tests run on' ) + parser.add_argument( '-php-driver', '--PHP_DRIVER', default='both', help='Name of the PHP driver: sqlsrv, pdo_sqlsrv or both') + parser.add_argument( '-test-only', '--TEST_ONLY', default='all', help='File name for only one test or all' ) args = parser.parse_args() # Start time is recorded only in the beginning of this script execution. So it is not benchmark specific. @@ -764,12 +763,12 @@ if __name__ == '__main__': print( "Start time: " + start_time ) validate_platform( args.PLATFORM ) - result_db = DB( args.RESULT_SERVER, args.RESULT_DB, args.RESULT_UID, args.RESULT_PWD ) - test_db = get_test_database() + result_db = get_test_database( result_file ) + test_db = get_test_database( connect_file ) print("Running the tests with default settings...") - run_tests( args.ITERATIONS, args.ITERATIONS_LARGE ) + run_tests( args.PHP_DRIVER, args.TEST_ONLY ) parse_and_store_results_all( test_db, result_db, args.PLATFORM, start_time, 0, 0 ) """ The following lines are commented out, because it already takes a long time to run the tests with the default settings. @@ -777,17 +776,17 @@ if __name__ == '__main__': print("Running the tests with MARS ON...") enable_mars() - run_tests( args.ITERATIONS, args.ITERATIONS_LARGE ) + run_tests( args.PHP_DRIVER, args.TEST_ONLY ) parse_and_store_results_all( test_db, result_db, args.PLATFORM, start_time, 1, 0 ) disable_mars() print("Running the tests with Pooling ON...") enable_pooling() - run_tests( args.ITERATIONS, args.ITERATIONS_LARGE ) + run_tests( args.PHP_DRIVER, args.TEST_ONLY ) parse_and_store_results_all( test_db, result_db, args.PLATFORM, start_time, 0, 1 ) disable_pooling() """ exit() - \ No newline at end of file + From 36cf163a7d9e11346c38a699b5d10ee5f1e2843c Mon Sep 17 00:00:00 2001 From: v-kaywon Date: Wed, 9 Aug 2017 14:00:16 -0700 Subject: [PATCH 03/11] change README.md for the new instructions for running run-perf_tests.py --- test/Performance/README.md | 21 +++++++------------ .../pdo_sqlsrv/PDOSelectVersionBench.php | 2 +- 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/test/Performance/README.md b/test/Performance/README.md index fc27dc13..0fb305c7 100644 --- a/test/Performance/README.md +++ b/test/Performance/README.md @@ -20,21 +20,16 @@ Run `cmd` as administrator. PHPBench is used to run the benchmarks. Visit http://phpbench.readthedocs.io/en/latest/introduction.html to have an idea how the tool works. ### 1. Modify lib/connect.php with the test database credentials -### 2. Execute run-perf_tests.py. +### 2. Modify lib/result_db.php with the result database credentials +### 3. The number of iterations for each test can be modified in the test itself (e.g., in test/Performance/benchmark/sqlsrv). Each test has a @Iteration(n) annotation. If you change the number in this annotation, you will change the number of iterations run for this test. By default, most tests are set to 1000 iterations. +### 4. Execute run-perf_tests.py. ### Windows - py.exe run-perf_tests.py -platform -iterations -iterations-large -result-server -result-db -result-uid -result-pwd >> run-perf_output.txt + py.exe run-perf_tests.py -platform >> run-perf_output.txt ### Linux and Mac On Linux and Mac, the script must be executed with `sudo python3` because to enable pooling it needs to modify odbcinst.ini system file. As an improvement, the location of the odbcinst.ini file can be changed so that, sudo is not requiered. - python3 run-perf_tests.py -platform -iterations -iterations-large -result-server -result-db -result-uid -result-pwd >> run-perf_output.txt + python3 run-perf_tests.py -platform >> run-perf_output.txt -`-platform` - The platform that the tests are ran on. Must be one of the following: Windows10, WindowsServer2016 WindowsServer2012 Ubuntu16 RedHat7 Sierra -`-iterations` - The number of iterations for regular tests. -`-iterations-large` - The number of iterations for the tests that fetch large data. Usually set to 1. -`-result-server` - The server of result database. It is assumed that, the result database already setup before running the tests. -`-result-db` - Database name. With the current result database setup files, this should be set to `TestResults` -`-result-uid` - Result database username -`-result-pwd` Result database password - - - +`-platform` - The platform that the tests are ran on. Must be one of the following: Windows10, WindowsServer2016, WindowsServer2012, Ubuntu16, RedHat7, Sierra +`-php-driver` (optional) - The driver that the tests are ran on. Must be one of the following: sqlsrv, pdo_sqlsrv, or both. Default is both. +`-test-only` (optional) - The test to run. Must be the file name (not including path) of one test or 'all'. Default is 'all'. If one test is specified, must also specify the -php-driver option to sqlsrv or pdo_sqlsrv. \ No newline at end of file diff --git a/test/Performance/benchmark/pdo_sqlsrv/PDOSelectVersionBench.php b/test/Performance/benchmark/pdo_sqlsrv/PDOSelectVersionBench.php index 1e9f6126..c7c05a9b 100644 --- a/test/Performance/benchmark/pdo_sqlsrv/PDOSelectVersionBench.php +++ b/test/Performance/benchmark/pdo_sqlsrv/PDOSelectVersionBench.php @@ -2,7 +2,7 @@ use PDOSqlsrvPerfTest\PDOSqlsrvUtil; /** - * @Iterations(1000) + * @Iterations(10000) * @BeforeMethods({"connect"}) * @AfterMethods({"disconnect"}) */ From 43cad3e86494a32cb4f852acfd806b79b7e2a63c Mon Sep 17 00:00:00 2001 From: v-kaywon Date: Wed, 9 Aug 2017 16:42:54 -0700 Subject: [PATCH 04/11] fixed type to Iterations annotation in PDOSelectVersionBench.php --- test/Performance/benchmark/pdo_sqlsrv/PDOFetchLargeBench.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Performance/benchmark/pdo_sqlsrv/PDOFetchLargeBench.php b/test/Performance/benchmark/pdo_sqlsrv/PDOFetchLargeBench.php index 3df754bd..af7a0ad0 100644 --- a/test/Performance/benchmark/pdo_sqlsrv/PDOFetchLargeBench.php +++ b/test/Performance/benchmark/pdo_sqlsrv/PDOFetchLargeBench.php @@ -2,7 +2,7 @@ use PDOSqlsrvPerfTest\PDOSqlsrvUtil; /** - * @Iteratinos(1) + * @Iterations(1) * @BeforeMethods({"connect", "setTableName" }) * @AfterMethods({ "disconnect"}) */ From ec9cfc79942b87c0e7be5a0a79712c7835610d84 Mon Sep 17 00:00:00 2001 From: v-kaywon Date: Thu, 10 Aug 2017 11:02:49 -0700 Subject: [PATCH 05/11] changed README --- test/Performance/README.md | 4 ++-- test/Performance/run-perf_tests.py | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/test/Performance/README.md b/test/Performance/README.md index 0fb305c7..1b2976e1 100644 --- a/test/Performance/README.md +++ b/test/Performance/README.md @@ -24,11 +24,11 @@ PHPBench is used to run the benchmarks. Visit http://phpbench.readthedocs.io/en/ ### 3. The number of iterations for each test can be modified in the test itself (e.g., in test/Performance/benchmark/sqlsrv). Each test has a @Iteration(n) annotation. If you change the number in this annotation, you will change the number of iterations run for this test. By default, most tests are set to 1000 iterations. ### 4. Execute run-perf_tests.py. ### Windows - py.exe run-perf_tests.py -platform >> run-perf_output.txt + py.exe run-perf_tests.py -platform > tee run-perf_output.txt ### Linux and Mac On Linux and Mac, the script must be executed with `sudo python3` because to enable pooling it needs to modify odbcinst.ini system file. As an improvement, the location of the odbcinst.ini file can be changed so that, sudo is not requiered. - python3 run-perf_tests.py -platform >> run-perf_output.txt + python3 run-perf_tests.py -platform | tee run-perf_output.txt `-platform` - The platform that the tests are ran on. Must be one of the following: Windows10, WindowsServer2016, WindowsServer2012, Ubuntu16, RedHat7, Sierra `-php-driver` (optional) - The driver that the tests are ran on. Must be one of the following: sqlsrv, pdo_sqlsrv, or both. Default is both. diff --git a/test/Performance/run-perf_tests.py b/test/Performance/run-perf_tests.py index b2f45e32..0a04e2ab 100644 --- a/test/Performance/run-perf_tests.py +++ b/test/Performance/run-perf_tests.py @@ -656,6 +656,7 @@ def parse_results( dump_file ): # If the bechmark was run successfully, parse the results. This is where you would add code to parse more details about the benchmark. else: xml_result.success = 1 + # convert microseconds to seconds xml_result.duration = int( round( int( benchmark[0][0].find( 'stats' ).get( 'sum' )) / 1000000 )) iterations = benchmark[0][0].findall( 'iteration' ) xml_result.iterations = len( iterations ) From e6e46b829367cba61bd9b3beeaa7b7330f3ec65f Mon Sep 17 00:00:00 2001 From: v-kaywon Date: Fri, 11 Aug 2017 11:03:26 -0700 Subject: [PATCH 06/11] changed report.sql to report MB instead of Bytes --- test/Performance/report.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Performance/report.sql b/test/Performance/report.sql index 859e769a..5629abf2 100644 --- a/test/Performance/report.sql +++ b/test/Performance/report.sql @@ -2,7 +2,7 @@ select t1.ResultId, Test, Client, Server, Driver, Duration, Memory, Success, Team, StartTime from ( select pr.ResultId, pr.Success, pt.TestName as Test, cl.HostName as Client, srv.HostName as Server, -tm.TeamName as Team, st.value as Driver, bi.value as Duration, bi2.value as Memory, dt.value as StartTime from +tm.TeamName as Team, st.value as Driver, bi.value as Duration, CAST(bi2.value AS decimal(10,2))/1048576 as Memory, dt.value as StartTime from KeyValueTableBigInt bi, KeyValueTableBigInt bi2, KeyValueTableString st, From 0c8a4b731abcaff19f662cb31997477ecdd6c649 Mon Sep 17 00:00:00 2001 From: v-kaywon Date: Fri, 11 Aug 2017 11:05:11 -0700 Subject: [PATCH 07/11] fix msodbc installation with homebrew in setup_env_unix.sh --- test/Performance/setup_env_unix.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Performance/setup_env_unix.sh b/test/Performance/setup_env_unix.sh index e8a139dc..69caebb6 100644 --- a/test/Performance/setup_env_unix.sh +++ b/test/Performance/setup_env_unix.sh @@ -86,7 +86,7 @@ elif [ $PLATFORM = "Sierra" ]; then echo "Installing MSODBCSQL..." brew tap microsoft/msodbcsql https://github.com/Microsoft/homebrew-msodbcsql >> env_setup.log 2>&1 brew update >> env_setup.log 2>&1 - yes | ACCEPT_EULA=Y brew install msodbcsql >> env_setup.log 2>&1 + yes | ACCEPT_EULA=Y brew install --no-sandbox msodbcsql >> env_setup.log 2>&1 echo "OK" yes | brew install autoconf >> env_setup.log 2>&1 echo "Installing pyodbc..." From 463d30b0ade15a1887af8da687f38fa378a544af Mon Sep 17 00:00:00 2001 From: v-kaywon Date: Tue, 22 Aug 2017 09:41:56 -0700 Subject: [PATCH 08/11] resolve merge conflicts --- test/Performance/README.md | 44 +++-- test/Performance/compile_php.bat | 3 - test/Performance/setup_env_unix.sh | 220 +++++++++++++++++-------- test/Performance/setup_env_windows.ps1 | 110 ++++--------- 4 files changed, 209 insertions(+), 168 deletions(-) delete mode 100644 test/Performance/compile_php.bat diff --git a/test/Performance/README.md b/test/Performance/README.md index 1b2976e1..1929d1de 100644 --- a/test/Performance/README.md +++ b/test/Performance/README.md @@ -1,28 +1,32 @@ ## Setup Environment on a clean machine -### Windows -Install Visual Studio 2015 before running the following commands. Make sure C++ tools are enabled. -Run `cmd` as administrator. +The PHP zip file can be downloaded from . + +The SQLSRV and PDO_SQLSRV driver binaries can be downloaded from . + +### Windows +Install Visual Studio 2015 redistributable before running the following commands. +Run `Windows PowerShell` as administrator. - powershell Set-ExecutionPolicy Unrestricted - .\setup_env_windows.ps1 + .\setup_env_windows.ps1 ### Ubuntu 16 - sudo env "PATH=$PATH" bash setup_env_unix.sh Ubuntu16 + sudo env "PATH=$PATH" bash setup_env_unix.sh Ubuntu16 ### RedHat 7 - sudo env "PATH=$PATH" bash setup_env_unix.sh RedHat7 -### Sierra + sudo env "PATH=$PATH" bash setup_env_unix.sh RedHat7 +### MacOS 10.12 Sierra `brew` cannot be run with `sudo` on Sierra. Either enable passwordless `sudo` on the machine or enter the password when prompted. - bash setup_env_unix.sh Sierra + bash setup_env_unix.sh Sierra ## Run benchmarks PHPBench is used to run the benchmarks. Visit http://phpbench.readthedocs.io/en/latest/introduction.html to have an idea how the tool works. -### 1. Modify lib/connect.php with the test database credentials -### 2. Modify lib/result_db.php with the result database credentials -### 3. The number of iterations for each test can be modified in the test itself (e.g., in test/Performance/benchmark/sqlsrv). Each test has a @Iteration(n) annotation. If you change the number in this annotation, you will change the number of iterations run for this test. By default, most tests are set to 1000 iterations. -### 4. Execute run-perf_tests.py. +##### 1. Modify lib/connect.php with the test database credentials +##### 2. Modify lib/result_db.php with the result database credentials +##### 3. The number of iterations for each test can be modified in the test itself (e.g., in test/Performance/benchmark/sqlsrv). Each test has a @Iteration(n) annotation. If you change the number in this annotation, you will change the number of iterations run for this test. By default, most tests are set to 1000 iterations. +##### 4. Execute run-perf_tests.py. + ### Windows py.exe run-perf_tests.py -platform > tee run-perf_output.txt ### Linux and Mac @@ -30,6 +34,16 @@ On Linux and Mac, the script must be executed with `sudo python3` because to ena python3 run-perf_tests.py -platform | tee run-perf_output.txt -`-platform` - The platform that the tests are ran on. Must be one of the following: Windows10, WindowsServer2016, WindowsServer2012, Ubuntu16, RedHat7, Sierra +<<<<<<< HEAD +`-platform` - The platform that the tests are ran on. Must be one of the following: Windows10, WindowsServer2016, WindowsServer2012, Ubuntu16, RedHat7, Sierra. `-php-driver` (optional) - The driver that the tests are ran on. Must be one of the following: sqlsrv, pdo_sqlsrv, or both. Default is both. -`-test-only` (optional) - The test to run. Must be the file name (not including path) of one test or 'all'. Default is 'all'. If one test is specified, must also specify the -php-driver option to sqlsrv or pdo_sqlsrv. \ No newline at end of file +`-test-only` (optional) - The test to run. Must be the file name (not including path) of one test or 'all'. Default is 'all'. If one test is specified, must also specify the -php-driver option to sqlsrv or pdo_sqlsrv. +======= +`-platform` - The platform that the tests are ran on. Must be one of the following: Windows10, WindowsServer2016, WindowsServer2012, Ubuntu16, RedHat7, Sierra. +`-iterations` - The number of iterations for regular tests. +`-iterations-large` - The number of iterations for the tests that fetch large data. Usually set to 1. +`-result-server` - The server containing the result database. It is assumed that the result database s already setup before running the tests. +`-result-db` - Database name. With the current result database setup files, this should be set to `TestResults`. +`-result-uid` - Result database username. +`-result-pwd` - Result database password. +>>>>>>> upstream/dev diff --git a/test/Performance/compile_php.bat b/test/Performance/compile_php.bat deleted file mode 100644 index e08b0f3a..00000000 --- a/test/Performance/compile_php.bat +++ /dev/null @@ -1,3 +0,0 @@ -set options=%2 -set options=%options:"=% -C:\php-sdk\bin\phpsdk_setvars.bat && "c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" %1 && .\buildconf --force && .\configure %options% && nmake && nmake install \ No newline at end of file diff --git a/test/Performance/setup_env_unix.sh b/test/Performance/setup_env_unix.sh index 69caebb6..d5341bfd 100644 --- a/test/Performance/setup_env_unix.sh +++ b/test/Performance/setup_env_unix.sh @@ -1,72 +1,91 @@ #!/bin/bash + set -e + if [[ ("$1" = "Ubuntu16" || "$1" = "RedHat7" || "$1" = "Sierra") ]]; then PLATFORM=$1 else - echo "First argument must be one of Ubuntu16, RedHat7, Sierra. Exiting..." + echo "1st argument must be one of Ubuntu16, RedHat7, Sierra. Exiting..." exit 1 fi + if [[ "$2" != 7.*.* ]]; then - echo "Second argument must be PHP version in format of 7.x.x.Exiting..." + echo "2nd argument must be PHP version in format of 7.x.y. Exiting..." exit else PHP_VERSION=$2 fi + if [[ ("$3" != "nts" && "$3" != "ts") ]]; then - echo "Thrid argument must be either nts or ts. Exiting..." + echo "3rd argument must be either nts or ts. Exiting..." exit 1 else PHP_THREAD=$3 fi -if [[ (! -d "$4") || (! -d $4/sqlsrv) || (! -d $4/pdo_sqlsrv) || (! -d $4/shared) ]]; then - echo "Fourth argument must be path to source folder.Path not found.Exiting..." + +if [[ (! -f "$4") || (! -f "$5") ]]; then + echo "5th and 6th argument must be paths to sqlsrv and pdo drivers. Exiting..." exit 1 else - DRIVER_SOURCE_PATH=$4 + SQLSRV_DRIVER=$4 + PDO_DRIVER=$5 fi -rm -rf env_setup.log -touch env_setup.log + if [ $PLATFORM = "Ubuntu16" ]; then - echo "Update..." - yes | sudo dpkg --configure -a >> env_setup.log 2>&1 - yes | sudo apt-get update >> env_setup.log 2>&1 - echo "Installing git, zip, curl, libxml, autoconf, openssl, python3, pip3..." - yes | sudo apt-get install git zip curl autoconf libxml2-dev libssl-dev pkg-config python3 python3-pip >> env_setup.log 2>&1 - echo "OK" - echo "Installing MSODBCSQL..." + printf "Update..." + yes | sudo dpkg --configure -a > env_setup.log + yes | sudo apt-get update >> env_setup.log + printf "done\n" + + printf "Installing git, zip, curl, libxml, autoconf, openssl, python3, pip3..." + yes | sudo apt-get install git zip curl autoconf libxml2-dev libssl-dev pkg-config python3 python3-pip >> env_setup.log + printf "done\n" + + printf "Installing MSODBCSQL..." curl -s https://packages.microsoft.com/keys/microsoft.asc | apt-key add - curl -s https://packages.microsoft.com/config/ubuntu/16.04/prod.list > /etc/apt/sources.list.d/mssql-release.list - yes | sudo apt-get update >> env_setup.log 2>&1 - yes | sudo ACCEPT_EULA=Y apt-get install msodbcsql >> env_setup.log 2>&1 - yes | sudo apt-get install -qq unixodbc-dev >> env_setup.log 2>&1 - echo "Installing pyodbc" - pip3 install --upgrade pip >> env_setup.log 2>&1 - pip3 install pyodbc >> env_setup.log 2>&1 - echo "OK" + yes | sudo apt-get update >> env_setup.log + yes | sudo ACCEPT_EULA=Y apt-get install msodbcsql >> env_setup.log + yes | sudo apt-get install -qq unixodbc-dev >> env_setup.log + printf "done\n" + + printf "Installing pyodbc" + pip3 install --upgrade pip >> env_setup.log + pip3 install pyodbc >> env_setup.log + printf "done\n" + elif [ $PLATFORM = "RedHat7" ]; then - echo "Update..." - yes | sudo yum update >> env_setup.log 2>&1 - echo "OK" - echo "Enabling EPEL repo..." + printf "Update..." + yes | sudo yum update >> env_setup.log + printf "done\n" + + printf "Enabling EPEL repo..." +# pipe non-error to log file (wget and yum install reports error when there's nothing to do) wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm >> env_setup.log 2>&1 yes | sudo yum install epel-release-latest-7.noarch.rpm >> env_setup.log 2>&1 || true - echo "OK" - echo "Installing python34-setuptools..." - yes | sudo yum install python34-setuptools -y >> env_setup.log 2>&1 - echo "OK" - echo "Installing gcc, git, zip libxml, openssl, EPEL, python3, pip3..." - yes | sudo yum install -y gcc-c++ libxml2-devel git zip openssl-devel python34 python34-devel python34-pip >> env_setup.log 2>&1 - echo "OK" - echo "Installing MSODBCSQL..." + printf "done\n" + + printf "Installing python34-setuptools..." + yes | sudo yum install python34-setuptools -y >> env_setup.log + printf "done\n" + + printf "Installing gcc, git, zip libxml, openssl, EPEL, python3, pip3..." + yes | sudo yum install -y gcc-c++ libxml2-devel git zip openssl-devel python34 python34-devel python34-pip >> env_setup.log + printf "done\n" + + printf "Installing MSODBCSQL..." curl -s https://packages.microsoft.com/config/rhel/7/prod.repo > /etc/yum.repos.d/mssql-release.repo - (yes | sudo ACCEPT_EULA=Y yum install -y msodbcsql >> env_setup.log 2>&1) - (yes | sudo yum install -y unixODBC-devel autoconf >> env_setup.log 2>&1) - echo "OK" - echo "Installing pyodbc" - pip3 install --upgrade pip >> env_setup.log 2>&1 - pip3 install pyodbc >> env_setup.log 2>&1 - echo "OK" + (yes | sudo ACCEPT_EULA=Y yum install -y msodbcsql >> env_setup.log) + (yes | sudo yum install -y unixODBC-devel autoconf >> env_setup.log) + printf "done\n" + + printf "Installing pyodbc" + pip3 install --upgrade pip >> env_setup.log + pip3 install pyodbc >> env_setup.log + printf "done\n" + elif [ $PLATFORM = "Sierra" ]; then +<<<<<<< HEAD echo "Installing homebrew..." yes | /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" >> env_setup.log 2>&1 echo "OK" @@ -92,49 +111,108 @@ elif [ $PLATFORM = "Sierra" ]; then echo "Installing pyodbc..." pip3 install pyodbc >> env_setup.log 2>&1 echo "OK" +======= + printf "Installing homebrew..." + yes | /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" >> env_setup.log + printf "done\n" + + printf "Installing wget..." + brew install wget >> env_setup.log + printf "done\n" + + printf "Installing svn..." + brew install svn >> env_setup.log + printf "done\n" + + printf "Installing openssl..." + brew install pkg-config >> env_setup.log + brew install openssl >> env_setup.log + printf "done\n" + + printf "Installing python3..." + brew install python3 >> env_setup.log + printf "done\n" + + printf "Installing MSODBCSQL..." + brew tap microsoft/msodbcsql https://github.com/Microsoft/homebrew-msodbcsql >> env_setup.log + brew update >> env_setup.log + yes | ACCEPT_EULA=Y brew install --no-sandbox msodbcsql >> env_setup.log + printf "done\n" + + yes | brew install autoconf >> env_setup.log + printf "Installing pyodbc..." + pip3 install pyodbc >> env_setup.log + printf "done\n" +>>>>>>> upstream/dev fi -echo "Downloading PHP-$PHP_VERSION source tarball..." + +printf "Downloading PHP-$PHP_VERSION source tarball..." +# pipe non-error to log file wget http://ca1.php.net/get/php-$PHP_VERSION.tar.gz/from/this/mirror -O php-$PHP_VERSION.tar.gz >> env_setup.log 2>&1 -echo "OK" -echo "Extracting PHP source tarball..." +printf "done\n" + +printf "Extracting PHP source tarball..." rm -rf php-$PHP_VERSION tar -xf php-$PHP_VERSION.tar.gz -echo "OK" -cd php-$PHP_VERSION -mkdir ext/sqlsrv ext/pdo_sqlsrv -cp -r $DRIVER_SOURCE_PATH/sqlsrv/* $DRIVER_SOURCE_PATH/shared ext/sqlsrv -cp -r $DRIVER_SOURCE_PATH/pdo_sqlsrv/* $DRIVER_SOURCE_PATH/shared ext/pdo_sqlsrv +printf "done\n" + +phpDir=php-$PHP_VERSION +cd $phpDir + +printf "Configuring PHP..." ./buildconf --force >> ../env_setup.log 2>&1 -CONFIG_OPTIONS="--enable-cli --enable-cgi --enable-pdo --enable-sqlsrv=shared --with-pdo_sqlsrv=shared --with-odbcver=0x0380 --with-zlib --enable-mbstring --prefix=/usr/local" +CONFIG_OPTIONS="--enable-cli --enable-cgi --with-zlib --enable-mbstring --prefix=/usr/local" [ "${PHP_THREAD}" == "ts" ] && CONFIG_OPTIONS=${CONFIG_OPTIONS}" --enable-maintainer-zts" if [ $PLATFORM = "Sierra" ]; then CONFIG_OPTIONS=$CONFIG_OPTIONS" --with-openssl=/usr/local/opt/openssl/" else CONFIG_OPTIONS=$CONFIG_OPTIONS" --with-openssl" fi -echo "Configuring PHP..." +#pipe non-error to log file (./configure $CONFIG_OPTIONS >> ../env_setup.log 2>&1) -echo "OK" -echo "Compiling PHP and the drivers..." -make >> ../env_setup.log 2>&1 -echo "OK" -sudo make install >> ../env_setup.log 2>&1 +printf "done\n" + +printf "Compiling and installing PHP..." +make >> ../env_setup.log +sudo make install >> ../env_setup.log +printf "done\n" + +# check PHP version +/usr/local/bin/php -v + +printf "Setting up drivers..." +phpExtDir=`/usr/local/bin/php-config --extension-dir` cp php.ini-production php.ini -echo "extension=sqlsrv.so" >> php.ini -echo "extension=pdo_sqlsrv.so" >> php.ini +driverName=$(basename $SQLSRV_DRIVER) +echo "extension=$driverName" >> php.ini +sudo cp -r $SQLSRV_DRIVER $phpExtDir/$driverName +sudo chmod a+r $SQLSRV_DRIVER $phpExtDir/$driverName + +driverName=$(basename $PDO_DRIVER) +echo "extension=$driverName" >> php.ini +sudo cp -r $PDO_DRIVER $phpExtDir/$driverName +sudo chmod a+r $SQLSRV_DRIVER $phpExtDir/$driverName + sudo cp php.ini /usr/local/lib +printf "done\n" + +# check drivers +/usr/local/bin/php --ri sqlsrv +/usr/local/bin/php --ri pdo_sqlsrv + +printf "Installing Composer..." cd .. -php -v -php --ri sqlsrv -php --ri pdo_sqlsrv -echo "Installing Composer..." +# pipe non-error to log file wget https://getcomposer.org/installer -O composer-setup.php >> env_setup.log 2>&1 -php composer-setup.php >> env_setup.log 2>&1 -echo "OK" -echo "Installing PHPBench..." -php composer.phar install >> env_setup.log 2>&1 -echo "OK" -echo "Cleaning up..." -rm -rf php-$PHP_VERSION* compser-setup.php -echo "OK" -echo "Setup completed!" \ No newline at end of file +/usr/local/bin/php composer-setup.php >> env_setup.log +printf "done\n" + +printf "Installing PHPBench...\n" +/usr/local/bin/php composer.phar install >> env_setup.log +printf "done\n" + +printf "Cleaning up..." +rm -rf $phpDir compser-setup.php +printf "done\n" + +echo "Setup completed!" diff --git a/test/Performance/setup_env_windows.ps1 b/test/Performance/setup_env_windows.ps1 index c4a580e5..a6b83633 100644 --- a/test/Performance/setup_env_windows.ps1 +++ b/test/Performance/setup_env_windows.ps1 @@ -1,28 +1,13 @@ Param( [Parameter(Mandatory=$True,Position=1)] - [string]$PHP_VERSION, - [Parameter(Mandatory=$True,Position=2)] - [string]$PHP_THREAD, + [string]$PHP_ZIP, + [Parameter(Mandatory=$True,Position=2)] + [string]$SQLSRV_DRIVER, [Parameter(Mandatory=$True,Position=3)] - [string]$DRIVER_SOURCE_PATH, -[Parameter(Mandatory=$True,Position=4)] - [string]$ARCH + [string]$PDO_DRIVER ) -IF($ARCH -ne "x64" -And $ARCH -ne "x86"){ - Write-Host "ARCH must either x64 or x86" - Break -} - -IF($PHP_THREAD -ne "nts" -And $PHP_THREAD -ne "ts"){ - Write-Host "PHP_THREAD must either nts or ts" - Break -} - -IF($PHP_VERSION -NotMatch "7.[0-1].[0-9]"){ - Write-Host "PHP_VERSION must be in format of 7.x.x" - Break -} +$ErrorActionPreference = "Stop" $startingDir=$pwd.Path $tempFolder=Join-Path $startingDir "temp" @@ -30,17 +15,12 @@ $tempFolder=Join-Path $startingDir "temp" Remove-Item temp -Recurse -Force -ErrorAction Ignore New-Item -ItemType directory -Path temp -(New-Object System.Net.WebClient).DownloadFile("http://windows.php.net/downloads/releases/sha1sum.txt","$tempFolder\sha1sum.txt") -$PHP70_LATEST_VERSION=type $tempFolder\sha1sum.txt | where { $_ -match "php-(7.0\.\d+)-src" } | foreach { $matches[1] } -$PHP71_LATEST_VERSION=type $tempFolder\sha1sum.txt | where { $_ -match "php-(7.1\.\d+)-src" } | foreach { $matches[1] } - -$PHP_VERSION_MINOR=$PHP_VERSION.split(".")[1] - Write-Host "Installing chocolatey..." iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1')) Write-Host "Installing Git..." choco install -y git -Set-Alias git 'C:\Program Files\Git\cmd\git.exe' + +$gitDir = 'C:\Program Files\Git\cmd\git.exe' Write-Host "Installing Python3..." choco install -y python3 RefreshEnv @@ -54,65 +34,37 @@ msiexec /quiet /passive /qn /i $tempFolder\msodbcsql.msi IACCEPTMSODBCSQLLICENSE Write-Host "Installing 7-Zip..." choco install -y 7zip.install -Write-Host "Downloading PHP-SDK..." -(New-Object System.Net.WebClient).DownloadFile('http://windows.php.net/downloads/php-sdk/php-sdk-binary-tools-20110915.zip', "$tempFolder\binary_tools.zip") -Write-Host "Downloading PHP-$PHP_VERSION source..." -IF($PHP_VERSION -eq $PHP70_LATEST_VERSION -Or $PHP_VERSION -eq $PHP71_LATEST_VERSION){ -(New-Object System.Net.WebClient).DownloadFile("http://windows.php.net/downloads/releases/php-$PHP_VERSION-src.zip", "$tempFolder\php-$PHP_VERSION-src.zip") -} -ELSE{ -(New-Object System.Net.WebClient).DownloadFile("http://windows.php.net/downloads/releases/archives/php-$PHP_VERSION-src.zip", "$tempFolder\php-$PHP_VERSION-src.zip") -} +Write-Host "Installing PHP..." +$phpDir="C:\php" -Write-Host "Downloading Dependencies..." -(New-Object System.Net.WebClient).DownloadFile("http://windows.php.net/downloads/php-sdk/deps-7.$PHP_VERSION_MINOR-vc14-$ARCH.7z", "$tempFolder\deps-7.$PHP_VERSION_MINOR-vc14-$ARCH.7z") +# remove existing PHP and setup new one +Remove-Item $phpDir -Recurse -ErrorAction Ignore +New-Item -ItemType directory -Path $phpDir +Expand-Archive $PHP_ZIP -DestinationPath $phpDir +Copy-Item $SQLSRV_DRIVER $phpDir\ext +Copy-Item $PDO_DRIVER $phpDir\ext -Add-Type -AssemblyName System.IO.Compression.FileSystem -Remove-Item C:\php-sdk -Recurse -Force -ErrorAction Ignore -New-Item -ItemType directory -Path C:\php-sdk -[System.IO.Compression.ZipFile]::ExtractToDirectory("$tempFolder\binary_tools.zip", "C:\php-sdk") -cd C:\php-sdk\ -bin\phpsdk_buildtree.bat phpdev -New-Item -ItemType directory -Path .\phpdev\vc14 -Copy-Item .\phpdev\vc9\* phpdev\vc14\ -recurse -[System.IO.Compression.ZipFile]::ExtractToDirectory("$tempFolder\php-$PHP_VERSION-src.zip", "C:\php-sdk\phpdev\vc14\$ARCH\") -7z.exe x $tempFolder\deps-7.$PHP_VERSION_MINOR-vc14-$ARCH.7z -oC:\php-sdk\phpdev\vc14\$ARCH\ +# setup driver +Copy-Item $phpDir\php.ini-production $phpDir\php.ini +Add-Content $phpDir\php.ini "extension=$phpDir\ext\php_openssl.dll" +Add-Content $phpDir\php.ini "extension=$phpDir\ext\php_mbstring.dll" -bin\phpsdk_setvars.bat - -cd C:\php-sdk\phpdev\vc14\$ARCH\php-$PHP_VERSION-src - -New-Item -ItemType directory -Path .\ext\sqlsrv -New-Item -ItemType directory -Path .\ext\pdo_sqlsrv -Copy-Item $DRIVER_SOURCE_PATH\sqlsrv\* .\ext\sqlsrv\ -recurse -Copy-Item $DRIVER_SOURCE_PATH\shared\ .\ext\sqlsrv\ -recurse -Copy-Item $DRIVER_SOURCE_PATH\pdo_sqlsrv\* .\ext\pdo_sqlsrv\ -recurse -Copy-Item $DRIVER_SOURCE_PATH\shared\ .\ext\pdo_sqlsrv\ -recurse - - -$CONFIG_OPTIONS="--enable-cli --enable-cgi --enable-sqlsrv=shared --enable-pdo=shared --with-pdo-sqlsrv=shared --with-odbcver=0x0380 --enable-mbstring --with-openssl" -if ($PHP_THREAD -ceq "nts") { - $CONFIG_OPTIONS=$CONFIG_OPTIONS + " --disable-zts" -} -& $startingDir\compile_php.bat $ARCH $CONFIG_OPTIONS - - - - -Copy-Item php.ini-production php.ini -Add-Content php.ini "extension=C:\php\ext\php_sqlsrv.dll" -Add-Content php.ini "extension=C:\php\ext\php_pdo_sqlsrv.dll" -Add-Content php.ini "extension=C:\php\ext\php_openssl.dll" -Move-Item php.ini C:\Windows -force -Copy-Item C:\php-sdk\phpdev\vc14\$ARCH\deps\bin\ssleay32.dll C:\Windows -force -Copy-Item C:\php-sdk\phpdev\vc14\$ARCH\deps\bin\libeay32.dll C:\Windows -force +$driverName=Split-Path $SQLSRV_DRIVER -leaf +Add-Content $phpDir\php.ini "extension=$phpDir\ext\$driverName" +$driverName=Split-Path $PDO_DRIVER -leaf +Add-Content $phpDir\php.ini "extension=$phpDir\ext\$driverName" +Move-Item $phpDir\php.ini C:\Windows -force +Copy-Item $phpDir\ssleay32.dll C:\Windows -force +Copy-Item $phpDir\libeay32.dll C:\Windows -force cd $startingDir -[Environment]::SetEnvironmentVariable("Path", $env:Path + ";C:\php\", [System.EnvironmentVariableTarget]::Machine) -$env:Path += ";C:\php\" +[Environment]::SetEnvironmentVariable("Path", $env:Path + ";" + $phpDir + ";" + $gitDir, [System.EnvironmentVariableTarget]::Machine) +$env:Path = $env:Path + ";" + $phpDir + ";" + $gitDir RefreshEnv + +# setup composer wget https://getcomposer.org/installer -O composer-setup.php php composer-setup.php php composer.phar install Remove-Item temp -Recurse -Force -ErrorAction Ignore -Write-Host "Setup completed!" \ No newline at end of file +Write-Host "Setup completed!" From 5990f6e7b6383791d48feb2127ea390b4d8eac86 Mon Sep 17 00:00:00 2001 From: v-kaywon Date: Tue, 22 Aug 2017 16:15:33 -0700 Subject: [PATCH 09/11] applied review comments --- test/Performance/README.md | 4 +- .../pdo_sqlsrv/PDOConnectionBench.php | 11 +- .../pdo_sqlsrv/PDOCreateDbTableProcBench.php | 14 ++- .../benchmark/pdo_sqlsrv/PDODeleteBench.php | 35 ++++-- .../benchmark/pdo_sqlsrv/PDOFetchBench.php | 32 +++-- .../pdo_sqlsrv/PDOFetchLargeBench.php | 15 ++- .../benchmark/pdo_sqlsrv/PDOInsertBench.php | 29 +++-- .../pdo_sqlsrv/PDOSelectVersionBench.php | 12 +- .../benchmark/pdo_sqlsrv/PDOUpdateBench.php | 38 ++++-- .../sqlsrv/SqlsrvConnectionBench.php | 11 +- .../sqlsrv/SqlsrvCreateDbTableProcBench.php | 14 ++- .../benchmark/sqlsrv/SqlsrvDeleteBench.php | 35 ++++-- .../benchmark/sqlsrv/SqlsrvFetchBench.php | 34 +++-- .../sqlsrv/SqlsrvFetchLargeBench.php | 15 ++- .../benchmark/sqlsrv/SqlsrvInsertBench.php | 29 +++-- .../sqlsrv/SqlsrvSelectVersionBench.php | 12 +- .../benchmark/sqlsrv/SqlsrvUpdateBench.php | 38 ++++-- test/Performance/lib/CRUDBaseBenchmark.php | 9 ++ test/Performance/lib/PDOSqlsrvUtil.php | 113 +++++++++++------ test/Performance/lib/SqlsrvUtil.php | 119 ++++++++++++------ test/Performance/report.sql | 6 +- test/Performance/run-perf_tests.py | 8 +- 22 files changed, 416 insertions(+), 217 deletions(-) create mode 100644 test/Performance/lib/CRUDBaseBenchmark.php diff --git a/test/Performance/README.md b/test/Performance/README.md index b45fb9e0..a1893e1e 100644 --- a/test/Performance/README.md +++ b/test/Performance/README.md @@ -28,7 +28,7 @@ PHPBench is used to run the benchmarks. Visit http://phpbench.readthedocs.io/en/ ##### 4. Execute run-perf_tests.py. ### Windows - py.exe run-perf_tests.py -platform > tee run-perf_output.txt + py.exe run-perf_tests.py -platform ### Linux and Mac On Linux and Mac, the script must be executed with `sudo python3` because to enable pooling it needs to modify odbcinst.ini system file. As an improvement, the location of the odbcinst.ini file can be changed so that, sudo is not requiered. @@ -36,4 +36,4 @@ On Linux and Mac, the script must be executed with `sudo python3` because to ena `-platform` - The platform that the tests are ran on. Must be one of the following: Windows10, WindowsServer2016, WindowsServer2012, Ubuntu16, RedHat7, Sierra. `-php-driver` (optional) - The driver that the tests are ran on. Must be one of the following: sqlsrv, pdo_sqlsrv, or both. Default is both. -`-test-only` (optional) - The test to run. Must be the file name (not including path) of one test or 'all'. Default is 'all'. If one test is specified, must also specify the -php-driver option to sqlsrv or pdo_sqlsrv. \ No newline at end of file +`-testname` (optional) - The test to run. Must be the file name (not including path) of one test or 'all'. Default is 'all'. If one test is specified, must also specify the -php-driver option to sqlsrv or pdo_sqlsrv. \ No newline at end of file diff --git a/test/Performance/benchmark/pdo_sqlsrv/PDOConnectionBench.php b/test/Performance/benchmark/pdo_sqlsrv/PDOConnectionBench.php index ed907ae9..9e995b34 100644 --- a/test/Performance/benchmark/pdo_sqlsrv/PDOConnectionBench.php +++ b/test/Performance/benchmark/pdo_sqlsrv/PDOConnectionBench.php @@ -1,14 +1,15 @@ conn = PDOSqlsrvUtil::connect(); } /* * Each iteration creates a database, a table and a stored procedure in that database and drops the database at the end. * Note that, execDirect function are used to execute all the queries. */ - public function benchCreateDbTableProc(){ + public function benchCreateDbTableProc() + { $randomNum = rand(); $databaseName = "test_db_$randomNum"; $tableName = "test_table_$randomNum"; @@ -25,7 +28,8 @@ class PDOCreateDbTableProcBench{ PDOSqlsrvUtil::dropDatabase( $this->conn, $databaseName ); } - public function disconnect(){ + public function disconnect() + { PDOSqlsrvUtil::disconnect( $this->conn ); } } diff --git a/test/Performance/benchmark/pdo_sqlsrv/PDODeleteBench.php b/test/Performance/benchmark/pdo_sqlsrv/PDODeleteBench.php index fd3d1a89..e14b26ff 100644 --- a/test/Performance/benchmark/pdo_sqlsrv/PDODeleteBench.php +++ b/test/Performance/benchmark/pdo_sqlsrv/PDODeleteBench.php @@ -1,35 +1,42 @@ tableName = "datatypes_".rand(); } - public function connect(){ + public function connect() + { $this->conn = PDOSqlsrvUtil::connect(); } - public function createTable(){ + public function createTable() + { PDOSqlsrvUtil::createCRUDTable( $this->conn, $this->tableName ); } - public function generateInsertValues(){ + public function generateInsertValues() + { $this->insertValues = PDOSqlsrvUtil::generateInsertValues(); } - public function insertWithPrepare(){ - for( $i=0; $i<100; $i++ ){ + public function insertWithPrepare() + { + for( $i=0; $iconn, $this->tableName, $this->insertValues ); } } @@ -37,17 +44,21 @@ class PDODeleteBench{ * Each iteration inserts 1000 rows into the table, benchDelete deletes top row from the table 1000 times. * Note that, every delete calls prepare and execute APIs. */ - public function benchDelete(){ - for( $i=0; $i<100; $i++ ){ + public function benchDelete() + { + for( $i=0; $iconn, $this->tableName ); } } - public function dropTable(){ + public function dropTable() + { PDOSqlsrvUtil::dropTable( $this->conn, $this->tableName ); } - public function disconnect(){ + public function disconnect() + { PDOSqlsrvUtil::disconnect( $this->conn ); } diff --git a/test/Performance/benchmark/pdo_sqlsrv/PDOFetchBench.php b/test/Performance/benchmark/pdo_sqlsrv/PDOFetchBench.php index 9c20bdf2..9601382a 100644 --- a/test/Performance/benchmark/pdo_sqlsrv/PDOFetchBench.php +++ b/test/Performance/benchmark/pdo_sqlsrv/PDOFetchBench.php @@ -1,33 +1,39 @@ tableName = "datatypes_".rand(); } - public function connect(){ + public function connect() + { $this->conn = PDOSqlsrvUtil::connect(); } - public function createTable(){ + public function createTable() + { PDOSqlsrvUtil::createCRUDTable( $this->conn, $this->tableName ); } - public function generateInsertValues(){ + public function generateInsertValues() + { $this->insertValues = PDOSqlsrvUtil::generateInsertValues(); } - public function insertWithPrepare(){ + public function insertWithPrepare() + { PDOSqlsrvUtil::insertWithPrepare( $this->conn, $this->tableName, $this->insertValues ); } @@ -35,17 +41,21 @@ class PDOFetchBench{ * Each iteration inserts a row into the table, benchFetchWithPrepare() fetches that row 1000 times. * Note that, every fetch calls prepare, execute and fetch APIs. */ - public function benchFetchWithPrepare(){ - for( $i=0; $i<100; $i++){ + public function benchFetchWithPrepare() + { + for( $i=0; $iconn, $this->tableName ); } } - public function dropTable(){ + public function dropTable() + { PDOSqlsrvUtil::dropTable( $this->conn, $this->tableName ); } - public function disconnect(){ + public function disconnect() + { PDOSqlsrvUtil::disconnect( $this->conn ); } } diff --git a/test/Performance/benchmark/pdo_sqlsrv/PDOFetchLargeBench.php b/test/Performance/benchmark/pdo_sqlsrv/PDOFetchLargeBench.php index af7a0ad0..26fab48c 100644 --- a/test/Performance/benchmark/pdo_sqlsrv/PDOFetchLargeBench.php +++ b/test/Performance/benchmark/pdo_sqlsrv/PDOFetchLargeBench.php @@ -6,27 +6,32 @@ use PDOSqlsrvPerfTest\PDOSqlsrvUtil; * @BeforeMethods({"connect", "setTableName" }) * @AfterMethods({ "disconnect"}) */ -class PDOFetchLargeBench{ +class PDOFetchLargeBench +{ private $conn; private $tableName; - public function setTableName(){ + public function setTableName() + { //Assumes the table is already populated with data $this->tableName = "LargeDB.dbo.datatypes"; } - public function connect(){ + public function connect() + { $this->conn = PDOSqlsrvUtil::connect(); } /* * Each iteration calls prepare, execute and fetch APIs to fetch the already populdated data */ - public function benchFetchWithPrepare(){ + public function benchFetchWithPrepare() + { PDOSqlsrvUtil::fetchWithPrepare( $this->conn, $this->tableName ); } - public function disconnect(){ + public function disconnect() + { PDOSqlsrvUtil::disconnect( $this->conn ); } } diff --git a/test/Performance/benchmark/pdo_sqlsrv/PDOInsertBench.php b/test/Performance/benchmark/pdo_sqlsrv/PDOInsertBench.php index 5edbe12b..99d47948 100644 --- a/test/Performance/benchmark/pdo_sqlsrv/PDOInsertBench.php +++ b/test/Performance/benchmark/pdo_sqlsrv/PDOInsertBench.php @@ -1,46 +1,55 @@ tableName = "datatypes_".rand(); } - public function connect(){ + public function connect() + { $this->conn = PDOSqlsrvUtil::connect(); } - public function createTable(){ + public function createTable() + { PDOSqlsrvUtil::createCRUDTable( $this->conn, $this->tableName ); } - public function generateInsertValues(){ + public function generateInsertValues() + { $this->insertValues = PDOSqlsrvUtil::generateInsertValues(); } /** * Each iteration inserts 1000 rows into the table. * Note that, every insertion calls prepare, bindParam and execute APIs. */ - public function benchInsertWithPrepare(){ - for ( $i=0; $i<100; $i++){ + public function benchInsertWithPrepare() + { + for ( $i=0; $iconn, $this->tableName, $this->insertValues ); } } - public function dropTable(){ + public function dropTable() + { PDOSqlsrvUtil::dropTable( $this->conn, $this->tableName ); } - public function disconnect(){ + public function disconnect() + { PDOSqlsrvUtil::disconnect( $this->conn ); } } diff --git a/test/Performance/benchmark/pdo_sqlsrv/PDOSelectVersionBench.php b/test/Performance/benchmark/pdo_sqlsrv/PDOSelectVersionBench.php index c7c05a9b..23631e26 100644 --- a/test/Performance/benchmark/pdo_sqlsrv/PDOSelectVersionBench.php +++ b/test/Performance/benchmark/pdo_sqlsrv/PDOSelectVersionBench.php @@ -6,21 +6,25 @@ use PDOSqlsrvPerfTest\PDOSqlsrvUtil; * @BeforeMethods({"connect"}) * @AfterMethods({"disconnect"}) */ -class PDOSelectVersionBench{ +class PDOSelectVersionBench +{ private $conn; - public function connect(){ + public function connect() + { $this->conn = PDOSqlsrvUtil::connect(); } /* * Each iteration calls execDirect API to fetch @@Version */ - public function benchSelectVersion(){ + public function benchSelectVersion() + { $version = PDOSqlsrvUtil::selectVersion( $this->conn ); } - public function disconnect(){ + public function disconnect() + { PDOSqlsrvUtil::disconnect( $this->conn ); } } diff --git a/test/Performance/benchmark/pdo_sqlsrv/PDOUpdateBench.php b/test/Performance/benchmark/pdo_sqlsrv/PDOUpdateBench.php index cac76e26..cceaac60 100644 --- a/test/Performance/benchmark/pdo_sqlsrv/PDOUpdateBench.php +++ b/test/Performance/benchmark/pdo_sqlsrv/PDOUpdateBench.php @@ -1,12 +1,13 @@ tableName = "datatypes_".rand(); } - public function connect(){ + public function connect() + { $this->conn = PDOSqlsrvUtil::connect(); } - public function createTable(){ + public function createTable() + { PDOSqlsrvUtil::createCRUDTable( $this->conn, $this->tableName ); } - public function generateInsertValues(){ + public function generateInsertValues() + { $this->insertValues = PDOSqlsrvUtil::generateInsertValues(); } - public function insertWithPrepare(){ + public function insertWithPrepare() + { PDOSqlsrvUtil::insertWithPrepare( $this->conn, $this->tableName, $this->insertValues ); } - public function generateUpdateValues(){ + public function generateUpdateValues() + { $this->updateValues = PDOSqlsrvUtil::generateUpdateValues(); } - public function generateUpdateParams(){ + public function generateUpdateParams() + { $this->updateParams = PDOSqlsrvUtil::generateUpdateParams(); } /** * Each iteration inserts a row into the table, updateWithPrepare() updates that row 1000 times. * Note that, every update calls prepare, bindParam and execute APIs. */ - public function benchUpdateWithPrepare(){ - for( $i=0; $i<100; $i++ ){ + public function benchUpdateWithPrepare() + { + for( $i=0; $iconn, $this->tableName, $this->updateValues, $this->updateParams ); } } - public function dropTable(){ + public function dropTable() + { PDOSqlsrvUtil::dropTable( $this->conn, $this->tableName ); } - public function disconnect(){ + public function disconnect() + { PDOSqlsrvUtil::disconnect( $this->conn ); } diff --git a/test/Performance/benchmark/sqlsrv/SqlsrvConnectionBench.php b/test/Performance/benchmark/sqlsrv/SqlsrvConnectionBench.php index f8fb0211..648a77db 100644 --- a/test/Performance/benchmark/sqlsrv/SqlsrvConnectionBench.php +++ b/test/Performance/benchmark/sqlsrv/SqlsrvConnectionBench.php @@ -1,14 +1,15 @@ conn = SqlsrvUtil::connect(); } @@ -17,7 +19,8 @@ class SqlsrvCreateDbTableProcBench{ * Each iteration creates a database, a table and a stored procedure in that database and drops the database at the end. * Note that, ODBC SQLExecDirect function are used to execute all the queries. */ - public function benchCreateDbTableProc(){ + public function benchCreateDbTableProc() + { $randomNum = rand(); $databaseName = "test_db_$randomNum"; $tableName = "test_table_$randomNum"; @@ -26,7 +29,8 @@ class SqlsrvCreateDbTableProcBench{ SqlsrvUtil::dropDatabase( $this->conn, $databaseName ); } - public function disconnect(){ + public function disconnect() + { SqlsrvUtil::disconnect( $this->conn ); } } diff --git a/test/Performance/benchmark/sqlsrv/SqlsrvDeleteBench.php b/test/Performance/benchmark/sqlsrv/SqlsrvDeleteBench.php index e68d88b1..73103c01 100644 --- a/test/Performance/benchmark/sqlsrv/SqlsrvDeleteBench.php +++ b/test/Performance/benchmark/sqlsrv/SqlsrvDeleteBench.php @@ -1,35 +1,42 @@ tableName = "datatypes_".rand(); } - public function connect(){ + public function connect() + { $this->conn = SqlsrvUtil::connect(); } - public function createTable(){ + public function createTable() + { SqlsrvUtil::createCRUDTable( $this->conn, $this->tableName ); } - public function generateInsertValues(){ + public function generateInsertValues() + { $this->insertValues = SqlsrvUtil::generateInsertValues(); } - public function insertWithPrepare(){ - for ( $i=0; $i<100; $i++ ){ + public function insertWithPrepare() + { + for ( $i=0; $iconn, $this->tableName, $this->insertValues ); } } @@ -37,17 +44,21 @@ class SqlsrvDeleteBench{ * Each iteration inserts 1000 rows into the table, benchDelete deletes top row from the table 1000 times. * Note that, every delete calls prepare and execute APIs. */ - public function benchDelete(){ - for( $i=0; $i<100; $i++ ){ + public function benchDelete() + { + for( $i=0; $iconn, $this->tableName ); } } - public function dropTable(){ + public function dropTable() + { SqlsrvUtil::dropTable( $this->conn, $this->tableName ); } - public function disconnect(){ + public function disconnect() + { SqlsrvUtil::disconnect( $this->conn ); } diff --git a/test/Performance/benchmark/sqlsrv/SqlsrvFetchBench.php b/test/Performance/benchmark/sqlsrv/SqlsrvFetchBench.php index b92d5f7e..ec06709d 100644 --- a/test/Performance/benchmark/sqlsrv/SqlsrvFetchBench.php +++ b/test/Performance/benchmark/sqlsrv/SqlsrvFetchBench.php @@ -1,36 +1,40 @@ tableName = "datatypes_".rand(); } - public function connect(){ + public function connect() + { $this->conn = SqlsrvUtil::connect(); } - public function createTable(){ + public function createTable() + { SqlsrvUtil::createCRUDTable( $this->conn, $this->tableName ); } - public function generateInsertValues(){ + public function generateInsertValues() + { $this->insertValues = SqlsrvUtil::generateInsertValues(); } - public function insertWithPrepare(){ + public function insertWithPrepare() + { SqlsrvUtil::insertWithPrepare( $this->conn, $this->tableName, $this->insertValues ); } @@ -38,17 +42,21 @@ class SqlsrvFetchBench{ * Each iteration inserts a row into the table, benchFetchWithPrepare() fetches that row 1000 times. * Note that, every fetch calls prepare, execute and fetch APIs. */ - public function benchFetchWithPrepare(){ - for( $i=0; $i<100; $i++){ + public function benchFetchWithPrepare() + { + for( $i=0; $iconn, $this->tableName ); } } - public function dropTable(){ + public function dropTable() + { SqlsrvUtil::dropTable( $this->conn, $this->tableName ); } - public function disconnect(){ + public function disconnect() + { SqlsrvUtil::disconnect( $this->conn ); } } diff --git a/test/Performance/benchmark/sqlsrv/SqlsrvFetchLargeBench.php b/test/Performance/benchmark/sqlsrv/SqlsrvFetchLargeBench.php index 2bda236a..24dee142 100644 --- a/test/Performance/benchmark/sqlsrv/SqlsrvFetchLargeBench.php +++ b/test/Performance/benchmark/sqlsrv/SqlsrvFetchLargeBench.php @@ -6,27 +6,32 @@ use SqlsrvPerfTest\SqlsrvUtil; * @BeforeMethods({"connect", "setTableName" }) * @AfterMethods({ "disconnect"}) */ -class SqlsrvFetchLargeBench{ +class SqlsrvFetchLargeBench +{ private $conn; private $tableName; - public function setTableName(){ + public function setTableName() + { //Assumes the table is already populated with data $this->tableName = "LargeDB.dbo.datatypes"; } - public function connect(){ + public function connect() + { $this->conn = SqlsrvUtil::connect(); } /* * Each iteration calls prepare, execute and fetch APIs to fetch the already populdated data */ - public function benchFetchWithPrepare(){ + public function benchFetchWithPrepare() + { SqlsrvUtil::fetchWithPrepare( $this->conn, $this->tableName ); } - public function disconnect(){ + public function disconnect() + { SqlsrvUtil::disconnect( $this->conn ); } } diff --git a/test/Performance/benchmark/sqlsrv/SqlsrvInsertBench.php b/test/Performance/benchmark/sqlsrv/SqlsrvInsertBench.php index ebd7d21f..1d1c2a9f 100644 --- a/test/Performance/benchmark/sqlsrv/SqlsrvInsertBench.php +++ b/test/Performance/benchmark/sqlsrv/SqlsrvInsertBench.php @@ -1,47 +1,56 @@ tableName = "datatypes_".rand(); } - public function connect(){ + public function connect() + { $this->conn = SqlsrvUtil::connect(); } - public function createTable(){ + public function createTable() + { SqlsrvUtil::createCRUDTable( $this->conn, $this->tableName ); } - public function generateInsertValues(){ + public function generateInsertValues() + { $this->insertValues = SqlsrvUtil::generateInsertValues(); } /** * Each iteration inserts 1000 rows into the table. * Note that, every insertion calls prepare, bindParam and execute APIs. */ - public function benchInsertWithPrepare(){ - for( $i=0; $i<100; $i++ ){ + public function benchInsertWithPrepare() + { + for( $i=0; $iconn, $this->tableName, $this->insertValues ); } } - public function dropTable(){ + public function dropTable() + { SqlsrvUtil::dropTable( $this->conn, $this->tableName ); } - public function disconnect(){ + public function disconnect() + { SqlsrvUtil::disconnect( $this->conn ); } } diff --git a/test/Performance/benchmark/sqlsrv/SqlsrvSelectVersionBench.php b/test/Performance/benchmark/sqlsrv/SqlsrvSelectVersionBench.php index b89bc429..8f640460 100644 --- a/test/Performance/benchmark/sqlsrv/SqlsrvSelectVersionBench.php +++ b/test/Performance/benchmark/sqlsrv/SqlsrvSelectVersionBench.php @@ -6,21 +6,25 @@ use SqlsrvPerfTest\SqlsrvUtil; * @BeforeMethods({"connect"}) * @AfterMethods({"disconnect"}) */ -class SqlsrvSelectVersionBench{ +class SqlsrvSelectVersionBench +{ private $conn; - public function connect(){ + public function connect() + { $this->conn = SqlsrvUtil::connect(); } /* * Each iteration calls execDirect API to fetch @@Version */ - public function benchSelectVersion(){ + public function benchSelectVersion() + { $version = SqlsrvUtil::selectVersion( $this->conn ); } - public function disconnect(){ + public function disconnect() + { SqlsrvUtil::disconnect( $this->conn ); } } diff --git a/test/Performance/benchmark/sqlsrv/SqlsrvUpdateBench.php b/test/Performance/benchmark/sqlsrv/SqlsrvUpdateBench.php index 0d31b881..de86cc82 100644 --- a/test/Performance/benchmark/sqlsrv/SqlsrvUpdateBench.php +++ b/test/Performance/benchmark/sqlsrv/SqlsrvUpdateBench.php @@ -1,12 +1,13 @@ tableName = "datatypes_".rand(); } - public function connect(){ + public function connect() + { $this->conn = SqlsrvUtil::connect(); } - public function createTable(){ + public function createTable() + { SqlsrvUtil::createCRUDTable( $this->conn, $this->tableName ); } - public function generateInsertValues(){ + public function generateInsertValues() + { $this->insertValues = SqlsrvUtil::generateInsertValues(); } - public function insertWithPrepare(){ + public function insertWithPrepare() + { SqlsrvUtil::insertWithPrepare( $this->conn, $this->tableName, $this->insertValues ); } - public function generateUpdateValues(){ + public function generateUpdateValues() + { $this->updateValues = SqlsrvUtil::generateUpdateValues(); } - public function generateUpdateParams(){ + public function generateUpdateParams() + { $this->updateParams = SqlsrvUtil::generateUpdateParams(); } /** * Each iteration inserts a row into the table, updateWithPrepare() updates that row 1000 times. * Note that, every update calls prepare, bindParam and execute APIs. */ - public function benchUpdateWithPrepare(){ - for( $i=0; $i<100; $i++ ){ + public function benchUpdateWithPrepare() + { + for( $i=0; $iconn, $this->tableName, $this->updateValues, $this->updateParams ); } } - public function dropTable(){ + public function dropTable() + { SqlsrvUtil::dropTable( $this->conn, $this->tableName ); } - public function disconnect(){ + public function disconnect() + { SqlsrvUtil::disconnect( $this->conn ); } diff --git a/test/Performance/lib/CRUDBaseBenchmark.php b/test/Performance/lib/CRUDBaseBenchmark.php new file mode 100644 index 00000000..b8c07de5 --- /dev/null +++ b/test/Performance/lib/CRUDBaseBenchmark.php @@ -0,0 +1,9 @@ + \ No newline at end of file diff --git a/test/Performance/lib/PDOSqlsrvUtil.php b/test/Performance/lib/PDOSqlsrvUtil.php index 2e82a476..d553b1c4 100644 --- a/test/Performance/lib/PDOSqlsrvUtil.php +++ b/test/Performance/lib/PDOSqlsrvUtil.php @@ -2,32 +2,41 @@ namespace PDOSqlsrvPerfTest; use PDO; -class PDOSqlsrvUtil{ +class PDOSqlsrvUtil +{ - public static function connect(){ + public static $loopsPerCRUDIter = 100; + + public static function connect() + { require dirname(__FILE__).DIRECTORY_SEPARATOR.'connect.php'; - try{ + try + { $conn = new PDO( "sqlsrv:Server=$server; Database=$database; ConnectionPooling=$pooling; MultipleActiveResultSets=$mars" , $uid, $pwd ); $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); return $conn; } - catch( PDOException $e ){ + catch( PDOException $e ) + { var_dump( $e ); exit; } } - public static function disconnect( $conn ){ + public static function disconnect( $conn ) + { $conn = null; } - public static function selectVersion( $conn ){ + public static function selectVersion( $conn ) + { $sql = "SELECT @@Version"; $stmt = self::query( $conn, $sql ); return self::fetch( $stmt ); } - public static function createDbTableProc( $conn, $databaseName, $tableName, $procName ){ + public static function createDbTableProc( $conn, $databaseName, $tableName, $procName ) + { $tableParams = "id INTEGER, name VARCHAR(32), value INTEGER, start_date DATE, time_added TIMESTAMP, set_time TIME(7)"; $procParams = "@id INTEGER, @name VARCHAR(32)"; $procTextBase = "SET NOCOUNT ON; SELECT id, name, value FROM $databaseName.$tableName WHERE id = @id AND name = @name"; @@ -37,7 +46,8 @@ class PDOSqlsrvUtil{ self::createStoredProc( $conn, $procName, $procParams, $procTextBase ); } - public static function generateInsertValues(){ + public static function generateInsertValues() + { $vcharVal = "test string"; $nvcharVal = "wstring"; $intVal = 3; @@ -52,7 +62,8 @@ class PDOSqlsrvUtil{ return $values; } - public static function generateUpdateValues(){ + public static function generateUpdateValues() + { $vcharVal = "test string updated"; $nvcharVal = "wstring updated"; $intVal = 5; @@ -67,7 +78,8 @@ class PDOSqlsrvUtil{ return $updatedValues; } - public static function generateUpdateParams(){ + public static function generateUpdateParams() + { $fieldNames = array( "vstring", "nvstring", @@ -81,41 +93,47 @@ class PDOSqlsrvUtil{ "dtoffset"); $params = ""; - foreach( $fieldNames as $fieldName ){ + foreach( $fieldNames as $fieldName ) + { $params = $params.$fieldName."=?,"; } $params = rtrim($params,", "); return $params; } - public static function insertWithPrepare( $conn, $tableName, $values ){ + public static function insertWithPrepare( $conn, $tableName, $values ) + { $sql = "INSERT INTO $tableName VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; $stmt = self::prepare( $conn, $sql ); self::bindParams( $stmt, $values ); self::execute( $stmt ); } - public static function fetchWithPrepare( $conn, $tableName ){ + public static function fetchWithPrepare( $conn, $tableName ) + { $sql = "SELECT * FROM $tableName"; $stmt = self::prepare( $conn, $sql ); self::execute( $stmt ); while ( $row = self::fetch( $stmt )){} } - public static function deleteWithPrepare( $conn, $tableName ){ + public static function deleteWithPrepare( $conn, $tableName ) + { $sql = "DELETE TOP (1) FROM $tableName"; $stmt = self::prepare( $conn, $sql ); self::execute( $stmt ); } - public static function updateWithPrepare( $conn, $tableName, $updateValues, $params ){ + public static function updateWithPrepare( $conn, $tableName, $updateValues, $params ) + { $sql = "UPDATE $tableName SET ".$params; $stmt = self::prepare( $conn, $sql ); self::bindParams( $stmt, $updateValues ); self::execute( $stmt ); } - private function bindParams( $stmt, $values ){ + private function bindParams( $stmt, $values ) + { //This functionn assumes the fields are from createCRUDTable() self::bindParam( $stmt, 1, $values[0], PDO::PARAM_STR); self::bindParam( $stmt, 2, $values[1], PDO::PARAM_STR); @@ -129,7 +147,8 @@ class PDOSqlsrvUtil{ self::bindParam( $stmt, 10, $values[9], PDO::PARAM_STR); } - public static function createCRUDTable( $conn, $tableName ){ + public static function createCRUDTable( $conn, $tableName ) + { $fields = array( "vstring" => "VARCHAR(64)", "nvstring" => "NVARCHAR(64)", @@ -142,86 +161,106 @@ class PDOSqlsrvUtil{ "vbin" => "VARBINARY", "dtoffset" => "DATETIMEOFFSET"); $params = ""; - foreach( $fields as $fieldName => $type ){ + foreach( $fields as $fieldName => $type ) + { $params .= $fieldName." ".$type.","; } $params = rtrim($params,", "); self::createTable( $conn, $tableName, $params ); } - private function createDatabase( $conn, $dbName ){ + private function createDatabase( $conn, $dbName ) + { $sql = "CREATE DATABASE $dbName"; $conn->exec( $sql ); } - public static function dropDatabase( $conn, $dbName ){ + public static function dropDatabase( $conn, $dbName ) + { $sql = "USE MASTER;DROP DATABASE $dbName"; $conn->exec( $sql ); } - public static function createTable( $conn, $tableName, $params ){ + public static function createTable( $conn, $tableName, $params ) + { $sql = "CREATE TABLE $tableName ($params)"; $conn->exec( $sql ); } - public static function dropTable( $conn, $tableName ){ + public static function dropTable( $conn, $tableName ) + { $sql = "DROP TABLE $tableName"; $conn->exec( $sql ); } - private function useDatabase( $conn, $dbName ){ + private function useDatabase( $conn, $dbName ) + { $sql = "USE $dbName"; $conn->exec( $sql ); } - private function createStoredProc( $conn, $procName, $params, $text ){ + private function createStoredProc( $conn, $procName, $params, $text ) + { $sql = "CREATE PROCEDURE $procName $params AS $text"; $conn->exec( $sql ); } - private function dropStoredProc( $conn, $procName ){ + private function dropStoredProc( $conn, $procName ) + { $sql = "DROP PROCEDURE $procName"; $conn->exec( $sql ); } - private function query( $conn, $sql ){ - try{ + private function query( $conn, $sql ) + { + try + { return $conn->query( $sql ); } - catch( PDOException $e ){ + catch( PDOException $e ) + { var_dump( $e ); exit; } } - private function fetch( $stmt ){ + private function fetch( $stmt ) + { return $stmt->fetch(); } - private function prepare( $conn, $sql ){ - try{ + private function prepare( $conn, $sql ) + { + try + { $stmt = $conn->prepare( $sql ); - if( $stmt === false ){ + if( $stmt === false ) + { die( "Failed to prepare\n"); } return $stmt; } - catch( PDOException $e ){ + catch( PDOException $e ) + { var_dump( $e ); exit; } } - private function execute( $stmt ){ + private function execute( $stmt ) + { $ret = $stmt->execute(); - if( $ret === false ){ + if( $ret === false ) + { die( "Failed to execute\n" ); } } - private function bindParam( $stmt, $index, $value, $type ){ + private function bindParam( $stmt, $index, $value, $type ) + { $ret = $stmt->bindParam( $index, $value, $type ); - if ( $ret === false){ + if ( $ret === false) + { die( "Faild to bind\n"); } } diff --git a/test/Performance/lib/SqlsrvUtil.php b/test/Performance/lib/SqlsrvUtil.php index f2a73533..4c8091b5 100644 --- a/test/Performance/lib/SqlsrvUtil.php +++ b/test/Performance/lib/SqlsrvUtil.php @@ -2,35 +2,45 @@ namespace SqlsrvPerfTest; -class SqlsrvUtil{ +class SqlsrvUtil +{ + + public static $loopsPerCRUDIter = 100; - public static function connect(){ + public static function connect() + { require dirname(__FILE__).DIRECTORY_SEPARATOR.'connect.php'; $options = array( "Database"=>$database, "UID"=>$uid, "PWD"=>$pwd, "ConnectionPooling"=>$pooling, "MultipleActiveResultSets"=>$mars ); $conn = sqlsrv_connect( $server, $options ); - if ( $conn === false ){ + if ( $conn === false ) + { die( print_r( sqlsrv_errors(), true)); } return $conn; } - public static function disconnect( $conn ){ - if ( $conn === false || $conn === null ){ + public static function disconnect( $conn ) + { + if ( $conn === false || $conn === null ) + { die( print_r( "Invalid connection resource\n")); } $ret = sqlsrv_close( $conn ); - if ( $ret === false ){ + if ( $ret === false ) + { die( print_r( sqlsrv_errors(), true)); } } - public static function selectVersion( $conn ){ + public static function selectVersion( $conn ) + { $sql = "SELECT @@Version"; $stmt = self::query( $conn, $sql ); return self::fetchArray( $stmt ); } - public static function createDbTableProc( $conn, $databaseName, $tableName, $procName ){ + public static function createDbTableProc( $conn, $databaseName, $tableName, $procName ) + { $tableParams = "id INTEGER, name VARCHAR(32), value INTEGER, start_date DATE, time_added TIMESTAMP, set_time TIME(7)"; $procParams = "@id INTEGER, @name VARCHAR(32)"; $procTextBase = "SET NOCOUNT ON; SELECT id, name, value FROM $databaseName.$tableName WHERE id = @id AND name = @name"; @@ -40,7 +50,8 @@ class SqlsrvUtil{ self::createStoredProc( $conn, $procName, $procParams, $procTextBase ); } - public static function generateInsertValues(){ + public static function generateInsertValues() + { $vcharVal = "test string"; $nvcharVal = "wstring"; $intVal = 3; @@ -55,7 +66,8 @@ class SqlsrvUtil{ return $values; } - public static function generateUpdateValues(){ + public static function generateUpdateValues() + { $vcharVal = "test string updated"; $nvcharVal = "wstring updated"; $intVal = 5; @@ -70,7 +82,8 @@ class SqlsrvUtil{ return $updatedValues; } - public static function generateUpdateParams(){ + public static function generateUpdateParams() + { $fieldNames = array( "vstring", "nvstring", @@ -84,33 +97,38 @@ class SqlsrvUtil{ "dtoffset"); $params = ""; - foreach( $fieldNames as $fieldName ){ + foreach( $fieldNames as $fieldName ) + { $params = $params.$fieldName."=?,"; } $params = rtrim($params,", "); return $params; } - public static function insertWithPrepare( $conn, $tableName, $values ){ + public static function insertWithPrepare( $conn, $tableName, $values ) + { $sql = "INSERT INTO $tableName VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; $stmt = self::prepare( $conn, $sql, $values ); self::execute( $stmt ); } - public static function updateWithPrepare( $conn, $tableName, $updateValues, $params ){ + public static function updateWithPrepare( $conn, $tableName, $updateValues, $params ) + { $sql = "UPDATE $tableName SET ".$params; $stmt = self::prepare( $conn, $sql, $updateValues ); self::execute( $stmt ); } - public static function fetchWithPrepare( $conn, $tableName ){ + public static function fetchWithPrepare( $conn, $tableName ) + { $sql = "SELECT * FROM $tableName"; $stmt = self::prepare( $conn, $sql, array()); self::execute( $stmt ); while( $row = self::fetchArray( $stmt ) ) {} } - public static function createCRUDTable( $conn, $tableName ){ + public static function createCRUDTable( $conn, $tableName ) + { $fields = array( "vstring" => "VARCHAR(64)", "nvstring" => "NVARCHAR(64)", @@ -123,108 +141,131 @@ class SqlsrvUtil{ "vbin" => "VARBINARY", "dtoffset" => "DATETIMEOFFSET"); $params = ""; - foreach( $fields as $fieldName => $type ){ + foreach( $fields as $fieldName => $type ) + { $params .= $fieldName." ".$type.","; } $params = rtrim($params,", "); self::createTable( $conn, $tableName, $params ); } - public static function query( $conn, $sql ){ + public static function query( $conn, $sql ) + { $stmt = sqlsrv_query( $conn, $sql ); - if( $stmt === false ){ + if( $stmt === false ) + { die( print_r( sqlsrv_errors(), true)); } return $stmt; } - public static function fetch( $stmt ){ + public static function fetch( $stmt ) + { $ret = sqlsrv_fetch( $stmt ); - if( $ret === false ){ + if( $ret === false ) + { die( print_r( sqlsrv_errors(), true)); } return $ret; } - public static function fetchArray( $stmt ){ + public static function fetchArray( $stmt ) + { $row = sqlsrv_fetch_array( $stmt ); - if ( $row === false ){ + if ( $row === false ) + { die( print_r( sqlsrv_errors(), true)); } return $row; } - public static function getField( $stmt, $index ){ + public static function getField( $stmt, $index ) + { return sqlsrv_get_field( $stmt, $index ); } - private function createDatabase( $conn, $dbName ){ + private function createDatabase( $conn, $dbName ) + { $sql = "CREATE DATABASE $dbName"; self::query( $conn, $sql ); } - public static function dropDatabase( $conn, $dbName ){ + public static function dropDatabase( $conn, $dbName ) + { $sql = "USE MASTER;DROP DATABASE $dbName"; self::query( $conn, $sql ); } - public static function createTable( $conn, $tableName, $params ){ + public static function createTable( $conn, $tableName, $params ) + { $sql = "CREATE TABLE $tableName ($params)"; self::query( $conn, $sql ); } - public static function dropTable( $conn, $tableName ){ + public static function dropTable( $conn, $tableName ) + { $sql = "DROP TABLE $tableName"; self::query( $conn, $sql ); } - private function useDatabase( $conn, $dbName ){ + private function useDatabase( $conn, $dbName ) + { $sql = "USE $dbName"; self::query( $conn, $sql ); } - private function createStoredProc( $conn, $procName, $params, $text ){ + private function createStoredProc( $conn, $procName, $params, $text ) + { $sql = "CREATE PROCEDURE $procName $params AS $text"; self::query( $conn, $sql ); } - private function dropStoredProc( $conn, $procName ){ + private function dropStoredProc( $conn, $procName ) + { $sql = "DROP PROCEDURE $procName"; self::query( $conn, $sql ); } - private function insert( $conn, $tableName, $values ){ + private function insert( $conn, $tableName, $values ) + { $sql = "INSERT INTO $tableName values ($values)"; self::query( $conn, $sql ); } - private function update( $conn, $tableName, $params, $condition ){ + private function update( $conn, $tableName, $params, $condition ) + { $sql = "UPDATE $tableName SET $params WHERE $condition"; self::query( $sql ); } - public function delete( $conn, $tableName){ + public function delete( $conn, $tableName) + { $sql = "DELETE TOP (1) FROM $tableName"; self::query( $conn, $sql ); } - public function deleteWithPrepare( $conn, $tableName ){ + public function deleteWithPrepare( $conn, $tableName ) + { $sql = "DELETE TOP (1) FROM $tableName"; $stmt = self::prepare( $conn, $sql, array() ); self::execute( $stmt ); } - private function prepare( $conn, $sql, $params ){ + private function prepare( $conn, $sql, $params ) + { $stmt = sqlsrv_prepare( $conn, $sql, $params ); - if( $stmt === false ){ + if( $stmt === false ) + { die( print_r( sqlsrv_errors(), true)); } return $stmt; } - public function execute( $stmt ){ + public function execute( $stmt ) + { $ret = sqlsrv_execute( $stmt ); - if ( $ret === false ){ + if ( $ret === false ) + { die( print_r( sqlsrv_errors(), true)); } } diff --git a/test/Performance/report.sql b/test/Performance/report.sql index 5629abf2..8023d6ac 100644 --- a/test/Performance/report.sql +++ b/test/Performance/report.sql @@ -1,8 +1,9 @@ --The script can be run to read the results. You can filter out the results ran on a certain date by changing the date at the end. +DECLARE @convByteToMegabyte int = 1048576 select t1.ResultId, Test, Client, Server, Driver, Duration, Memory, Success, Team, StartTime from ( select pr.ResultId, pr.Success, pt.TestName as Test, cl.HostName as Client, srv.HostName as Server, -tm.TeamName as Team, st.value as Driver, bi.value as Duration, CAST(bi2.value AS decimal(10,2))/1048576 as Memory, dt.value as StartTime from +tm.TeamName as Team, st.value as Driver, bi.value as Duration, CAST(bi2.value AS decimal(10,2))/@convByteToMegabyte as Memory, dt.value as StartTime from KeyValueTableBigInt bi, KeyValueTableBigInt bi2, KeyValueTableString st, @@ -20,5 +21,4 @@ and cl.ClientId = pr.ClientId and pt.TestId = pr.TestId and tm.TeamId = pr.TeamId and srv.ServerId = pr.ServerId -) t1 where StartTime like '%2017-06-23%' - +) t1 where StartTime like '%2017-06-23%' \ No newline at end of file diff --git a/test/Performance/run-perf_tests.py b/test/Performance/run-perf_tests.py index 0a04e2ab..4a928efe 100644 --- a/test/Performance/run-perf_tests.py +++ b/test/Performance/run-perf_tests.py @@ -755,7 +755,7 @@ if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument( '-platform', '--PLATFORM', required=True, help='The name of the platform the tests run on' ) parser.add_argument( '-php-driver', '--PHP_DRIVER', default='both', help='Name of the PHP driver: sqlsrv, pdo_sqlsrv or both') - parser.add_argument( '-test-only', '--TEST_ONLY', default='all', help='File name for only one test or all' ) + parser.add_argument( '-testname', '--TESTNAME', default='all', help='File name for only one test or all' ) args = parser.parse_args() # Start time is recorded only in the beginning of this script execution. So it is not benchmark specific. @@ -769,7 +769,7 @@ if __name__ == '__main__': print("Running the tests with default settings...") - run_tests( args.PHP_DRIVER, args.TEST_ONLY ) + run_tests( args.PHP_DRIVER, args.TESTNAME ) parse_and_store_results_all( test_db, result_db, args.PLATFORM, start_time, 0, 0 ) """ The following lines are commented out, because it already takes a long time to run the tests with the default settings. @@ -777,14 +777,14 @@ if __name__ == '__main__': print("Running the tests with MARS ON...") enable_mars() - run_tests( args.PHP_DRIVER, args.TEST_ONLY ) + run_tests( args.PHP_DRIVER, args.TESTNAME ) parse_and_store_results_all( test_db, result_db, args.PLATFORM, start_time, 1, 0 ) disable_mars() print("Running the tests with Pooling ON...") enable_pooling() - run_tests( args.PHP_DRIVER, args.TEST_ONLY ) + run_tests( args.PHP_DRIVER, args.TESTNAME ) parse_and_store_results_all( test_db, result_db, args.PLATFORM, start_time, 0, 1 ) disable_pooling() """ From 13dc8134ce030a721ac5dbf7dcaa45c2ec1574b3 Mon Sep 17 00:00:00 2001 From: v-kaywon Date: Tue, 22 Aug 2017 16:46:42 -0700 Subject: [PATCH 10/11] change README.md documentation on modifying test iterations --- test/Performance/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Performance/README.md b/test/Performance/README.md index a1893e1e..7be4ca55 100644 --- a/test/Performance/README.md +++ b/test/Performance/README.md @@ -24,7 +24,7 @@ PHPBench is used to run the benchmarks. Visit http://phpbench.readthedocs.io/en/ ##### 1. Modify lib/connect.php with the test database credentials ##### 2. Modify lib/result_db.php with the result database credentials -##### 3. The number of iterations for each test can be modified in the test itself (e.g., in test/Performance/benchmark/sqlsrv). Each test has a @Iteration(n) annotation. If you change the number in this annotation, you will change the number of iterations run for this test. By default, most tests are set to 1000 iterations. +##### 3. The number of iterations for each test can be modified in the test itself (e.g., in test/Performance/benchmark/sqlsrv/SqlsrvSelectVersionBench.php). Each bench class in a test, or the parent class that it extends from, has a @Iteration(n) annotation. If you change the number in this annotation, you will change the number of iterations run for this test. By default, most tests are set to 1000 iterations. ##### 4. Execute run-perf_tests.py. ### Windows From a1fb3ca8360063508e7b1dae042dba8ba95362dc Mon Sep 17 00:00:00 2001 From: v-kaywon Date: Wed, 23 Aug 2017 09:39:49 -0700 Subject: [PATCH 11/11] change commend regarding large and regular folder structure in run-perf_tests.py --- test/Performance/run-perf_tests.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Performance/run-perf_tests.py b/test/Performance/run-perf_tests.py index 4a928efe..077afa26 100644 --- a/test/Performance/run-perf_tests.py +++ b/test/Performance/run-perf_tests.py @@ -25,7 +25,7 @@ from time import strftime import hashlib """ - Paths to current benchmarks. These constants should be modified if there are any changes in folder structure of the project. "regular" folder contains the benchmarks that can be run for any iterations. "large" folder contains the benchmarks ( currently the benchmark that fetches large amount of data ) that take long time to run and meant to have less number of iterations than the regular ones. + Paths to current benchmarks. These constants should be modified if there are any changes in folder structure of the project. """ sqlsrv_path = "benchmark" + os.sep + "sqlsrv"