ckptbenchth.c 7.4 KB

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