ckptbenchth.c 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  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. int thread;
  137. };
  138. void *benchmark_thread (void *arg)
  139. {
  140. SaCkptCheckpointHandleT checkpointHandle;
  141. int write_count;
  142. int write_size;
  143. SaErrorT error;
  144. SaUint32T erroroneousVectorIndex = 0;
  145. struct threaddata *td = (struct threaddata *)arg;
  146. int ckptinv;
  147. checkpointHandle = td->checkpointHandle;
  148. write_count = td->write_count;
  149. write_size = td->write_size;
  150. WriteVectorElements[0].dataSize = write_size;
  151. for (ckptinv = 0; ckptinv < write_count; ckptinv++) {
  152. /*
  153. * Test checkpoint write
  154. */
  155. do {
  156. error = saCkptCheckpointWrite (&checkpointHandle,
  157. WriteVectorElements,
  158. 1,
  159. &erroroneousVectorIndex);
  160. // if (error == SA_ERR_TRY_AGAIN) {
  161. // usleep (rand() % 500);
  162. // }
  163. } while (error == SA_ERR_TRY_AGAIN);
  164. printf ("done writing for thread %d\n", td->thread);
  165. if (error != SA_OK) {
  166. printf ("saCkptCheckpointWrite result %d (should be 1)\n", error);
  167. exit (1);
  168. }
  169. }
  170. pthread_exit (0);
  171. }
  172. void threaded_bench (SaCkptCheckpointHandleT *checkpointHandles, int threads, int write_count,
  173. int write_size)
  174. {
  175. struct timeval tv1, tv2, tv_elapsed;
  176. struct threaddata td[100];
  177. int i;
  178. pthread_t threadt[100];
  179. int res;
  180. runs = threads;
  181. gettimeofday (&tv1, NULL);
  182. for (i = 0; i < threads; i++) {
  183. td[i].checkpointHandle = checkpointHandles[i];
  184. td[i].write_count = write_count;
  185. td[i].write_size = write_size;
  186. td[i].thread = i;
  187. res = pthread_create (&threadt[i], NULL, benchmark_thread, (void *)&td[i]);
  188. }
  189. for (i = 0; i < threads; i++) {
  190. pthread_join (threadt[i], NULL);
  191. }
  192. gettimeofday (&tv2, NULL);
  193. timersub (&tv2, &tv1, &tv_elapsed);
  194. printf ("%5d Writes ", write_count * threads);
  195. printf ("%5d bytes per write ", write_size);
  196. printf ("%7.3f Seconds runtime ",
  197. (tv_elapsed.tv_sec + (tv_elapsed.tv_usec / 1000000.0)));
  198. printf ("%9.3f TP/s ",
  199. ((float)write_count * (float)threads) / (tv_elapsed.tv_sec + (tv_elapsed.tv_usec / 1000000.0)));
  200. printf ("%7.3f MB/s.\n",
  201. ((float)write_count * (float)threads) * ((float)write_size) / ((tv_elapsed.tv_sec + (tv_elapsed.tv_usec / 1000000.0)) * 1000000.0));
  202. }
  203. SaNameT checkpointName = { 12, "abra\0" };
  204. #define CHECKPOINT_THREADS 500
  205. int main (void) {
  206. SaCkptCheckpointHandleT checkpointHandles[500];
  207. SaErrorT error;
  208. int size;
  209. int count;
  210. int i, j;
  211. /*
  212. * Create CHECPOINT_THREADS checkpoints
  213. */
  214. for (i = 0; i < CHECKPOINT_THREADS; i++) {
  215. sprintf (checkpointName.value, "checkpoint%d \n", i);
  216. error = saCkptCheckpointOpen (&checkpointName,
  217. &checkpointCreationAttributes,
  218. SA_CKPT_CHECKPOINT_READ|SA_CKPT_CHECKPOINT_WRITE,
  219. 0,
  220. &checkpointHandles[i]);
  221. error = saCkptSectionCreate (&checkpointHandles[i],
  222. &sectionCreationAttributes1,
  223. "Initial Data #0",
  224. strlen ("Initial Data #0") + 1);
  225. error = saCkptSectionCreate (&checkpointHandles[i],
  226. &sectionCreationAttributes2,
  227. "Initial Data #0",
  228. strlen ("Initial Data #0") + 1);
  229. }
  230. for (i = CHECKPOINT_THREADS-50; i < CHECKPOINT_THREADS; i++) { /* i threads */
  231. count = 3000; /* initial count */
  232. size = 100000; /* initial size */
  233. printf ("THREADS %d\n", i);
  234. for (j = 0; j < 5; j++) { /* number of runs with i threads */
  235. threaded_bench (checkpointHandles, i, count, size);
  236. /*
  237. * Adjust count to 95% of previous count
  238. * adjust size upwards by 1500
  239. * This keeps the run times similiar
  240. */
  241. count = (((float)count) * 0.95);
  242. size += 1500;
  243. }
  244. }
  245. return (0);
  246. }