ckptbenchth.c 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  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 <string.h>
  38. #include <errno.h>
  39. #include <unistd.h>
  40. #include <time.h>
  41. #include <sys/time.h>
  42. #include <sys/types.h>
  43. #include <sys/socket.h>
  44. #include <sys/select.h>
  45. #include <sys/un.h>
  46. #include <pthread.h>
  47. #include <assert.h>
  48. #include "saAis.h"
  49. #include "saCkpt.h"
  50. void printSaNameT (SaNameT *name)
  51. {
  52. int i;
  53. for (i = 0; i < name->length; i++) {
  54. printf ("%c", name->value[i]);
  55. }
  56. }
  57. SaVersionT version = { 'B', 1, 1 };
  58. SaCkptCallbacksT callbacks = {
  59. 0,
  60. 0
  61. };
  62. SaCkptCheckpointCreationAttributesT checkpointCreationAttributes = {
  63. .creationFlags = SA_CKPT_WR_ALL_REPLICAS,
  64. .checkpointSize = 100000,
  65. .retentionDuration = 0,
  66. .maxSections = 5,
  67. .maxSectionSize = 150000,
  68. .maxSectionIdSize = 10
  69. };
  70. SaCkptSectionIdT sectionId1 = {
  71. 14,
  72. (SaUint8T *) "section ID #1"
  73. };
  74. SaCkptSectionIdT sectionId2 = {
  75. 14,
  76. (SaUint8T *) "section ID #2"
  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. 14,
  92. (SaUint8T *) "section ID #1"
  93. },
  94. readBuffer1,
  95. sizeof (readBuffer1),
  96. 0,
  97. 0
  98. },
  99. {
  100. {
  101. 14,
  102. (SaUint8T *) "section ID #2"
  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. 14,
  117. (SaUint8T *) "section ID #1"
  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. 14,
  128. (SaUint8T *) "section ID #2"
  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. int runs = 0;
  138. struct threaddata {
  139. SaCkptHandleT ckptHandle;
  140. SaCkptCheckpointHandleT checkpointHandle;
  141. int write_count;
  142. int write_size;
  143. int thread;
  144. };
  145. void *benchmark_thread (void *arg)
  146. {
  147. SaCkptCheckpointHandleT checkpointHandle;
  148. SaCkptHandleT ckptHandle;
  149. int write_count;
  150. int write_size;
  151. SaAisErrorT error;
  152. SaUint32T erroroneousVectorIndex = 0;
  153. struct threaddata *td = (struct threaddata *)arg;
  154. int ckptinv;
  155. checkpointHandle = td->checkpointHandle;
  156. ckptHandle = td->ckptHandle;
  157. write_count = td->write_count;
  158. write_size = td->write_size;
  159. WriteVectorElements[0].dataSize = write_size;
  160. for (ckptinv = 0; ckptinv < write_count; ckptinv++) {
  161. /*
  162. * Test checkpoint write
  163. */
  164. do {
  165. error = saCkptCheckpointWrite (checkpointHandle,
  166. WriteVectorElements,
  167. 1,
  168. &erroroneousVectorIndex);
  169. } while (error == SA_AIS_ERR_TRY_AGAIN);
  170. if (error != SA_AIS_OK) {
  171. printf ("saCkptCheckpointWrite result %d (should be 1)\n", error);
  172. exit (1);
  173. }
  174. }
  175. pthread_exit (0);
  176. }
  177. void threaded_bench (SaCkptHandleT *ckptHandles, SaCkptCheckpointHandleT *checkpointHandles,
  178. int threads, int write_count, int write_size)
  179. {
  180. struct timeval tv1, tv2, tv_elapsed;
  181. struct threaddata td[100];
  182. int i;
  183. pthread_t threadt[100];
  184. int res;
  185. runs = threads;
  186. gettimeofday (&tv1, NULL);
  187. for (i = 0; i < threads; i++) {
  188. td[i].ckptHandle = ckptHandles[i];
  189. td[i].checkpointHandle = checkpointHandles[i];
  190. td[i].write_count = write_count;
  191. td[i].write_size = write_size;
  192. td[i].thread = i;
  193. res = pthread_create (&threadt[i], NULL, benchmark_thread, (void *)&td[i]);
  194. }
  195. for (i = 0; i < threads; i++) {
  196. pthread_join (threadt[i], NULL);
  197. }
  198. gettimeofday (&tv2, NULL);
  199. timersub (&tv2, &tv1, &tv_elapsed);
  200. printf ("%5d Writes ", write_count * threads);
  201. printf ("%5d bytes per write ", write_size);
  202. printf ("%7.3f Seconds runtime ",
  203. (tv_elapsed.tv_sec + (tv_elapsed.tv_usec / 1000000.0)));
  204. printf ("%9.3f TP/s ",
  205. ((float)write_count * (float)threads) / (tv_elapsed.tv_sec + (tv_elapsed.tv_usec / 1000000.0)));
  206. printf ("%7.3f MB/s.\n",
  207. ((float)write_count * (float)threads) * ((float)write_size) / ((tv_elapsed.tv_sec + (tv_elapsed.tv_usec / 1000000.0)) * 1000000.0));
  208. }
  209. SaNameT checkpointName = { 12, "abra\0" };
  210. #define CHECKPOINT_THREADS 50
  211. int main (void) {
  212. SaCkptHandleT ckptHandles[500];
  213. SaCkptCheckpointHandleT checkpointHandles[500];
  214. SaAisErrorT error;
  215. int size;
  216. int count;
  217. int i, j;
  218. /*
  219. * Create CHECPOINT_THREADS checkpoints
  220. */
  221. for (i = 0; i < CHECKPOINT_THREADS; i++) {
  222. sprintf ((char *)checkpointName.value, "checkpoint%d \n", i);
  223. error = saCkptInitialize (&ckptHandles[i], &callbacks, &version);
  224. assert (error == SA_AIS_OK);
  225. error = saCkptCheckpointOpen (ckptHandles[i],
  226. &checkpointName,
  227. &checkpointCreationAttributes,
  228. SA_CKPT_CHECKPOINT_CREATE|SA_CKPT_CHECKPOINT_READ|SA_CKPT_CHECKPOINT_WRITE,
  229. SA_TIME_END,
  230. &checkpointHandles[i]);
  231. assert (error == SA_AIS_OK);
  232. error = saCkptSectionCreate (checkpointHandles[i],
  233. &sectionCreationAttributes1,
  234. "Initial Data #0",
  235. strlen ("Initial Data #0") + 1);
  236. assert (error == SA_AIS_OK);
  237. error = saCkptSectionCreate (checkpointHandles[i],
  238. &sectionCreationAttributes2,
  239. "Initial Data #0",
  240. strlen ("Initial Data #0") + 1);
  241. assert (error == SA_AIS_OK);
  242. }
  243. for (i = 25; i < CHECKPOINT_THREADS; i++) { /* i threads */
  244. count = 3000; /* initial write count */
  245. size = 10000; /* initial size */
  246. printf ("THREADS %d\n", i);
  247. for (j = 0; j < 5; j++) { /* number of runs with i threads */
  248. threaded_bench (ckptHandles, checkpointHandles, i, count, size);
  249. /*
  250. * Adjust count to 95% of previous count
  251. * adjust size upwards by 1500
  252. * This keeps the run times similiar
  253. */
  254. count = (((float)count) * 0.95);
  255. size += 1000;
  256. }
  257. }
  258. return (0);
  259. }