ckptbench.c 6.0 KB

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