~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/archive/concurrency_test.c

  • Committer: Monty Taylor
  • Date: 2009-03-04 02:16:28 UTC
  • mto: (917.1.2 mordred)
  • mto: This revision was merged to the branch mainline in revision 912.
  • Revision ID: mordred@inaugust.com-20090304021628-rfq0b16uoi09g8tx
Fix to make VPATH builds work again.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
  Just a test application for threads.
3
3
  */
4
4
#include "azio.h"
5
 
#include <libdrizzle/libdrizzle.h>
 
5
#include <libdrizzleclient/libdrizzle.h>
6
6
#include <mysys/my_getopt.h>
7
7
#include <stdio.h>
8
8
#include <stdlib.h>
28
28
 
29
29
#define DEFAULT_INITIAL_LOAD 10000
30
30
#define DEFAULT_EXECUTE_SECONDS 120
31
 
#define DEFAULT_CONCURRENCY 8
32
31
#define TEST_FILENAME "concurrency_test.az"
33
32
 
34
33
#define HUGE_STRING_LENGTH 8192
47
46
pthread_mutex_t row_lock;
48
47
 
49
48
/* Prototypes */
50
 
void *run_task(void *p);
 
49
void *run_concurrent_task(void *p);
51
50
void *timer_thread(void *p);
52
51
void scheduler(az_method use_aio);
53
 
void create_data_file(azio_stream *write_handler, unsigned long long rows);
 
52
void create_data_file(azio_stream *write_handler, uint64_t rows);
54
53
unsigned int write_row(azio_stream *s);
55
54
 
56
55
typedef struct thread_context_st thread_context_st;
57
56
struct thread_context_st {
58
57
  unsigned int how_often_to_write;
59
 
  unsigned long long counter;
 
58
  uint64_t counter;
60
59
  az_method use_aio;
61
60
  azio_stream *writer;
62
61
};
114
113
void scheduler(az_method use_aio)
115
114
{
116
115
  unsigned int x;
117
 
  unsigned long long total;
 
116
  uint64_t total;
118
117
  azio_stream writer_handle;
119
118
  thread_context_st *context;
120
119
  pthread_t mainthread;            /* Thread descriptor */
151
150
    context[x].use_aio= use_aio;
152
151
 
153
152
    /* now you create the thread */
154
 
    if (pthread_create(&mainthread, &attr, run_task,
 
153
    if (pthread_create(&mainthread, &attr, run_concurrent_task,
155
154
                       (void *)context) != 0)
156
155
    {
157
156
      fprintf(stderr,"Could not create thread\n");
167
166
    timer_alarm= true;
168
167
    pthread_mutex_unlock(&timer_alarm_mutex);
169
168
 
170
 
    if (pthread_create(&mainthread, &attr, timer_thread, 
 
169
    if (pthread_create(&mainthread, &attr, timer_thread,
171
170
                       (void *)&opt_timer_length) != 0)
172
171
    {
173
172
      fprintf(stderr,"%s: Could not create timer thread\n", my_progname);
204
203
  free(context);
205
204
  azclose(&writer_handle);
206
205
 
207
 
  printf("Read %llu rows\n", total);
 
206
  printf("Read %"PRIu64" rows\n", total);
208
207
}
209
208
 
210
209
void *timer_thread(void *p)
212
211
  time_t *timer_length= (time_t *)p;
213
212
  struct timespec abstime;
214
213
 
215
 
  /* 
216
 
    We lock around the initial call in case were we in a loop. This 
 
214
  /*
 
215
    We lock around the initial call in case were we in a loop. This
217
216
    also keeps the value properly syncronized across call threads.
218
217
  */
219
218
  pthread_mutex_lock(&sleeper_mutex);
236
235
  return 0;
237
236
}
238
237
 
239
 
void *run_task(void *p)
 
238
void *run_concurrent_task(void *p)
240
239
{
241
240
  thread_context_st *context= (thread_context_st *)p;
242
 
  unsigned long long count;
 
241
  uint64_t count;
243
242
  int ret;
244
243
  int error;
245
244
  azio_stream reader_handle;
246
245
 
247
 
  if (!(ret= azopen(&reader_handle, TEST_FILENAME, O_RDONLY|O_BINARY,
 
246
  if (!(ret= azopen(&reader_handle, TEST_FILENAME, O_RDONLY,
248
247
                    context->use_aio)))
249
248
  {
250
249
    printf("Could not open test file\n");
255
254
  while (master_wakeup)
256
255
  {
257
256
    pthread_cond_wait(&sleep_threshhold, &sleeper_mutex);
258
 
  } 
 
257
  }
259
258
  pthread_mutex_unlock(&sleeper_mutex);
260
259
 
261
260
  /* Do Stuff */
285
284
  return NULL;
286
285
}
287
286
 
288
 
void create_data_file(azio_stream *write_handler, unsigned long long rows)
 
287
void create_data_file(azio_stream *write_handler, uint64_t rows)
289
288
{
290
289
  int ret;
291
 
  unsigned long long x;
 
290
  uint64_t x;
292
291
 
293
 
  if (!(ret= azopen(write_handler, TEST_FILENAME, O_CREAT|O_RDWR|O_TRUNC|O_BINARY,
 
292
  if (!(ret= azopen(write_handler, TEST_FILENAME, O_CREAT|O_RDWR|O_TRUNC,
294
293
                    AZ_METHOD_BLOCK)))
295
294
  {
296
295
    printf("Could not create test file\n");
313
312
  /* Avoid zero length strings */
314
313
  length++;
315
314
 
316
 
  get_random_string(buffer, length); 
 
315
  get_random_string(buffer, length);
317
316
  pthread_mutex_lock(&row_lock);
318
317
  azwrite_row(s, buffer, length);
319
318
  pthread_mutex_unlock(&row_lock);