Kouhei Sutou
null+****@clear*****
Sun Aug 10 15:39:38 JST 2014
Kouhei Sutou 2014-08-10 15:39:38 +0900 (Sun, 10 Aug 2014) New Revision: c4379140c02699e3c74b94cd9e7b88d372202aa5 https://github.com/groonga/groonga/commit/c4379140c02699e3c74b94cd9e7b88d372202aa5 Message: benchmark: add for query optimizer Added files: benchmark/bench-query-optimizer-ddl.grn benchmark/bench-query-optimizer.c Modified files: .gitignore benchmark/Makefile.am Modified: .gitignore (+1 -0) =================================================================== --- .gitignore 2014-08-10 12:50:46 +0900 (b4f9df9) +++ .gitignore 2014-08-10 15:39:38 +0900 (18f84e6) @@ -93,6 +93,7 @@ cmake_install.cmake /benchmark/bench-geo-distance /benchmark/bench-table-factory /benchmark/bench-ctx-create +/benchmark/bench-query-optimizer /packages/*/*.log /packages/apt/debian/groonga-keyring.postrm /packages/apt/repositories/debian/pool/*/*/*/*/*.diff.gz Modified: benchmark/Makefile.am (+23 -2) =================================================================== --- benchmark/Makefile.am 2014-08-10 12:50:46 +0900 (b753566) +++ benchmark/Makefile.am 2014-08-10 15:39:38 +0900 (146bd49) @@ -9,9 +9,13 @@ noinst_PROGRAMS = \ bench-table-factory \ bench-geo-distance \ bench-geo-select \ - bench-ctx-create + bench-ctx-create \ + bench-query-optimizer endif +EXTRA_DIST = \ + bench-query-optimizer-ddl.grn + AM_CPPFLAGS = \ -I$(srcdir) \ -I$(srcdir)/lib \ @@ -39,11 +43,15 @@ nodist_EXTRA_bench_geo_select_SOURCES = $(NONEXISTENT_CXX_SOURCE) bench_ctx_create_SOURCES = bench-ctx-create.c nodist_EXTRA_bench_ctx_create_SOURCES = $(NONEXISTENT_CXX_SOURCE) +bench_query_optimizer_SOURCES = bench-query-optimizer.c +nodist_EXTRA_bench_query_optimizer_SOURCES = $(NONEXISTENT_CXX_SOURCE) + benchmarks = \ run-bench-table-factory \ run-bench-geo-distance \ run-bench-geo-select \ - run-bench-ctx-create + run-bench-ctx-create \ + run-bench-query-optimizer run-bench-table-factory: bench-table-factory @echo $@: @@ -65,4 +73,17 @@ run-bench-ctx-create: bench-ctx-create @echo $@: ./bench-ctx-create +run-bench-query-optimizer: bench-query-optimizer + @echo $@: + @rm -rf tmp/query-optimizer + @mkdir -p tmp/query-optimizer + @env \ + GRN_RUBY_SCRIPTS_DIR=$(top_srcdir)/lib/mrb/scripts \ + ../src/groonga \ + --file $(srcdir)/bench-query-optimizer-ddl.grn \ + -n tmp/query-optimizer/db > /dev/null + env \ + GRN_RUBY_SCRIPTS_DIR=$(top_srcdir)/lib/mrb/scripts \ + ./bench-query-optimizer + benchmark: $(benchmarks) Added: benchmark/bench-query-optimizer-ddl.grn (+16 -0) 100644 =================================================================== --- /dev/null +++ benchmark/bench-query-optimizer-ddl.grn 2014-08-10 15:39:38 +0900 (68317ae) @@ -0,0 +1,16 @@ +table_create Entries TABLE_PAT_KEY ShortText +column_create Entries name COLUMN_SCALAR ShortText +column_create Entries description COLUMN_SCALAR Text +column_create Entries last_modified COLUMN_SCALAR Time + +table_create Bigram TABLE_PAT_KEY ShortText \ + --default_tokenizer TokenBigram \ + --normalizer NormalizerAuto +column_create Bigram entries_name COLUMN_INDEX|WITH_POSITION \ + Entries name +column_create Bigram entries_description COLUMN_INDEX|WITH_POSITION \ + Entries description + +table_create Times TABLE_PAT_KEY Time +column_create Times entries_last_modified COLUMN_INDEX \ + Entries last_modified Added: benchmark/bench-query-optimizer.c (+184 -0) 100644 =================================================================== --- /dev/null +++ benchmark/bench-query-optimizer.c 2014-08-10 15:39:38 +0900 (ee8e52b) @@ -0,0 +1,184 @@ +/* -*- c-basic-offset: 2; coding: utf-8 -*- */ +/* + Copyright (C) 2014 Kouhei Sutou <kou �� clear-code.com> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License version 2.1 as published by the Free Software Foundation. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#include <stdlib.h> +#include <string.h> + +#include <glib.h> + +#include <groonga.h> + +#include "lib/benchmark.h" + +typedef struct _BenchmarkData { + grn_ctx context; + grn_obj *database; + grn_bool use_mruby; + GString *command; +} BenchmarkData; + +static void +bench(gpointer user_data) +{ + BenchmarkData *data = user_data; + grn_ctx *context = &(data->context); + char *response; + unsigned int response_length; + int flags; + + grn_ctx_send(context, data->command->str, data->command->len, 0); + grn_ctx_recv(context, &response, &response_length, &flags); +} + +static void +bench_setup(gpointer user_data) +{ + BenchmarkData *data = user_data; + + if (data->use_mruby) { + g_setenv("GRN_MRUBY_ENABLED", "yes", TRUE); + } else { + g_setenv("GRN_MRUBY_ENABLED", "no", TRUE); + } + grn_ctx_init(&(data->context), 0); + grn_ctx_use(&(data->context), data->database); +} + +static void +bench_teardown(gpointer user_data) +{ + BenchmarkData *data = user_data; + + grn_ctx_fin(&(data->context)); +} + +static gchar * +get_tmp_dir(void) +{ + gchar *current_dir; + gchar *tmp_dir; + + current_dir = g_get_current_dir(); + tmp_dir = g_build_filename(current_dir, "tmp", NULL); + g_free(current_dir); + + return tmp_dir; +} + +static grn_obj * +setup_database(grn_ctx *context) +{ + gchar *tmp_dir; + gchar *database_path; + grn_obj *database; + const gchar *warmup_command = "dump"; + gchar *response; + unsigned int response_length; + int flags; + + tmp_dir = get_tmp_dir(); + database_path = g_build_filename(tmp_dir, "query-optimizer", "db", NULL); + database = grn_db_open(context, database_path); + grn_ctx_send(context, warmup_command, strlen(warmup_command), 0); + grn_ctx_recv(context, &response, &response_length, &flags); + + g_free(database_path); + + return database; +} + +static void +teardown_database(grn_ctx *context, grn_obj *database) +{ + grn_obj_close(context, database); +} + +int +main(int argc, gchar **argv) +{ + grn_ctx context; + grn_obj *database; + BenchReporter *reporter; + gint n = 100; + + grn_init(); + bench_init(&argc, &argv); + + grn_ctx_init(&context, 0); + + database = setup_database(&context); + + reporter = bench_reporter_new(); + + g_print("Process %d times in each pattern\n", n); + { + BenchmarkData data_one_condition_with_mruby; + BenchmarkData data_one_condition_without_mruby; + BenchmarkData data_multiple_conditions_with_mruby; + BenchmarkData data_multiple_conditions_without_mruby; + +#define REGISTER(label, data, use_mruby_, command_) \ + data.database = database; \ + data.use_mruby = use_mruby_; \ + data.command = g_string_new(command_); \ + bench_reporter_register(reporter, label, \ + n, \ + bench_setup, \ + bench, \ + bench_teardown, \ + &data) + + REGISTER("1 condition: with mruby", data_one_condition_with_mruby, + GRN_TRUE, + "select Entries --cache no --query 'name:@Groonga'"); + REGISTER("1 condition: without mruby", data_one_condition_without_mruby, + GRN_FALSE, + "select Entries --cache no --query 'name:@Groonga'"); + REGISTER("4 conditions: with mruby", + data_multiple_conditions_with_mruby, + GRN_TRUE, + "select Entries --cache no --filter '" + "name @ \"Groonga\" && " + "description @ \"search\" && " + "last_modified >= \"2014-2-9 00:00:00\" && " + "last_modified <= \"2014-11-29 00:00:00\"" + "'"); + REGISTER("4 conditions: without mruby", + data_multiple_conditions_without_mruby, + GRN_FALSE, + "select Entries --cache no --filter '" + "name @ \"Groonga\" && " + "description @ \"search\" && " + "last_modified >= \"2014-2-9 00:00:00\" && " + "last_modified <= \"2014-11-29 00:00:00\"" + "'"); + +#undef REGISTER + + bench_reporter_run(reporter); + } + g_object_unref(reporter); + + teardown_database(&context, database); + + grn_ctx_fin(&context); + + grn_fin(); + + return 0; +} -------------- next part -------------- HTML����������������������������...Download