Changeset: 758d42fb4fa6 for MonetDB URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=758d42fb4fa6 Added Files: monetdb5/extras/pyapi/Benchmarks/db_test.sh Modified Files: monetdb5/extras/pyapi/Benchmarks/monetdb_testing.py monetdb5/extras/pyapi/Benchmarks/pyapi_test.sh monetdb5/extras/pyapi/pyapi.c Branch: pyapi Log Message:
Modified some benchmarks so they run faster and don't run out of memory, added code for building Postgres. diffs (truncated from 341 to 300 lines): diff --git a/monetdb5/extras/pyapi/Benchmarks/db_test.sh b/monetdb5/extras/pyapi/Benchmarks/db_test.sh new file mode 100644 --- /dev/null +++ b/monetdb5/extras/pyapi/Benchmarks/db_test.sh @@ -0,0 +1,26 @@ + + +export PYAPI_BASE_DIR=/export/scratch1/raasveld + +export PYAPI_TEST_DIR=$PYAPI_BASE_DIR/monetdb_pyapi_test +export PYAPI_MONETDB_DIR=$PYAPI_TEST_DIR/MonetDB-pyapi +export PYAPI_SRC_DIR=$PYAPI_MONETDB_DIR/monetdb5/extras/pyapi +export PYAPI_BUILD_DIR=$PYAPI_TEST_DIR/build +export PYAPI_OUTPUT_DIR=$PYAPI_TEST_DIR/output + +export POSTGRES_BASEDIR=$PYAPI_TEST_DIR/postgres +export POSTGRES_TEST_DIR=$POSTGRES_BASEDIR/postgres_test +export POSTGRES_BUILD_DIR=$POSTGRES_BASEDIR/build +export PGDATA=$POSTGRES_BASEDIR/postgres_data + +export POSTGRES_VERSION=9.4.4 +export POSTGRES_BASE=postgresql-$POSTGRES_VERSION +export POSTGRES_TAR_FILE=$POSTGRES_BASE.tar.gz +export POSTGRES_TAR_URL=https://ftp.postgresql.org/pub/source/v$POSTGRES_VERSION/$POSTGRES_TAR_FILE + + +function postgres_build() { + cd $PYAPI_TEST_DIR + wget $POSTGRES_TAR_URL && tar xvzf $POSTGRES_TAR_FILE && cd $POSTGRES_BASE && ./configure --prefix=$POSTGRES_BUILD_DIR --with-python && make && make install && $POSTGRES_BUILD_DIR/bin/initdb && $POSTGRES_BUILD_DIR/bin/createdb python_test +} + diff --git a/monetdb5/extras/pyapi/Benchmarks/monetdb_testing.py b/monetdb5/extras/pyapi/Benchmarks/monetdb_testing.py --- a/monetdb5/extras/pyapi/Benchmarks/monetdb_testing.py +++ b/monetdb5/extras/pyapi/Benchmarks/monetdb_testing.py @@ -62,6 +62,7 @@ def export_function(function, argtypes, raise Exception("Zero byte!"); return(export) +import math import multiprocessing import numpy import platform @@ -108,6 +109,7 @@ test_count = int(arguments[3]) port = int(arguments[4]) parameters_start = 5 max_retries = 15 +max_size = 1000 import monetdb.sql # Try to connect to the database @@ -141,13 +143,8 @@ if str(arguments[1]).lower() == "input" max_int = math.pow(2,31) - 1 min_int = -max_int integer_count = int(byte_size / integer_size_byte) - integers = numpy.zeros(integer_count, dtype=numpy.int32) - mask = numpy.zeros(integer_count, dtype=numpy.bool) - for i in range(0, integer_count): - integers[i] = random.randint(min_int, max_int) - if integers[i] < 0: - mask[i] = True - return numpy.ma.masked_array(integers, mask) + integers = numpy.random.random_integers(min_int, max_int, integer_count).astype(numpy.int32) + return numpy.ma.masked_array(integers, numpy.less(integers, 0)) else: def generate_integers(mb): import random @@ -157,10 +154,7 @@ if str(arguments[1]).lower() == "input" max_int = math.pow(2,31) - 1 min_int = -max_int integer_count = int(byte_size / integer_size_byte) - integers = numpy.zeros(integer_count, dtype=numpy.int32) - for i in range(0, integer_count): - integers[i] = random.randint(min_int, max_int) - return integers + return numpy.random.random_integers(min_int, max_int, integer_count).astype(numpy.int32) cursor.execute(export_function(generate_integers, ['float'], ['i integer'], table=True, test=False)) @@ -179,9 +173,12 @@ if str(arguments[1]).lower() == "input" mb.append(float(arguments[i])) for size in mb: - cursor.execute('create table integers as SELECT * FROM generate_integers(' + str(size) + ') with data;') - #result_file = open(temp_file, 'r') - #result_file.readline() + cursor.execute('CREATE TABLE integers (i integer);') + temp_size = size + for increment in range(0, int(math.ceil(float(size) / float(max_size)))): + current_size = temp_size if temp_size < max_size else max_size + cursor.execute('INSERT INTO integers SELECT * FROM generate_integers(' + str(current_size) + ');') + temp_size -= max_size if (str(arguments[1]).lower() == "input"): results = [] @@ -430,10 +427,7 @@ elif "factorial" in str(arguments[1]).lo max_int = 2000 min_int = 1000 integer_count = int(byte_size / integer_size_byte) - integers = numpy.zeros(integer_count, dtype=numpy.int32) - for i in range(0, integer_count): - integers[i] = random.randint(min_int, max_int) - return integers + return numpy.random.random_integers(min_int, max_int, integer_count).astype(numpy.int32) cursor.execute(export_function(generate_integers, ['float'], ['i integer'], table=True, test=False)) def factorial(i): @@ -503,10 +497,7 @@ elif str(arguments[1]).lower() == "pquan max_int = math.pow(2,31) - 1 min_int = -max_int integer_count = int(byte_size / integer_size_byte) - integers = numpy.zeros(integer_count, dtype=numpy.int32) - for i in range(0, integer_count): - integers[i] = random.randint(min_int, max_int) - return integers + return numpy.random.random_integers(min_int, max_int, integer_count).astype(numpy.int32) cursor.execute(export_function(generate_integers, ['float'], ['i integer'], table=True, test=False)) diff --git a/monetdb5/extras/pyapi/Benchmarks/pyapi_test.sh b/monetdb5/extras/pyapi/Benchmarks/pyapi_test.sh --- a/monetdb5/extras/pyapi/Benchmarks/pyapi_test.sh +++ b/monetdb5/extras/pyapi/Benchmarks/pyapi_test.sh @@ -1,8 +1,8 @@ # The base directory of testing, a new folder is created in this base directory [$PYAPI_TEST_DIR], and everything is done in that new folder -export PYAPI_BASE_DIR=$HOME -# The terminal to start mserver with, examples are 'gnome-terminal', 'xterm', 'konsole' +export PYAPI_BASE_DIR=/export/scratch1/raasveld +# The terminal to start mserver with, examples are gnome-terminal, xterm, konsole export TERMINAL=x-terminal-emulator # Port used by the MSERVER export MSERVER_PORT=49979 @@ -45,8 +45,7 @@ export QUANTILE_TESTING_SIZES="0.1 1 10 # Amount of tests to run for each size export QUANTILE_TESTING_NTESTS=10 - -# You probably don't need to change these +# You probably dont need to change these export PYAPI_TEST_DIR=$PYAPI_BASE_DIR/monetdb_pyapi_test export PYAPI_MONETDB_DIR=$PYAPI_TEST_DIR/MonetDB-pyapi export PYAPI_SRC_DIR=$PYAPI_MONETDB_DIR/monetdb5/extras/pyapi @@ -86,7 +85,7 @@ if [ $? -ne 0 ]; then export SETSID=1 fi -function pyapi_build { +function pyapi_build() { echo "Making directory $PYAPI_TEST_DIR." mkdir $PYAPI_TEST_DIR && cd $PYAPI_TEST_DIR if [ $? -ne 0 ]; then @@ -124,7 +123,7 @@ function pyapi_build { fi fi echo "Finished testing for libraries. Downloading and installing MonetDB." - wget $PYAPI_TAR_URL && tar xvzf pyapi.tar.gz && cd $PYAPI_MONETDB_DIR && printf '#ifndef _PYAPI_TESTING_\n#define _PYAPI_TESTING_\n#endif\n' | cat - $PYAPI_SRC_DIR/pyapi.h > $PYAPI_SRC_DIR/temp && mv $PYAPI_SRC_DIR/temp $PYAPI_SRC_DIR/pyapi.h && ./bootstrap && ./configure prefix=$PYAPI_BUILD_DIR --enable-debug=no --enable-assert=no --enable-optimize=yes && make -j install + wget $PYAPI_TAR_URL && tar xvzf pyapi.tar.gz && cd $PYAPI_MONETDB_DIR && printf '#ifndef _PYAPI_TESTING_\n#define _PYAPI_TESTING_\n#define _PYAPI_VERBOSE_\n#endif\n' | cat - $PYAPI_SRC_DIR/pyapi.h > $PYAPI_SRC_DIR/temp && mv $PYAPI_SRC_DIR/temp $PYAPI_SRC_DIR/pyapi.h && ./bootstrap && ./configure --prefix=$PYAPI_BUILD_DIR --enable-debug=no --enable-assert=no --enable-optimize=yes && make -j install if [ $? -ne 0 ]; then echo "Failed to download and install MonetDB. Exiting..." return 1 @@ -156,7 +155,7 @@ function pyapi_run_single_test() { return 1 } -function pyapi_test_input { +function pyapi_test_input() { echo "Beginning Input Testing (Copy vs Zero Copy)" pyapi_run_single_test "Input Testing (Zero Copy)" "" "INPUT" input_zerocopy "$INPUT_TESTING_NTESTS" "$INPUT_TESTING_SIZES" if [ $? -ne 0 ]; then @@ -173,7 +172,7 @@ function pyapi_test_input { } -function pyapi_test_input_null { +function pyapi_test_input_null() { echo "Beginning Input Testing [NULL] (Copy vs Zero Copy)" pyapi_run_single_test "Input Testing (Zero Copy)" "" "INPUT-NULL" input_zerocopy_null "$INPUT_TESTING_NTESTS" "$INPUT_TESTING_SIZES" if [ $? -ne 0 ]; then @@ -185,7 +184,7 @@ function pyapi_test_input_null { fi } -function pyapi_test_output { +function pyapi_test_output() { pyapi_run_single_test "Output Testing (Zero Copy)" "" "OUTPUT" output_zerocopy "$OUTPUT_TESTING_NTESTS" "$OUTPUT_TESTING_SIZES" if [ $? -ne 0 ]; then return 1 @@ -197,7 +196,7 @@ function pyapi_test_output { fi } -function pyapi_test_string_samelength { +function pyapi_test_string_samelength() { pyapi_run_single_test "String Testing (LazyArray, Same Length)" "--set enable_lazyarray=true" "STRING_SAMELENGTH" string_samelength_lazyarray "$STRINGSAMELENGTH_TESTING_NTESTS" "$STRINGSAMELENGTH_TESTING_SIZES" if [ $? -ne 0 ]; then return 1 @@ -214,7 +213,7 @@ function pyapi_test_string_samelength { fi } -function pyapi_test_string_extreme { +function pyapi_test_string_extreme() { pyapi_run_single_test "String Testing (NPY_OBJECT, Extreme Length)" "" "STRING_EXTREMELENGTH" string_extremelength_npyobject "$STRINGEXTREMELENGTH_TESTING_NTESTS" "$STRINGEXTREMELENGTH_TESTING_SIZES" if [ $? -ne 0 ]; then return 1 @@ -226,7 +225,7 @@ function pyapi_test_string_extreme { fi } -function pyapi_test_string_unicode_ascii { +function pyapi_test_string_unicode_ascii() { pyapi_run_single_test "String Testing (Check Unicode, ASCII)" "" "STRING_SAMELENGTH" string_unicode_ascii_check "$STRINGUNICODE_TESTING_NTESTS" "$STRINGUNICODE_TESTING_SIZES" if [ $? -ne 0 ]; then return 1 @@ -248,7 +247,7 @@ function pyapi_test_string_unicode_ascii fi } -function pyapi_test_bytearray_vs_string { +function pyapi_test_bytearray_vs_string() { pyapi_run_single_test "String Testing (ByteArray Object)" "" "STRING_SAMELENGTH" string_bytearrayobject "$STRINGSAMELENGTH_TESTING_NTESTS" "$STRINGSAMELENGTH_TESTING_SIZES" if [ $? -ne 0 ]; then return 1 @@ -260,7 +259,7 @@ function pyapi_test_bytearray_vs_string fi } -function pyapi_test_threads { +function pyapi_test_threads() { rm multithreading.tsv for thread in $MULTITHREADING_NR_THREADS do @@ -271,7 +270,7 @@ function pyapi_test_threads { done } -function pyapi_test_quantile { +function pyapi_test_quantile() { echo "Beginning Quantile Testing (Python vs R vs MonetDB)" pyapi_run_single_test "Quantile Testing (Python)" "" "PQUANTILE" quantile_python "$QUANTILE_TESTING_NTESTS" "$QUANTILE_TESTING_SIZES" if [ $? -ne 0 ]; then @@ -287,7 +286,7 @@ function pyapi_test_quantile { fi } -function pyapi_run_tests { +function pyapi_run_tests() { if [ -d $PYAPI_OUTPUT_DIR ]; then read -p "Directory $PYAPI_OUTPUT_DIR already exists, should we delete it? (y/n): " -n 1 -r echo "" @@ -314,7 +313,7 @@ function pyapi_run_tests { pyapi_test_threads } -function pyapi_graph { +function pyapi_graph() { python $PYAPI_GRAPHFILE "SAVE" "Input (Both)" "-xlog" "Zero Copy:input_zerocopy.tsv" "Copy:input_copy.tsv" "Zero Copy (Null):input_zerocopy_null.tsv" "Copy (Null):input_copy_null.tsv" python $PYAPI_GRAPHFILE "SAVE" "Input" "-xlog" "Zero Copy:input_zerocopy.tsv" "Copy:input_copy.tsv" python $PYAPI_GRAPHFILE "SAVE" "Input-Null" "-xlog" "Zero Copy:input_zerocopy_null.tsv" "Copy:input_copy_null.tsv" @@ -342,7 +341,7 @@ function pyapi_graph { } -function pyapi_cleanup { +function pyapi_cleanup() { read -p "Finished testing, would you like me to remove the test directory $PYAPI_TEST_DIR and everything in it? (y/n): " -n 1 -r echo "" if [[ $REPLY =~ ^[Yy]$ ]]; then @@ -351,7 +350,7 @@ function pyapi_cleanup { return 0 } -function pyapi_test { +function pyapi_test() { if [ -d $PYAPI_TEST_DIR ]; then read -p "Directory $PYAPI_TEST_DIR already exists, skip the building and continue to testing? (y/n): " -n 1 -r echo "" diff --git a/monetdb5/extras/pyapi/pyapi.c b/monetdb5/extras/pyapi/pyapi.c --- a/monetdb5/extras/pyapi/pyapi.c +++ b/monetdb5/extras/pyapi/pyapi.c @@ -1678,40 +1678,50 @@ PyObject *PyArrayObject_FromScalar(PyInp PyObject *vararray = NULL; char *msg = NULL; assert(inp->scalar); //input has to be a scalar - VERBOSE_MESSAGE("- Loading a scalar of type %s (%i)\n", BatType_Format(inp->bat_type), inp->bat_type); + VERBOSE_MESSAGE("- Loading a scalar of type %s (%i)", BatType_Format(inp->bat_type), inp->bat_type); switch(inp->bat_type) { case TYPE_bit: vararray = PyInt_FromLong((long)(*(bit*)inp->dataptr)); + VERBOSE_MESSAGE(" [Value: %ld]\n", (long)(*(bit*)inp->dataptr)); break; case TYPE_bte: vararray = PyInt_FromLong((long)(*(bte*)inp->dataptr)); + VERBOSE_MESSAGE(" [Value: %ld]\n", (long)(*(bte*)inp->dataptr)); break; case TYPE_sht: vararray = PyInt_FromLong((long)(*(sht*)inp->dataptr)); + VERBOSE_MESSAGE(" [Value: %ld]\n", (long)(*(sht*)inp->dataptr)); _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list