Add writeback call to objdb
[openais.git] / test / ckptbench.c
blob4590e857726826cb2ee7f6f29ee542828baea656
1 #define _BSD_SOURCE
2 /*
3 * Copyright (c) 2002-2004 MontaVista Software, Inc.
4 * Copyright (c) 2006 Sun Microsystems, Inc.
6 * All rights reserved.
8 * Author: Steven Dake (sdake@mvista.com)
10 * This software licensed under BSD license, the text of which follows:
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions are met:
15 * - Redistributions of source code must retain the above copyright notice,
16 * this list of conditions and the following disclaimer.
17 * - Redistributions in binary form must reproduce the above copyright notice,
18 * this list of conditions and the following disclaimer in the documentation
19 * and/or other materials provided with the distribution.
20 * - Neither the name of the MontaVista Software, Inc. nor the names of its
21 * contributors may be used to endorse or promote products derived from this
22 * software without specific prior written permission.
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
28 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
34 * THE POSSIBILITY OF SUCH DAMAGE.
37 #include <stdio.h>
38 #include <stdlib.h>
39 #include <string.h>
40 #include <signal.h>
41 #include <unistd.h>
42 #include <errno.h>
43 #include <unistd.h>
44 #include <time.h>
45 #include <sys/time.h>
46 #include <sys/types.h>
47 #include <sys/socket.h>
48 #include <sys/select.h>
49 #include <sys/un.h>
50 #include <sys/socket.h>
51 #include <netinet/in.h>
52 #include <arpa/inet.h>
54 #include "saAis.h"
55 #include "saCkpt.h"
56 #include "sa_error.h"
58 #ifdef OPENAIS_SOLARIS
59 #define timersub(a, b, result) \
60 do { \
61 (result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \
62 (result)->tv_usec = (a)->tv_usec - (b)->tv_usec; \
63 if ((result)->tv_usec < 0) { \
64 --(result)->tv_sec; \
65 (result)->tv_usec += 1000000; \
66 } \
67 } while (0)
68 #endif
70 int alarm_notice;
72 void fail_on_error(SaAisErrorT error, char* opName) {
73 if (error != SA_AIS_OK) {
74 printf ("%s: result %s\n", opName, get_sa_error_b(error));
75 exit (1);
79 void printSaNameT (SaNameT *name)
81 int i;
83 for (i = 0; i < name->length; i++) {
84 printf ("%c", name->value[i]);
88 SaVersionT version = { 'B', 1, 1 };
90 SaCkptCallbacksT callbacks = {
95 SaNameT checkpointName = { 5, "abra\0" };
97 SaCkptCheckpointCreationAttributesT checkpointCreationAttributes = {
98 .creationFlags = SA_CKPT_WR_ALL_REPLICAS,
99 .checkpointSize = 250000,
100 .retentionDuration = 0,
101 .maxSections = 5,
102 .maxSectionSize = 250000,
103 .maxSectionIdSize = 15
106 SaCkptSectionIdT sectionId1 = {
108 (SaUint8T *) "section ID #1"
111 SaCkptSectionIdT sectionId2 = {
113 (SaUint8T *) "section ID #2"
115 SaCkptSectionCreationAttributesT sectionCreationAttributes1 = {
116 &sectionId1,
117 0xFFFFFFFF
120 SaCkptSectionCreationAttributesT sectionCreationAttributes2 = {
121 &sectionId2,
122 0xFFFFFFFF
125 char readBuffer1[1025];
127 char readBuffer2[1025];
129 SaCkptIOVectorElementT ReadVectorElements[] = {
133 (SaUint8T *) "section ID #1"
135 readBuffer1,
136 sizeof (readBuffer1),
143 (SaUint8T *) "section ID #2"
145 readBuffer2,
146 sizeof (readBuffer2),
152 #define DATASIZE 200000
153 #define LOOPS 5000
155 char data[500000];
156 SaCkptIOVectorElementT WriteVectorElements[] = {
160 (SaUint8T *) "section ID #1"
162 data, /*"written data #1, this should extend past end of old section data", */
163 DATASIZE, /*sizeof ("data #1, this should extend past end of old section data") + 1, */
164 0, //5,
167 #ifdef COMPILE_OUT
171 (SaUint8T *) "section ID #2"
173 data, /*"written data #2, this should extend past end of old section data" */
174 DATASIZE, /*sizeof ("written data #2, this should extend past end of old section data") + 1, */
175 0, //3,
178 #endif
181 void ckpt_benchmark (SaCkptCheckpointHandleT checkpointHandle,
182 int write_size)
184 struct timeval tv1, tv2, tv_elapsed;
185 SaUint32T erroroneousVectorIndex = 0;
186 SaAisErrorT error;
187 int write_count = 0;
189 alarm_notice = 0;
190 alarm (10);
191 WriteVectorElements[0].dataSize = write_size;
193 gettimeofday (&tv1, NULL);
194 do {
196 * Test checkpoint write
198 retry:
199 error = saCkptCheckpointWrite (checkpointHandle,
200 WriteVectorElements,
202 &erroroneousVectorIndex);
203 if (error == SA_AIS_ERR_TRY_AGAIN) {
204 goto retry;
206 fail_on_error(error, "saCkptCheckpointWrite");
207 write_count += 1;
208 } while (alarm_notice == 0);
209 gettimeofday (&tv2, NULL);
210 timersub (&tv2, &tv1, &tv_elapsed);
212 printf ("%5d Writes ", write_count);
213 printf ("%5d bytes per write ", write_size);
214 printf ("%7.3f Seconds runtime ",
215 (tv_elapsed.tv_sec + (tv_elapsed.tv_usec / 1000000.0)));
216 printf ("%9.3f TP/s ",
217 ((float)write_count) / (tv_elapsed.tv_sec + (tv_elapsed.tv_usec / 1000000.0)));
218 printf ("%7.3f MB/s.\n",
219 ((float)write_count) * ((float)write_size) / ((tv_elapsed.tv_sec + (tv_elapsed.tv_usec / 1000000.0)) * 1000000.0));
222 void sigalrm_handler (int num)
224 alarm_notice = 1;
227 int main (void) {
228 SaCkptHandleT ckptHandle;
229 SaCkptCheckpointHandleT checkpointHandle;
230 SaAisErrorT error;
231 int size;
232 int i;
234 signal (SIGALRM, sigalrm_handler);
236 error = saCkptInitialize (&ckptHandle, &callbacks, &version);
237 fail_on_error(error, "saCkptInitialize");
239 error = saCkptCheckpointOpen (ckptHandle,
240 &checkpointName,
241 &checkpointCreationAttributes,
242 SA_CKPT_CHECKPOINT_CREATE|SA_CKPT_CHECKPOINT_READ|SA_CKPT_CHECKPOINT_WRITE,
244 &checkpointHandle);
245 fail_on_error(error, "saCkptCheckpointOpen");
246 error = saCkptSectionCreate (checkpointHandle,
247 &sectionCreationAttributes1,
248 "Initial Data #0",
249 strlen ("Initial Data #0") + 1);
250 fail_on_error(error, "saCkptCheckpointSectionCreate");
251 error = saCkptSectionCreate (checkpointHandle,
252 &sectionCreationAttributes2,
253 "Initial Data #0",
254 strlen ("Initial Data #0") + 1);
255 fail_on_error(error, "saCkptCheckpointSectionCreate");
257 size = 1;
259 for (i = 0; i < 50; i++) { /* number of repetitions - up to 50k */
260 ckpt_benchmark (checkpointHandle, size);
261 size += 1000;
264 error = saCkptFinalize (ckptHandle);
265 return (0);