ckptbench.c 5.4 KB

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