ckptbench.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. #define _BSD_SOURCE
  2. /*
  3. * Copyright (c) 2002-2004 MontaVista Software, Inc.
  4. * Copyright (c) 2006 Sun Microsystems, Inc.
  5. *
  6. * All rights reserved.
  7. *
  8. * Author: Steven Dake (sdake@mvista.com)
  9. *
  10. * This software licensed under BSD license, the text of which follows:
  11. *
  12. * Redistribution and use in source and binary forms, with or without
  13. * modification, are permitted provided that the following conditions are met:
  14. *
  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.
  23. *
  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.
  35. */
  36. #include <stdio.h>
  37. #include <stdlib.h>
  38. #include <string.h>
  39. #include <signal.h>
  40. #include <unistd.h>
  41. #include <errno.h>
  42. #include <unistd.h>
  43. #include <time.h>
  44. #include <sys/time.h>
  45. #include <sys/types.h>
  46. #include <sys/socket.h>
  47. #include <sys/select.h>
  48. #include <sys/un.h>
  49. #include <sys/socket.h>
  50. #include <netinet/in.h>
  51. #include <arpa/inet.h>
  52. #include "saAis.h"
  53. #include "saCkpt.h"
  54. #ifdef OPENAIS_SOLARIS
  55. #define timersub(a, b, result) \
  56. do { \
  57. (result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \
  58. (result)->tv_usec = (a)->tv_usec - (b)->tv_usec; \
  59. if ((result)->tv_usec < 0) { \
  60. --(result)->tv_sec; \
  61. (result)->tv_usec += 1000000; \
  62. } \
  63. } while (0)
  64. #endif
  65. int alarm_notice;
  66. void printSaNameT (SaNameT *name)
  67. {
  68. int i;
  69. for (i = 0; i < name->length; i++) {
  70. printf ("%c", name->value[i]);
  71. }
  72. }
  73. SaVersionT version = { 'B', 1, 1 };
  74. SaCkptCallbacksT callbacks = {
  75. 0,
  76. 0
  77. };
  78. SaNameT checkpointName = { 5, "abra\0" };
  79. SaCkptCheckpointCreationAttributesT checkpointCreationAttributes = {
  80. .creationFlags = SA_CKPT_WR_ALL_REPLICAS,
  81. .checkpointSize = 250000,
  82. .retentionDuration = 0,
  83. .maxSections = 5,
  84. .maxSectionSize = 250000,
  85. .maxSectionIdSize = 10
  86. };
  87. SaCkptSectionIdT sectionId1 = {
  88. 14,
  89. (SaUint8T *) "section ID #1"
  90. };
  91. SaCkptSectionIdT sectionId2 = {
  92. 14,
  93. (SaUint8T *) "section ID #2"
  94. };
  95. SaCkptSectionCreationAttributesT sectionCreationAttributes1 = {
  96. &sectionId1,
  97. 0xFFFFFFFF
  98. };
  99. SaCkptSectionCreationAttributesT sectionCreationAttributes2 = {
  100. &sectionId2,
  101. 0xFFFFFFFF
  102. };
  103. char readBuffer1[1025];
  104. char readBuffer2[1025];
  105. SaCkptIOVectorElementT ReadVectorElements[] = {
  106. {
  107. {
  108. 14,
  109. (SaUint8T *) "section ID #1"
  110. },
  111. readBuffer1,
  112. sizeof (readBuffer1),
  113. 0,
  114. 0
  115. },
  116. {
  117. {
  118. 14,
  119. (SaUint8T *) "section ID #2"
  120. },
  121. readBuffer2,
  122. sizeof (readBuffer2),
  123. 0,
  124. 0
  125. }
  126. };
  127. #define DATASIZE 200000
  128. #define LOOPS 5000
  129. char data[500000];
  130. SaCkptIOVectorElementT WriteVectorElements[] = {
  131. {
  132. {
  133. 14,
  134. (SaUint8T *) "section ID #1"
  135. },
  136. data, /*"written data #1, this should extend past end of old section data", */
  137. DATASIZE, /*sizeof ("data #1, this should extend past end of old section data") + 1, */
  138. 0, //5,
  139. 0
  140. }
  141. #ifdef COMPILE_OUT
  142. {
  143. {
  144. 14,
  145. (SaUint8T *) "section ID #2"
  146. },
  147. data, /*"written data #2, this should extend past end of old section data" */
  148. DATASIZE, /*sizeof ("written data #2, this should extend past end of old section data") + 1, */
  149. 0, //3,
  150. 0
  151. }
  152. #endif
  153. };
  154. void ckpt_benchmark (SaCkptCheckpointHandleT checkpointHandle,
  155. int write_size)
  156. {
  157. struct timeval tv1, tv2, tv_elapsed;
  158. SaUint32T erroroneousVectorIndex = 0;
  159. SaAisErrorT error;
  160. int write_count = 0;
  161. alarm_notice = 0;
  162. alarm (10);
  163. WriteVectorElements[0].dataSize = write_size;
  164. gettimeofday (&tv1, NULL);
  165. do {
  166. /*
  167. * Test checkpoint write
  168. */
  169. retry:
  170. error = saCkptCheckpointWrite (checkpointHandle,
  171. WriteVectorElements,
  172. 1,
  173. &erroroneousVectorIndex);
  174. if (error == SA_AIS_ERR_TRY_AGAIN) {
  175. goto retry;
  176. }
  177. if (error != SA_AIS_OK) {
  178. printf ("saCkptCheckpointWrite result %d (should be 1)\n", error);
  179. exit (1);
  180. }
  181. write_count += 1;
  182. } while (alarm_notice == 0);
  183. gettimeofday (&tv2, NULL);
  184. timersub (&tv2, &tv1, &tv_elapsed);
  185. printf ("%5d Writes ", write_count);
  186. printf ("%5d bytes per write ", write_size);
  187. printf ("%7.3f Seconds runtime ",
  188. (tv_elapsed.tv_sec + (tv_elapsed.tv_usec / 1000000.0)));
  189. printf ("%9.3f TP/s ",
  190. ((float)write_count) / (tv_elapsed.tv_sec + (tv_elapsed.tv_usec / 1000000.0)));
  191. printf ("%7.3f MB/s.\n",
  192. ((float)write_count) * ((float)write_size) / ((tv_elapsed.tv_sec + (tv_elapsed.tv_usec / 1000000.0)) * 1000000.0));
  193. }
  194. void sigalrm_handler (int num)
  195. {
  196. alarm_notice = 1;
  197. }
  198. int main (void) {
  199. SaCkptHandleT ckptHandle;
  200. SaCkptCheckpointHandleT checkpointHandle;
  201. SaAisErrorT error;
  202. int size;
  203. int i;
  204. signal (SIGALRM, sigalrm_handler);
  205. error = saCkptInitialize (&ckptHandle, &callbacks, &version);
  206. error = saCkptCheckpointOpen (ckptHandle,
  207. &checkpointName,
  208. &checkpointCreationAttributes,
  209. SA_CKPT_CHECKPOINT_CREATE|SA_CKPT_CHECKPOINT_READ|SA_CKPT_CHECKPOINT_WRITE,
  210. 0,
  211. &checkpointHandle);
  212. error = saCkptSectionCreate (checkpointHandle,
  213. &sectionCreationAttributes1,
  214. "Initial Data #0",
  215. strlen ("Initial Data #0") + 1);
  216. error = saCkptSectionCreate (checkpointHandle,
  217. &sectionCreationAttributes2,
  218. "Initial Data #0",
  219. strlen ("Initial Data #0") + 1);
  220. size = 1;
  221. for (i = 0; i < 50; i++) { /* number of repetitions - up to 50k */
  222. ckpt_benchmark (checkpointHandle, size);
  223. size += 1000;
  224. }
  225. error = saCkptFinalize (ckptHandle);
  226. return (0);
  227. }