~stewart/drizzle/embedded-innodb-create-select-transaction-arrgh

« back to all changes in this revision

Viewing changes to storage/archive/archive_performance.c

  • Committer: brian
  • Date: 2008-06-25 05:29:13 UTC
  • Revision ID: brian@localhost.localdomain-20080625052913-6upwo0jsrl4lnapl
clean slate

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 "azio.h"
 
17
#include <string.h>
 
18
#include <assert.h>
 
19
#include <stdio.h>
 
20
#include <stdlib.h>
 
21
#include <string.h>
 
22
#include <my_getopt.h>
 
23
#include <mysql_version.h>
 
24
 
 
25
#define ARCHIVE_ROW_HEADER_SIZE 4
 
26
 
 
27
#define COMMENT_STRING "Your bases"
 
28
#define FRM_STRING "My bases"
 
29
#define TEST_FILENAME "performance_test.az"
 
30
#define TEST_STRING_INIT "YOU don't know about me without you have read a book by the name of The Adventures of Tom Sawyer; but that ain't no matter.  That book was made by Mr. Mark Twain, and he told the truth, mainly.  There was things which he stretched, but mainly he told the truth.  That is nothing.  I never seen anybody but lied one time or another, without it was Aunt Polly, or the widow, or maybe Mary.  Aunt Polly--Tom's Aunt Polly, she is--and Mary, and the Widow Douglas is all told about in that book, which is mostly a true book, with some stretchers, as I said before.  Now the way that the book winds up is this:  Tom and me found the money that the robbers hid in the cave, and it made us rich.  We got six thousand dollars apiece--all gold.  It was an awful sight of money when it was piled up.  Well, Judge Thatcher he took it and put it out at interest, and it fetched us a dollar a day apiece all the year round --more than a body could tell what to do with.  The Widow Douglas she took me for her son, and allowed she would..."
 
31
#define TEST_LOOP_NUM 100
 
32
 
 
33
 
 
34
#define ARCHIVE_ROW_HEADER_SIZE 4
 
35
 
 
36
#define BUFFER_LEN 1024
 
37
 
 
38
char test_string[BUFFER_LEN];
 
39
 
 
40
#define ROWS_TO_TEST LL(2000000)
 
41
 
 
42
/* prototypes */
 
43
long int timedif(struct timeval a, struct timeval b);
 
44
int generate_data(unsigned long long length);
 
45
int read_test(azio_stream *reader_handle, unsigned long long rows_to_test_for);
 
46
 
 
47
int main(int argc, char *argv[])
 
48
{
 
49
  unsigned int method;
 
50
  struct timeval start_time, end_time;
 
51
  long int timing;
 
52
 
 
53
  my_init();
 
54
  MY_INIT(argv[0]);
 
55
 
 
56
  if (argc != 1)
 
57
    return 1;
 
58
 
 
59
  printf("Performing write() test\n");
 
60
  generate_data(ROWS_TO_TEST);
 
61
 
 
62
  for (method= AZ_METHOD_BLOCK; method < AZ_METHOD_MAX; method++)
 
63
  {
 
64
    unsigned int ret;
 
65
    azio_stream reader_handle;
 
66
 
 
67
    if (method)
 
68
      printf("Performing aio_read() test\n");
 
69
    else
 
70
      printf("Performing read() test\n");
 
71
 
 
72
    if (!(ret= azopen(&reader_handle, TEST_FILENAME, O_RDONLY|O_BINARY,
 
73
                    method)))
 
74
    {
 
75
      printf("Could not open test file\n");
 
76
      return 0;
 
77
    }
 
78
 
 
79
    gettimeofday(&start_time, NULL);
 
80
    read_test(&reader_handle, 1044496L);
 
81
    gettimeofday(&end_time, NULL);
 
82
    timing= timedif(end_time, start_time);
 
83
    printf("Time took to read was %ld.%03ld seconds\n", timing / 1000, timing % 1000);
 
84
 
 
85
    azclose(&reader_handle);
 
86
  }
 
87
 
 
88
  my_end(0);
 
89
 
 
90
  return 0;
 
91
}
 
92
 
 
93
int generate_data(unsigned long long rows_to_test)
 
94
{
 
95
  azio_stream writer_handle;
 
96
  unsigned long long x;
 
97
  unsigned int ret;
 
98
  struct timeval start_time, end_time;
 
99
  long int timing;
 
100
  struct stat buf;
 
101
 
 
102
  if ((stat(TEST_FILENAME, &buf)) == 0)
 
103
  {
 
104
    printf("Writer file already available\n");
 
105
    return 0;
 
106
  }
 
107
 
 
108
  if (!(ret= azopen(&writer_handle, TEST_FILENAME, O_CREAT|O_RDWR|O_TRUNC|O_BINARY,
 
109
                    AZ_METHOD_BLOCK)))
 
110
  {
 
111
    printf("Could not create test file\n");
 
112
    exit(1);
 
113
  }
 
114
 
 
115
  gettimeofday(&start_time, NULL);
 
116
  for (x= 0; x < rows_to_test; x++)
 
117
  {
 
118
    ret= azwrite_row(&writer_handle, test_string, BUFFER_LEN);
 
119
    if (ret != BUFFER_LEN)
 
120
    {
 
121
      printf("Size %u\n", ret);
 
122
      assert(ret != BUFFER_LEN);
 
123
    }
 
124
    if ((x % 14031) == 0)
 
125
    {
 
126
      azflush(&writer_handle,  Z_SYNC_FLUSH);
 
127
    }
 
128
  }
 
129
  /* 
 
130
    We put the flush in just to be honest with write speed, normally azclose 
 
131
    would be fine.
 
132
  */
 
133
  azflush(&writer_handle,  Z_SYNC_FLUSH);
 
134
  gettimeofday(&end_time, NULL);
 
135
  timing= timedif(end_time, start_time);
 
136
 
 
137
  azclose(&writer_handle);
 
138
 
 
139
  printf("Time took to write was %ld.%03ld seconds\n", timing / 1000, timing % 1000);
 
140
 
 
141
  return 0;
 
142
}
 
143
 
 
144
int read_test(azio_stream *reader_handle, unsigned long long rows_to_test_for)
 
145
{
 
146
  unsigned long long read_length= 0;
 
147
  unsigned long long count= 0;
 
148
  unsigned int ret;
 
149
  int error;
 
150
 
 
151
  azread_init(reader_handle);
 
152
  while ((ret= azread_row(reader_handle, &error)))
 
153
  {
 
154
    if (error)
 
155
    {
 
156
      fprintf(stderr, "Got an error while reading at row %llu\n", count);
 
157
      exit(1);
 
158
    }
 
159
 
 
160
    read_length+= ret;
 
161
    assert(!memcmp(reader_handle->row_ptr, test_string, ret));
 
162
    if (ret != BUFFER_LEN)
 
163
    {
 
164
      printf("Size %u\n", ret);
 
165
      assert(ret != BUFFER_LEN);
 
166
    }
 
167
    count++;
 
168
  }
 
169
  assert(rows_to_test_for == rows_to_test_for);
 
170
 
 
171
  return 0;
 
172
}
 
173
 
 
174
long int timedif(struct timeval a, struct timeval b)
 
175
{
 
176
    register int us, s;
 
177
 
 
178
    us = a.tv_usec - b.tv_usec;
 
179
    us /= 1000;
 
180
    s = a.tv_sec - b.tv_sec;
 
181
    s *= 1000;
 
182
    return s + us;
 
183
}