ckptbenchth.c 7.1 KB

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