ckptbenchth.c 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  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 <pthread.h>
  46. #include "ais_types.h"
  47. #include "ais_ckpt.h"
  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. SaCkptCheckpointCreationAttributesT checkpointCreationAttributes = {
  57. SA_CKPT_WR_ALL_REPLICAS,
  58. 100000,
  59. 0,
  60. 5,
  61. 20000,
  62. 10
  63. };
  64. SaCkptSectionIdT sectionId1 = {
  65. "section ID #1",
  66. 14
  67. };
  68. SaCkptSectionIdT sectionId2 = {
  69. "section ID #2",
  70. 14
  71. };
  72. SaCkptSectionCreationAttributesT sectionCreationAttributes1 = {
  73. &sectionId1,
  74. 0xFFFFFFFF
  75. };
  76. SaCkptSectionCreationAttributesT sectionCreationAttributes2 = {
  77. &sectionId2,
  78. 0xFFFFFFFF
  79. };
  80. char readBuffer1[1025];
  81. char readBuffer2[1025];
  82. SaCkptIOVectorElementT ReadVectorElements[] = {
  83. {
  84. {
  85. "section ID #1",
  86. 14
  87. },
  88. readBuffer1,
  89. sizeof (readBuffer1),
  90. 0,
  91. 0
  92. },
  93. {
  94. {
  95. "section ID #2",
  96. 14
  97. },
  98. readBuffer2,
  99. sizeof (readBuffer2),
  100. 0,
  101. 0
  102. }
  103. };
  104. #define DATASIZE 1000
  105. #define LOOPS 5000
  106. char data[500000];
  107. SaCkptIOVectorElementT WriteVectorElements[] = {
  108. {
  109. {
  110. "section ID #1",
  111. 14
  112. },
  113. data, /*"written data #1, this should extend past end of old section data", */
  114. DATASIZE, /*sizeof ("data #1, this should extend past end of old section data") + 1, */
  115. 0, //5,
  116. 0
  117. }
  118. #ifdef COMPILE_OUT
  119. {
  120. {
  121. "section ID #2",
  122. 14
  123. },
  124. data, /*"written data #2, this should extend past end of old section data" */
  125. DATASIZE, /*sizeof ("written data #2, this should extend past end of old section data") + 1, */
  126. 0, //3,
  127. 0
  128. }
  129. #endif
  130. };
  131. int runs = 0;
  132. struct threaddata {
  133. SaCkptCheckpointHandleT checkpointHandle;
  134. int write_count;
  135. int write_size;
  136. };
  137. void *benchmark_thread (void *arg)
  138. {
  139. SaCkptCheckpointHandleT checkpointHandle;
  140. int write_count;
  141. int write_size;
  142. SaErrorT error;
  143. SaUint32T erroroneousVectorIndex = 0;
  144. struct threaddata *td = (struct threaddata *)arg;
  145. int ckptinv;
  146. checkpointHandle = td->checkpointHandle;
  147. write_count = td->write_count;
  148. write_size = td->write_size;
  149. WriteVectorElements[0].dataSize = write_size;
  150. for (ckptinv = 0; ckptinv < write_count; ckptinv++) {
  151. /*
  152. * Test checkpoint write
  153. */
  154. error = saCkptCheckpointWrite (&checkpointHandle,
  155. WriteVectorElements,
  156. 1,
  157. &erroroneousVectorIndex);
  158. if (error != SA_OK) {
  159. printf ("saCkptCheckpointWrite result %d (should be 1)\n", error);
  160. exit (1);
  161. }
  162. }
  163. pthread_exit (0);
  164. }
  165. void threaded_bench (SaCkptCheckpointHandleT *checkpointHandles, int threads, int write_count,
  166. int write_size)
  167. {
  168. struct timeval tv1, tv2, tv_elapsed;
  169. struct threaddata td[100];
  170. int i;
  171. pthread_t threadt[100];
  172. int res;
  173. runs = threads;
  174. gettimeofday (&tv1, NULL);
  175. for (i = 0; i < threads; i++) {
  176. td[i].checkpointHandle = checkpointHandles[i];
  177. td[i].write_count = write_count;
  178. td[i].write_size = write_size;
  179. res = pthread_create (&threadt[i], NULL, benchmark_thread, (void *)&td[i]);
  180. }
  181. for (i = 0; i < threads; i++) {
  182. pthread_join (threadt[i], NULL);
  183. }
  184. gettimeofday (&tv2, NULL);
  185. timersub (&tv2, &tv1, &tv_elapsed);
  186. printf ("%5d Writes ", write_count * threads);
  187. printf ("%5d bytes per write ", write_size);
  188. printf ("%7.3f Seconds runtime ",
  189. (tv_elapsed.tv_sec + (tv_elapsed.tv_usec / 1000000.0)));
  190. printf ("%9.3f TP/s ",
  191. ((float)write_count * (float)threads) / (tv_elapsed.tv_sec + (tv_elapsed.tv_usec / 1000000.0)));
  192. printf ("%7.3f MB/s.\n",
  193. ((float)write_count * (float)threads) * ((float)write_size) / ((tv_elapsed.tv_sec + (tv_elapsed.tv_usec / 1000000.0)) * 1000000.0));
  194. }
  195. SaNameT checkpointName = { 12, "abra\0" };
  196. int main (void) {
  197. SaCkptCheckpointHandleT checkpointHandles[50];
  198. SaErrorT error;
  199. int size;
  200. int count;
  201. int i, j;
  202. /*
  203. * Create 50 checkpoints
  204. */
  205. for (i = 0; i < 50; i++) {
  206. sprintf (checkpointName.value, "checkpoint%d \n", i);
  207. error = saCkptCheckpointOpen (&checkpointName,
  208. &checkpointCreationAttributes,
  209. SA_CKPT_CHECKPOINT_READ|SA_CKPT_CHECKPOINT_WRITE,
  210. 0,
  211. &checkpointHandles[i]);
  212. error = saCkptSectionCreate (&checkpointHandles[i],
  213. &sectionCreationAttributes1,
  214. "Initial Data #0",
  215. strlen ("Initial Data #0") + 1);
  216. error = saCkptSectionCreate (&checkpointHandles[i],
  217. &sectionCreationAttributes2,
  218. "Initial Data #0",
  219. strlen ("Initial Data #0") + 1);
  220. }
  221. for (i = 1; i < 50; i++) { /* i threads */
  222. count = 3000; /* initial count */
  223. size = 1000; /* initial size */
  224. printf ("THREADS %d\n", i);
  225. for (j = 0; j < 5; j++) { /* number of runs with i threads */
  226. threaded_bench (checkpointHandles, i, count, size);
  227. /*
  228. * Adjust count to 95% of previous count
  229. * adjust size upwards by 1500
  230. * This keeps the run times similiar
  231. */
  232. count = (((float)count) * 0.95);
  233. size += 1500;
  234. }
  235. }
  236. return (0);
  237. }