ckptbench.c 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  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. #include "sa_error.h"
  55. #ifdef OPENAIS_SOLARIS
  56. #define timersub(a, b, result) \
  57. do { \
  58. (result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \
  59. (result)->tv_usec = (a)->tv_usec - (b)->tv_usec; \
  60. if ((result)->tv_usec < 0) { \
  61. --(result)->tv_sec; \
  62. (result)->tv_usec += 1000000; \
  63. } \
  64. } while (0)
  65. #endif
  66. int alarm_notice;
  67. void fail_on_error(SaAisErrorT error, char* opName) {
  68. if (error != SA_AIS_OK) {
  69. printf ("%s: result %s\n", opName, get_sa_error_b(error));
  70. exit (1);
  71. }
  72. }
  73. void printSaNameT (SaNameT *name)
  74. {
  75. int i;
  76. for (i = 0; i < name->length; i++) {
  77. printf ("%c", name->value[i]);
  78. }
  79. }
  80. SaVersionT version = { 'B', 1, 1 };
  81. SaCkptCallbacksT callbacks = {
  82. 0,
  83. 0
  84. };
  85. SaNameT checkpointName = { 5, "abra\0" };
  86. SaCkptCheckpointCreationAttributesT checkpointCreationAttributes = {
  87. .creationFlags = SA_CKPT_WR_ALL_REPLICAS,
  88. .checkpointSize = 250000,
  89. .retentionDuration = 0,
  90. .maxSections = 5,
  91. .maxSectionSize = 250000,
  92. .maxSectionIdSize = 15
  93. };
  94. SaCkptSectionIdT sectionId1 = {
  95. 14,
  96. (SaUint8T *) "section ID #1"
  97. };
  98. SaCkptSectionIdT sectionId2 = {
  99. 14,
  100. (SaUint8T *) "section ID #2"
  101. };
  102. SaCkptSectionCreationAttributesT sectionCreationAttributes1 = {
  103. &sectionId1,
  104. 0xFFFFFFFF
  105. };
  106. SaCkptSectionCreationAttributesT sectionCreationAttributes2 = {
  107. &sectionId2,
  108. 0xFFFFFFFF
  109. };
  110. char readBuffer1[1025];
  111. char readBuffer2[1025];
  112. SaCkptIOVectorElementT ReadVectorElements[] = {
  113. {
  114. {
  115. 14,
  116. (SaUint8T *) "section ID #1"
  117. },
  118. readBuffer1,
  119. sizeof (readBuffer1),
  120. 0,
  121. 0
  122. },
  123. {
  124. {
  125. 14,
  126. (SaUint8T *) "section ID #2"
  127. },
  128. readBuffer2,
  129. sizeof (readBuffer2),
  130. 0,
  131. 0
  132. }
  133. };
  134. #define DATASIZE 200000
  135. #define LOOPS 5000
  136. char data[500000];
  137. SaCkptIOVectorElementT WriteVectorElements[] = {
  138. {
  139. {
  140. 14,
  141. (SaUint8T *) "section ID #1"
  142. },
  143. data, /*"written data #1, this should extend past end of old section data", */
  144. DATASIZE, /*sizeof ("data #1, this should extend past end of old section data") + 1, */
  145. 0, //5,
  146. 0
  147. }
  148. #ifdef COMPILE_OUT
  149. {
  150. {
  151. 14,
  152. (SaUint8T *) "section ID #2"
  153. },
  154. data, /*"written data #2, this should extend past end of old section data" */
  155. DATASIZE, /*sizeof ("written data #2, this should extend past end of old section data") + 1, */
  156. 0, //3,
  157. 0
  158. }
  159. #endif
  160. };
  161. void ckpt_benchmark (SaCkptCheckpointHandleT checkpointHandle,
  162. int write_size)
  163. {
  164. struct timeval tv1, tv2, tv_elapsed;
  165. SaUint32T erroroneousVectorIndex = 0;
  166. SaAisErrorT error;
  167. int write_count = 0;
  168. alarm_notice = 0;
  169. alarm (10);
  170. WriteVectorElements[0].dataSize = write_size;
  171. gettimeofday (&tv1, NULL);
  172. do {
  173. /*
  174. * Test checkpoint write
  175. */
  176. retry:
  177. error = saCkptCheckpointWrite (checkpointHandle,
  178. WriteVectorElements,
  179. 1,
  180. &erroroneousVectorIndex);
  181. if (error == SA_AIS_ERR_TRY_AGAIN) {
  182. goto retry;
  183. }
  184. fail_on_error(error, "saCkptCheckpointWrite");
  185. write_count += 1;
  186. } while (alarm_notice == 0);
  187. gettimeofday (&tv2, NULL);
  188. timersub (&tv2, &tv1, &tv_elapsed);
  189. printf ("%5d Writes ", write_count);
  190. printf ("%5d bytes per write ", write_size);
  191. printf ("%7.3f Seconds runtime ",
  192. (tv_elapsed.tv_sec + (tv_elapsed.tv_usec / 1000000.0)));
  193. printf ("%9.3f TP/s ",
  194. ((float)write_count) / (tv_elapsed.tv_sec + (tv_elapsed.tv_usec / 1000000.0)));
  195. printf ("%7.3f MB/s.\n",
  196. ((float)write_count) * ((float)write_size) / ((tv_elapsed.tv_sec + (tv_elapsed.tv_usec / 1000000.0)) * 1000000.0));
  197. }
  198. void sigalrm_handler (int num)
  199. {
  200. alarm_notice = 1;
  201. }
  202. int main (void) {
  203. SaCkptHandleT ckptHandle;
  204. SaCkptCheckpointHandleT checkpointHandle;
  205. SaAisErrorT error;
  206. int size;
  207. int i;
  208. signal (SIGALRM, sigalrm_handler);
  209. error = saCkptInitialize (&ckptHandle, &callbacks, &version);
  210. fail_on_error(error, "saCkptInitialize");
  211. error = saCkptCheckpointOpen (ckptHandle,
  212. &checkpointName,
  213. &checkpointCreationAttributes,
  214. SA_CKPT_CHECKPOINT_CREATE|SA_CKPT_CHECKPOINT_READ|SA_CKPT_CHECKPOINT_WRITE,
  215. 0,
  216. &checkpointHandle);
  217. fail_on_error(error, "saCkptCheckpointOpen");
  218. error = saCkptSectionCreate (checkpointHandle,
  219. &sectionCreationAttributes1,
  220. "Initial Data #0",
  221. strlen ("Initial Data #0") + 1);
  222. fail_on_error(error, "saCkptCheckpointSectionCreate");
  223. error = saCkptSectionCreate (checkpointHandle,
  224. &sectionCreationAttributes2,
  225. "Initial Data #0",
  226. strlen ("Initial Data #0") + 1);
  227. fail_on_error(error, "saCkptCheckpointSectionCreate");
  228. size = 1;
  229. for (i = 0; i < 50; i++) { /* number of repetitions - up to 50k */
  230. ckpt_benchmark (checkpointHandle, size);
  231. size += 1000;
  232. }
  233. error = saCkptFinalize (ckptHandle);
  234. return (0);
  235. }