~ubuntu-branches/ubuntu/trusty/drizzle/trusty

« back to all changes in this revision

Viewing changes to plugin/archive/archive_performance.cc

  • Committer: Bazaar Package Importer
  • Author(s): Monty Taylor
  • Date: 2010-03-18 12:12:31 UTC
  • Revision ID: james.westby@ubuntu.com-20100318121231-k6g1xe6cshbwa0f8
Tags: upstream-2010.03.1347
ImportĀ upstreamĀ versionĀ 2010.03.1347

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 "drizzled/my_getopt.h"
 
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
 
 
40
#define TEST_FILENAME "performance_test.az"
 
41
 
 
42
#define BUFFER_LEN 1024
 
43
 
 
44
char test_string[BUFFER_LEN];
 
45
 
 
46
#define ROWS_TO_TEST 2000000LL
 
47
 
 
48
/* prototypes */
 
49
static long int timedif(struct timeval a, struct timeval b);
 
50
static int generate_data(uint64_t length);
 
51
static int read_test(azio_stream *reader_handle, uint64_t rows_to_test_for);
 
52
 
 
53
int main(int argc, char *argv[])
 
54
{
 
55
  unsigned int method;
 
56
  struct timeval start_time, end_time;
 
57
  long int timing;
 
58
 
 
59
  drizzled::internal::my_init();
 
60
  MY_INIT(argv[0]);
 
61
 
 
62
  if (argc != 1)
 
63
    return 1;
 
64
 
 
65
  printf("Performing write() test\n");
 
66
  generate_data(ROWS_TO_TEST);
 
67
 
 
68
  for (method= AZ_METHOD_BLOCK; method < AZ_METHOD_MAX; method++)
 
69
  {
 
70
    unsigned int ret;
 
71
    azio_stream reader_handle;
 
72
 
 
73
    if (method)
 
74
      printf("Performing azio_read() test\n");
 
75
    else
 
76
      printf("Performing read() test\n");
 
77
 
 
78
    if (!(ret= azopen(&reader_handle, TEST_FILENAME, O_RDONLY,
 
79
                      (az_method)method)))
 
80
    {
 
81
      printf("Could not open test file\n");
 
82
      return 0;
 
83
    }
 
84
 
 
85
    gettimeofday(&start_time, NULL);
 
86
    read_test(&reader_handle, 1044496L);
 
87
    gettimeofday(&end_time, NULL);
 
88
    timing= timedif(end_time, start_time);
 
89
    printf("Time took to read was %ld.%03ld seconds\n", timing / 1000, timing % 1000);
 
90
 
 
91
    azclose(&reader_handle);
 
92
  }
 
93
 
 
94
  drizzled::internal::my_end();
 
95
 
 
96
  return 0;
 
97
}
 
98
 
 
99
static int generate_data(uint64_t rows_to_test)
 
100
{
 
101
  azio_stream writer_handle;
 
102
  uint64_t x;
 
103
  unsigned int ret;
 
104
  struct timeval start_time, end_time;
 
105
  long int timing;
 
106
  struct stat buf;
 
107
 
 
108
  if ((stat(TEST_FILENAME, &buf)) == 0)
 
109
  {
 
110
    printf("Writer file already available\n");
 
111
    return 0;
 
112
  }
 
113
 
 
114
  if (!(ret= azopen(&writer_handle, TEST_FILENAME, O_CREAT|O_RDWR|O_TRUNC,
 
115
                    AZ_METHOD_BLOCK)))
 
116
  {
 
117
    printf("Could not create test file\n");
 
118
    exit(1);
 
119
  }
 
120
 
 
121
  gettimeofday(&start_time, NULL);
 
122
  for (x= 0; x < rows_to_test; x++)
 
123
  {
 
124
    ret= azwrite_row(&writer_handle, test_string, BUFFER_LEN);
 
125
    if (ret != BUFFER_LEN)
 
126
    {
 
127
      printf("Size %u\n", ret);
 
128
      assert(ret != BUFFER_LEN);
 
129
    }
 
130
    if ((x % 14031) == 0)
 
131
    {
 
132
      azflush(&writer_handle,  Z_SYNC_FLUSH);
 
133
    }
 
134
  }
 
135
  /*
 
136
    We put the flush in just to be honest with write speed, normally azclose
 
137
    would be fine.
 
138
  */
 
139
  azflush(&writer_handle,  Z_SYNC_FLUSH);
 
140
  gettimeofday(&end_time, NULL);
 
141
  timing= timedif(end_time, start_time);
 
142
 
 
143
  azclose(&writer_handle);
 
144
 
 
145
  printf("Time took to write was %ld.%03ld seconds\n", timing / 1000, timing % 1000);
 
146
 
 
147
  return 0;
 
148
}
 
149
 
 
150
static int read_test(azio_stream *reader_handle, uint64_t rows_to_test_for)
 
151
{
 
152
  uint64_t read_length= 0;
 
153
  uint64_t count= 0;
 
154
  unsigned int ret;
 
155
  int error;
 
156
 
 
157
  azread_init(reader_handle);
 
158
  while ((ret= azread_row(reader_handle, &error)))
 
159
  {
 
160
    if (error)
 
161
    {
 
162
      fprintf(stderr, "Got an error while reading at row %"PRIu64"\n", count);
 
163
      exit(1);
 
164
    }
 
165
 
 
166
    read_length+= ret;
 
167
    assert(!memcmp(reader_handle->row_ptr, test_string, ret));
 
168
    if (ret != BUFFER_LEN)
 
169
    {
 
170
      printf("Size %u\n", ret);
 
171
      assert(ret != BUFFER_LEN);
 
172
    }
 
173
    count++;
 
174
  }
 
175
  assert(rows_to_test_for == rows_to_test_for);
 
176
 
 
177
  return 0;
 
178
}
 
179
 
 
180
static long int timedif(struct timeval a, struct timeval b)
 
181
{
 
182
    register int us, s;
 
183
 
 
184
    us = a.tv_usec - b.tv_usec;
 
185
    us /= 1000;
 
186
    s = a.tv_sec - b.tv_sec;
 
187
    s *= 1000;
 
188
    return s + us;
 
189
}