ckptbench.c 5.3 KB

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