~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/archive/archive_performance.cc

  • Committer: Monty Taylor
  • Date: 2011-03-09 20:59:40 UTC
  • mfrom: (2226.1.14 build)
  • Revision ID: mordred@inaugust.com-20110309205940-7f5mk6zba2u7bawa
Merged Dave - Filtered Replication docs
Merged Olaf - Refactoring work
Removed archive, blackhole, filesystem_engine, blitzdb, csv and pbxt from
the tree pre-GA as we have no interest in supporting them moving forward.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (C) 2006 MySQL AB
2
 
 
3
 
   This program is free software; you can redistribute it and/or modify
4
 
   it under the terms of the GNU General Public License as published by
5
 
   the Free Software Foundation; version 2 of the License.
6
 
 
7
 
   This program is distributed in the hope that it will be useful,
8
 
   but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
 
   GNU General Public License for more details.
11
 
 
12
 
   You should have received a copy of the GNU General Public License
13
 
   along with this program; if not, write to the Free Software
14
 
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
15
 
 
16
 
#include <config.h>
17
 
 
18
 
#include "azio.h"
19
 
#include <string.h>
20
 
#include <assert.h>
21
 
#include <stdio.h>
22
 
#include <stdlib.h>
23
 
#include <string.h>
24
 
#include <fcntl.h>
25
 
#include <sys/stat.h>
26
 
#include <memory>
27
 
 
28
 
#if TIME_WITH_SYS_TIME
29
 
# include <sys/time.h>
30
 
# include <time.h>
31
 
#else
32
 
# if HAVE_SYS_TIME_H
33
 
#  include <sys/time.h>
34
 
# else
35
 
#  include <time.h>
36
 
# endif
37
 
#endif
38
 
 
39
 
#include <boost/scoped_ptr.hpp>
40
 
 
41
 
#define TEST_FILENAME "performance_test.az"
42
 
 
43
 
#define BUFFER_LEN 1024
44
 
 
45
 
char test_string[BUFFER_LEN];
46
 
 
47
 
#define ROWS_TO_TEST 2000000LL
48
 
 
49
 
/* prototypes */
50
 
static long int timedif(struct timeval a, struct timeval b);
51
 
static int generate_data(uint64_t length);
52
 
static int read_test(azio_stream *reader_handle, uint64_t rows_to_test_for);
53
 
 
54
 
int main(int argc, char *argv[])
55
 
{
56
 
  unsigned int method;
57
 
  struct timeval start_time, end_time;
58
 
  long int timing;
59
 
 
60
 
  drizzled::internal::my_init();
61
 
  MY_INIT(argv[0]);
62
 
 
63
 
  if (argc != 1)
64
 
    return 1;
65
 
 
66
 
  printf("Performing write() test\n");
67
 
  generate_data(ROWS_TO_TEST);
68
 
 
69
 
  for (method= AZ_METHOD_BLOCK; method < AZ_METHOD_MAX; method++)
70
 
  {
71
 
    unsigned int ret;
72
 
    boost::scoped_ptr<azio_stream> reader_handle_ap(new azio_stream);
73
 
    azio_stream &reader_handle= *reader_handle_ap.get();
74
 
 
75
 
    if (method)
76
 
      printf("Performing azio_read() test\n");
77
 
    else
78
 
      printf("Performing read() test\n");
79
 
 
80
 
    if (!(ret= azopen(&reader_handle, TEST_FILENAME, O_RDONLY,
81
 
                      (az_method)method)))
82
 
    {
83
 
      printf("Could not open test file\n");
84
 
      return 0;
85
 
    }
86
 
 
87
 
    gettimeofday(&start_time, NULL);
88
 
    read_test(&reader_handle, 1044496L);
89
 
    gettimeofday(&end_time, NULL);
90
 
    timing= timedif(end_time, start_time);
91
 
    printf("Time took to read was %ld.%03ld seconds\n", timing / 1000, timing % 1000);
92
 
 
93
 
    azclose(&reader_handle);
94
 
  }
95
 
 
96
 
  drizzled::internal::my_end();
97
 
 
98
 
  return 0;
99
 
}
100
 
 
101
 
static int generate_data(uint64_t rows_to_test)
102
 
{
103
 
  boost::scoped_ptr<azio_stream> writer_handle_ap(new azio_stream);
104
 
  azio_stream &writer_handle= *writer_handle_ap.get();
105
 
  uint64_t x;
106
 
  unsigned int ret;
107
 
  struct timeval start_time, end_time;
108
 
  long int timing;
109
 
  struct stat buf;
110
 
 
111
 
  if ((stat(TEST_FILENAME, &buf)) == 0)
112
 
  {
113
 
    printf("Writer file already available\n");
114
 
    return 0;
115
 
  }
116
 
 
117
 
  if (!(ret= azopen(&writer_handle, TEST_FILENAME, O_CREAT|O_RDWR|O_TRUNC,
118
 
                    AZ_METHOD_BLOCK)))
119
 
  {
120
 
    printf("Could not create test file\n");
121
 
    exit(1);
122
 
  }
123
 
 
124
 
  gettimeofday(&start_time, NULL);
125
 
  for (x= 0; x < rows_to_test; x++)
126
 
  {
127
 
    ret= azwrite_row(&writer_handle, test_string, BUFFER_LEN);
128
 
    if (ret != BUFFER_LEN)
129
 
    {
130
 
      printf("Size %u\n", ret);
131
 
      assert(ret != BUFFER_LEN);
132
 
    }
133
 
    if ((x % 14031) == 0)
134
 
    {
135
 
      azflush(&writer_handle,  Z_SYNC_FLUSH);
136
 
    }
137
 
  }
138
 
  /*
139
 
    We put the flush in just to be honest with write speed, normally azclose
140
 
    would be fine.
141
 
  */
142
 
  azflush(&writer_handle,  Z_SYNC_FLUSH);
143
 
  gettimeofday(&end_time, NULL);
144
 
  timing= timedif(end_time, start_time);
145
 
 
146
 
  azclose(&writer_handle);
147
 
 
148
 
  printf("Time took to write was %ld.%03ld seconds\n", timing / 1000, timing % 1000);
149
 
 
150
 
  return 0;
151
 
}
152
 
 
153
 
static int read_test(azio_stream *reader_handle, uint64_t rows_to_test_for)
154
 
{
155
 
  uint64_t read_length= 0;
156
 
  uint64_t count= 0;
157
 
  unsigned int ret;
158
 
  int error;
159
 
 
160
 
  azread_init(reader_handle);
161
 
  while ((ret= azread_row(reader_handle, &error)))
162
 
  {
163
 
    if (error)
164
 
    {
165
 
      fprintf(stderr, "Got an error while reading at row %"PRIu64"\n", count);
166
 
      exit(1);
167
 
    }
168
 
 
169
 
    read_length+= ret;
170
 
    assert(!memcmp(reader_handle->row_ptr, test_string, ret));
171
 
    if (ret != BUFFER_LEN)
172
 
    {
173
 
      printf("Size %u\n", ret);
174
 
      assert(ret != BUFFER_LEN);
175
 
    }
176
 
    count++;
177
 
  }
178
 
  assert(rows_to_test_for == rows_to_test_for);
179
 
 
180
 
  return 0;
181
 
}
182
 
 
183
 
static long int timedif(struct timeval a, struct timeval b)
184
 
{
185
 
    register int us, s;
186
 
 
187
 
    us = a.tv_usec - b.tv_usec;
188
 
    us /= 1000;
189
 
    s = a.tv_sec - b.tv_sec;
190
 
    s *= 1000;
191
 
    return s + us;
192
 
}