ckptbench.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. #define _BSD_SOURCE
  2. /*
  3. * Copyright (c) 2002-2004 MontaVista Software, Inc.
  4. *
  5. * All rights reserved.
  6. *
  7. * Author: Steven Dake (sdake@mvista.com)
  8. *
  9. * This software licensed under BSD license, the text of which follows:
  10. *
  11. * Redistribution and use in source and binary forms, with or without
  12. * modification, are permitted provided that the following conditions are met:
  13. *
  14. * - Redistributions of source code must retain the above copyright notice,
  15. * this list of conditions and the following disclaimer.
  16. * - Redistributions in binary form must reproduce the above copyright notice,
  17. * this list of conditions and the following disclaimer in the documentation
  18. * and/or other materials provided with the distribution.
  19. * - Neither the name of the MontaVista Software, Inc. nor the names of its
  20. * contributors may be used to endorse or promote products derived from this
  21. * software without specific prior written permission.
  22. *
  23. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  24. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  25. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  26. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  27. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  28. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  29. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  30. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  31. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  32. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  33. * THE POSSIBILITY OF SUCH DAMAGE.
  34. */
  35. #include <stdio.h>
  36. #include <stdlib.h>
  37. #include <string.h>
  38. #include <signal.h>
  39. #include <unistd.h>
  40. #include <errno.h>
  41. #include <unistd.h>
  42. #include <time.h>
  43. #include <sys/time.h>
  44. #include <sys/types.h>
  45. #include <sys/socket.h>
  46. #include <sys/select.h>
  47. #include <sys/un.h>
  48. #include <sys/socket.h>
  49. #include <netinet/in.h>
  50. #include <arpa/inet.h>
  51. #include "saAis.h"
  52. #include "saCkpt.h"
  53. int alarm_notice;
  54. void printSaNameT (SaNameT *name)
  55. {
  56. int i;
  57. for (i = 0; i < name->length; i++) {
  58. printf ("%c", name->value[i]);
  59. }
  60. }
  61. SaVersionT version = { 'B', 1, 1 };
  62. SaCkptCallbacksT callbacks = {
  63. 0,
  64. 0
  65. };
  66. SaNameT checkpointName = { 5, "abra\0" };
  67. SaCkptCheckpointCreationAttributesT checkpointCreationAttributes = {
  68. .creationFlags = SA_CKPT_WR_ALL_REPLICAS,
  69. .checkpointSize = 250000,
  70. .retentionDuration = 0,
  71. .maxSections = 5,
  72. .maxSectionSize = 250000,
  73. .maxSectionIdSize = 10
  74. };
  75. SaCkptSectionIdT sectionId1 = {
  76. 14,
  77. (SaUint8T *) "section ID #1"
  78. };
  79. SaCkptSectionIdT sectionId2 = {
  80. 14,
  81. (SaUint8T *) "section ID #2"
  82. };
  83. SaCkptSectionCreationAttributesT sectionCreationAttributes1 = {
  84. &sectionId1,
  85. 0xFFFFFFFF
  86. };
  87. SaCkptSectionCreationAttributesT sectionCreationAttributes2 = {
  88. &sectionId2,
  89. 0xFFFFFFFF
  90. };
  91. char readBuffer1[1025];
  92. char readBuffer2[1025];
  93. SaCkptIOVectorElementT ReadVectorElements[] = {
  94. {
  95. {
  96. 14,
  97. (SaUint8T *) "section ID #1"
  98. },
  99. readBuffer1,
  100. sizeof (readBuffer1),
  101. 0,
  102. 0
  103. },
  104. {
  105. {
  106. 14,
  107. (SaUint8T *) "section ID #2"
  108. },
  109. readBuffer2,
  110. sizeof (readBuffer2),
  111. 0,
  112. 0
  113. }
  114. };
  115. #define DATASIZE 200000
  116. #define LOOPS 5000
  117. char data[500000];
  118. SaCkptIOVectorElementT WriteVectorElements[] = {
  119. {
  120. {
  121. 14,
  122. (SaUint8T *) "section ID #1"
  123. },
  124. data, /*"written data #1, this should extend past end of old section data", */
  125. DATASIZE, /*sizeof ("data #1, this should extend past end of old section data") + 1, */
  126. 0, //5,
  127. 0
  128. }
  129. #ifdef COMPILE_OUT
  130. {
  131. {
  132. 14,
  133. (SaUint8T *) "section ID #2"
  134. },
  135. data, /*"written data #2, this should extend past end of old section data" */
  136. DATASIZE, /*sizeof ("written data #2, this should extend past end of old section data") + 1, */
  137. 0, //3,
  138. 0
  139. }
  140. #endif
  141. };
  142. void ckpt_benchmark (SaCkptCheckpointHandleT checkpointHandle,
  143. int write_size)
  144. {
  145. struct timeval tv1, tv2, tv_elapsed;
  146. SaUint32T erroroneousVectorIndex = 0;
  147. SaAisErrorT error;
  148. int write_count = 0;
  149. alarm_notice = 0;
  150. alarm (10);
  151. WriteVectorElements[0].dataSize = write_size;
  152. gettimeofday (&tv1, NULL);
  153. do {
  154. /*
  155. * Test checkpoint write
  156. */
  157. retry:
  158. error = saCkptCheckpointWrite (checkpointHandle,
  159. WriteVectorElements,
  160. 1,
  161. &erroroneousVectorIndex);
  162. if (error == SA_AIS_ERR_TRY_AGAIN) {
  163. goto retry;
  164. }
  165. if (error != SA_AIS_OK) {
  166. printf ("saCkptCheckpointWrite result %d (should be 1)\n", error);
  167. exit (1);
  168. }
  169. write_count += 1;
  170. } while (alarm_notice == 0);
  171. gettimeofday (&tv2, NULL);
  172. timersub (&tv2, &tv1, &tv_elapsed);
  173. printf ("%5d Writes ", write_count);
  174. printf ("%5d bytes per write ", write_size);
  175. printf ("%7.3f Seconds runtime ",
  176. (tv_elapsed.tv_sec + (tv_elapsed.tv_usec / 1000000.0)));
  177. printf ("%9.3f TP/s ",
  178. ((float)write_count) / (tv_elapsed.tv_sec + (tv_elapsed.tv_usec / 1000000.0)));
  179. printf ("%7.3f MB/s.\n",
  180. ((float)write_count) * ((float)write_size) / ((tv_elapsed.tv_sec + (tv_elapsed.tv_usec / 1000000.0)) * 1000000.0));
  181. }
  182. void sigalrm_handler (int num)
  183. {
  184. alarm_notice = 1;
  185. }
  186. int main (void) {
  187. SaCkptHandleT ckptHandle;
  188. SaCkptCheckpointHandleT checkpointHandle;
  189. SaAisErrorT error;
  190. int size;
  191. int i;
  192. signal (SIGALRM, sigalrm_handler);
  193. error = saCkptInitialize (&ckptHandle, &callbacks, &version);
  194. error = saCkptCheckpointOpen (ckptHandle,
  195. &checkpointName,
  196. &checkpointCreationAttributes,
  197. SA_CKPT_CHECKPOINT_CREATE|SA_CKPT_CHECKPOINT_READ|SA_CKPT_CHECKPOINT_WRITE,
  198. 0,
  199. &checkpointHandle);
  200. error = saCkptSectionCreate (checkpointHandle,
  201. &sectionCreationAttributes1,
  202. "Initial Data #0",
  203. strlen ("Initial Data #0") + 1);
  204. error = saCkptSectionCreate (checkpointHandle,
  205. &sectionCreationAttributes2,
  206. "Initial Data #0",
  207. strlen ("Initial Data #0") + 1);
  208. size = 1;
  209. for (i = 0; i < 50; i++) { /* number of repetitions - up to 50k */
  210. ckpt_benchmark (checkpointHandle, size);
  211. size += 1000;
  212. }
  213. error = saCkptFinalize (ckptHandle);
  214. return (0);
  215. }