From: Sanja Byelkin Date: May 14 2008 7:36am Subject: test of flush List-Archive: http://lists.mysql.com/maria/37 Message-Id: <20080514073603.GA2543@desktop.lan> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="lrZ03NoBR/3+SXJZ" --lrZ03NoBR/3+SXJZ Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Hi! I made test program to find which is better to write to file from one thread or meny threads as it was discussed on IRC. Now I think that the idea was not really correct: 1. If we sync the file then bottle neck is disk IO and there is no difference in result for 1, 2 and 4 threads (I have 4 core comp so did not test more) 2. if sync switched off then results vary from run to run about two times (I remove the result file before rerun so I think it did not infuence on result). So I think something made wrong, if somebody has knowladge in IO please say about errors in the test. The test is attached, and also attached diff to make buildimng it simple if put the test file in storage/maria/unittest/ -- __ ___ ___ ____ __ / |/ /_ __/ __/ __ \/ / Mr. Oleksandr Byelkin / /|_/ / // /\ \/ /_/ / /__ MySQL AB, Full-Time Developer /_/ /_/\_, /___/\___\_\___/ Lugansk, Ukraine <___/ www.mysql.com --lrZ03NoBR/3+SXJZ Content-Type: text/x-csrc; charset=utf-8 Content-Disposition: attachment; filename="write_test.c" /* test multithread write/flush */ #include #include #include static const uint number_of_threads= TEST_THREAD; static const uint sync_period= 8; #define COUNTER_LIMIT sync_period*64; static uint counter_limit; static uint counter= 0; static pthread_mutex_t counter_lock; static pthread_cond_t counter_cond; static uint in_progress= 0; static pthread_mutex_t progress_lock; static pthread_cond_t progress_cond; static char buffer[1048576]; static File file; void main_writer() { uint pos; for(;;) { pthread_mutex_lock(&counter_lock); if (counter % sync_period == 0) { pthread_mutex_lock(&progress_lock); while (in_progress > 0) { pthread_cond_wait(&progress_cond, &progress_lock); } pthread_mutex_unlock(&progress_lock); /*if (my_sync(file, MYF(MY_WME))) exit(1);*/ if (counter >= counter_limit) { my_close(file, MYF(MY_WME)); exit(0); } pthread_cond_broadcast(&counter_cond); } pos= counter++; pthread_mutex_unlock(&counter_lock); if (my_pwrite(file, buffer, sizeof(buffer), sizeof(buffer) * pos, MYF(MY_WME | MY_NABP))) exit(1); } } void helper_writer() { uint pos; for(;;) { pthread_mutex_lock(&counter_lock); while (counter % sync_period == 0) { pthread_cond_wait(&counter_cond, &counter_lock); } pos= counter++; pthread_mutex_lock(&progress_lock); in_progress++; pthread_mutex_unlock(&progress_lock); pthread_mutex_unlock(&counter_lock); if (my_pwrite(file, buffer, sizeof(buffer), sizeof(buffer) * pos, MYF(MY_WME | MY_NABP))) exit(1); pthread_mutex_lock(&progress_lock); in_progress--; if (!in_progress) pthread_cond_broadcast(&progress_cond); pthread_mutex_unlock(&progress_lock); } } static void *test_thread_writer(void *arg) { int param=*((int*) arg); my_thread_init(); if (number_of_threads == (uint)param) main_writer(); else helper_writer(); free((uchar*) arg); my_thread_end(); return 0; } int main(int argc __attribute__((unused)), char **argv __attribute__((unused))) { uint i; int *param; pthread_t tid; pthread_attr_t thr_attr; counter_limit= COUNTER_LIMIT; MY_INIT(argv[0]); pthread_mutex_init(&counter_lock, MY_MUTEX_INIT_FAST); pthread_mutex_init(&progress_lock, MY_MUTEX_INIT_FAST); pthread_cond_init(&counter_cond, NULL); pthread_cond_init(&progress_cond, NULL); if ((file= my_open("FILE", O_CREAT | O_TRUNC | O_RDWR, MYF(0))) == -1) exit(1); memset(buffer, '1', sizeof(buffer)); pthread_attr_init(&thr_attr); pthread_attr_setdetachstate(&thr_attr, PTHREAD_CREATE_DETACHED); for(i= 1; i <= number_of_threads; i++) { param=(int*) malloc(sizeof(int)); *param= (int) i; if (pthread_create(&tid, &thr_attr, test_thread_writer, (void*) param)) exit(1); } for (;;) { sleep(10); } my_end(0); } --lrZ03NoBR/3+SXJZ Content-Type: text/plain; charset=utf-8 Content-Disposition: attachment; filename="test.diff" ===== storage/maria/unittest/Makefile.am 1.29 vs edited ===== --- 1.29/storage/maria/unittest/Makefile.am 2008-05-07 07:58:10 +03:00 +++ edited/storage/maria/unittest/Makefile.am 2008-05-14 09:25:09 +03:00 @@ -49,7 +49,8 @@ ma_test_loghandler_max_lsn-t \ ma_test_loghandler_purge-t \ ma_test_loghandler_readonly-t\ - ma_test_loghandler_nologs-t + ma_test_loghandler_nologs-t\ + write_test1 write_test2 write_test4 ma_test_loghandler_t_SOURCES = ma_test_loghandler-t.c ma_maria_log_cleanup.c ma_loghandler_examples.c ma_test_loghandler_multigroup_t_SOURCES = ma_test_loghandler_multigroup-t.c ma_maria_log_cleanup.c ma_loghandler_examples.c sequence_storage.c sequence_storage.h @@ -98,6 +99,13 @@ ma_pagecache_rwconsist_1k_t_SOURCES = ma_pagecache_rwconsist.c ma_pagecache_rwconsist_1k_t_CPPFLAGS = -DTEST_PAGE_SIZE=1024 + +write_test1_SOURCES = write_test.c +write_test1_CPPFLAGS = -DTEST_THREAD=1 +write_test2_SOURCES = write_test.c +write_test2_CPPFLAGS = -DTEST_THREAD=2 +write_test4_SOURCES = write_test.c +write_test4_CPPFLAGS = -DTEST_THREAD=4 # the generic lock manager may not be used in the end and lockman1-t crashes, # so we don't build lockman-t and lockman1-t --lrZ03NoBR/3+SXJZ--