~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/archive/concurrency_test.c

Merged vcol stuff.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 
 *
4
 
 *  Copyright (C) 2009 Sun Microsystems, Inc.
5
 
 *
6
 
 *  This program is free software; you can redistribute it and/or modify
7
 
 *  it under the terms of the GNU General Public License as published by
8
 
 *  the Free Software Foundation; version 2 of the License.
9
 
 *
10
 
 *  This program is distributed in the hope that it will be useful,
11
 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 
 *  GNU General Public License for more details.
14
 
 *
15
 
 *  You should have received a copy of the GNU General Public License
16
 
 *  along with this program; if not, write to the Free Software
17
 
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
 
 */
19
 
 
20
1
/*
21
2
  Just a test application for threads.
22
3
  */
23
 
 
24
 
#include "config.h"
25
 
 
26
4
#include "azio.h"
 
5
#include <libdrizzle/libdrizzle.h>
 
6
#include <mysys/my_getopt.h>
27
7
#include <stdio.h>
28
8
#include <stdlib.h>
29
9
#include <sys/types.h>
37
17
#ifndef __WIN__
38
18
#include <sys/wait.h>
39
19
#endif
40
 
#include <memory>
41
20
 
42
21
#ifdef __WIN__
43
22
#define srandom  srand
45
24
#define snprintf _snprintf
46
25
#endif
47
26
 
48
 
#include <boost/scoped_ptr.hpp>
49
 
 
50
27
#include "azio.h"
51
28
 
52
29
#define DEFAULT_INITIAL_LOAD 10000
53
30
#define DEFAULT_EXECUTE_SECONDS 120
 
31
#define DEFAULT_CONCURRENCY 8
54
32
#define TEST_FILENAME "concurrency_test.az"
55
33
 
56
34
#define HUGE_STRING_LENGTH 8192
69
47
pthread_mutex_t row_lock;
70
48
 
71
49
/* Prototypes */
72
 
extern "C" {
73
 
  void *run_concurrent_task(void *p);
74
 
  void *timer_thread(void *p);
75
 
}
 
50
void *run_task(void *p);
 
51
void *timer_thread(void *p);
76
52
void scheduler(az_method use_aio);
77
53
void create_data_file(azio_stream *write_handler, uint64_t rows);
78
54
unsigned int write_row(azio_stream *s);
103
79
int main(int argc, char *argv[])
104
80
{
105
81
 
106
 
  unsigned int method;
107
 
  drizzled::internal::my_init();
 
82
  az_method method;
 
83
  my_init();
108
84
 
109
85
  MY_INIT(argv[0]);
110
86
 
122
98
  pthread_mutex_init(&row_lock, NULL);
123
99
 
124
100
  for (method= AZ_METHOD_BLOCK; method < AZ_METHOD_MAX; method++)
125
 
    scheduler((az_method)method);
 
101
    scheduler(method);
126
102
 
127
103
  (void)pthread_mutex_destroy(&counter_mutex);
128
104
  (void)pthread_cond_destroy(&count_threshhold);
139
115
{
140
116
  unsigned int x;
141
117
  uint64_t total;
142
 
  boost::scoped_ptr<azio_stream> writer_handle_ap(new azio_stream);
143
 
  azio_stream &writer_handle= *writer_handle_ap.get();
 
118
  azio_stream writer_handle;
144
119
  thread_context_st *context;
145
120
  pthread_t mainthread;            /* Thread descriptor */
146
121
  pthread_attr_t attr;          /* Thread attributes */
176
151
    context[x].use_aio= use_aio;
177
152
 
178
153
    /* now you create the thread */
179
 
    if (pthread_create(&mainthread, &attr, run_concurrent_task,
 
154
    if (pthread_create(&mainthread, &attr, run_task,
180
155
                       (void *)context) != 0)
181
156
    {
182
157
      fprintf(stderr,"Could not create thread\n");
192
167
    timer_alarm= true;
193
168
    pthread_mutex_unlock(&timer_alarm_mutex);
194
169
 
195
 
    if (pthread_create(&mainthread, &attr, timer_thread,
 
170
    if (pthread_create(&mainthread, &attr, timer_thread, 
196
171
                       (void *)&opt_timer_length) != 0)
197
172
    {
198
 
      fprintf(stderr,"%s: Could not create timer thread\n", drizzled::internal::my_progname);
 
173
      fprintf(stderr,"%s: Could not create timer thread\n", my_progname);
199
174
      exit(1);
200
175
    }
201
176
  }
237
212
  time_t *timer_length= (time_t *)p;
238
213
  struct timespec abstime;
239
214
 
240
 
  /*
241
 
    We lock around the initial call in case were we in a loop. This
 
215
  /* 
 
216
    We lock around the initial call in case were we in a loop. This 
242
217
    also keeps the value properly syncronized across call threads.
243
218
  */
244
219
  pthread_mutex_lock(&sleeper_mutex);
261
236
  return 0;
262
237
}
263
238
 
264
 
void *run_concurrent_task(void *p)
 
239
void *run_task(void *p)
265
240
{
266
241
  thread_context_st *context= (thread_context_st *)p;
267
242
  uint64_t count;
268
243
  int ret;
269
244
  int error;
270
 
  boost::scoped_ptr<azio_stream> reader_handle_ap(new azio_stream);
271
 
  azio_stream &reader_handle= *reader_handle_ap.get();
 
245
  azio_stream reader_handle;
272
246
 
273
 
  if (!(ret= azopen(&reader_handle, TEST_FILENAME, O_RDONLY,
 
247
  if (!(ret= azopen(&reader_handle, TEST_FILENAME, O_RDONLY|O_BINARY,
274
248
                    context->use_aio)))
275
249
  {
276
250
    printf("Could not open test file\n");
281
255
  while (master_wakeup)
282
256
  {
283
257
    pthread_cond_wait(&sleep_threshhold, &sleeper_mutex);
284
 
  }
 
258
  } 
285
259
  pthread_mutex_unlock(&sleeper_mutex);
286
260
 
287
261
  /* Do Stuff */
316
290
  int ret;
317
291
  uint64_t x;
318
292
 
319
 
  if (!(ret= azopen(write_handler, TEST_FILENAME, O_CREAT|O_RDWR|O_TRUNC,
 
293
  if (!(ret= azopen(write_handler, TEST_FILENAME, O_CREAT|O_RDWR|O_TRUNC|O_BINARY,
320
294
                    AZ_METHOD_BLOCK)))
321
295
  {
322
296
    printf("Could not create test file\n");
339
313
  /* Avoid zero length strings */
340
314
  length++;
341
315
 
342
 
  get_random_string(buffer, length);
 
316
  get_random_string(buffer, length); 
343
317
  pthread_mutex_lock(&row_lock);
344
318
  azwrite_row(s, buffer, length);
345
319
  pthread_mutex_unlock(&row_lock);