Back to home page

Enduro/X

 
 

    


0001 /**
0002  * @brief Basic test client
0003  *
0004  * @file atmiclt48_bench.c
0005  */
0006 /* -----------------------------------------------------------------------------
0007  * Enduro/X Middleware Platform for Distributed Transaction Processing
0008  * Copyright (C) 2009-2016, ATR Baltic, Ltd. All Rights Reserved.
0009  * Copyright (C) 2017-2023, Mavimax, Ltd. All Rights Reserved.
0010  * This software is released under one of the following licenses:
0011  * AGPL (with Java and Go exceptions) or Mavimax's license for commercial use.
0012  * See LICENSE file for full text.
0013  * -----------------------------------------------------------------------------
0014  * AGPL license:
0015  *
0016  * This program is free software; you can redistribute it and/or modify it under
0017  * the terms of the GNU Affero General Public License, version 3 as published
0018  * by the Free Software Foundation;
0019  *
0020  * This program is distributed in the hope that it will be useful, but WITHOUT ANY
0021  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
0022  * PARTICULAR PURPOSE. See the GNU Affero General Public License, version 3
0023  * for more details.
0024  *
0025  * You should have received a copy of the GNU Affero General Public License along 
0026  * with this program; if not, write to the Free Software Foundation, Inc.,
0027  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
0028  *
0029  * -----------------------------------------------------------------------------
0030  * A commercial use license is available from Mavimax, Ltd
0031  * contact@mavimax.com
0032  * -----------------------------------------------------------------------------
0033  */
0034 #include <string.h>
0035 #include <stdio.h>
0036 #include <stdlib.h>
0037 #include <memory.h>
0038 #include <math.h>
0039 
0040 #include <atmi.h>
0041 #include <ubf.h>
0042 #include <ndebug.h>
0043 #include <test.fd.h>
0044 #include <ndrstandard.h>
0045 #include <nstopwatch.h>
0046 #include <fcntl.h>
0047 #include <unistd.h>
0048 
0049 #include <nstdutil.h>
0050 /*---------------------------Externs------------------------------------*/
0051 /*---------------------------Macros-------------------------------------*/
0052 /*---------------------------Enums--------------------------------------*/
0053 /*---------------------------Typedefs-----------------------------------*/
0054 /*---------------------------Globals------------------------------------*/
0055 /*---------------------------Statics------------------------------------*/
0056 /*---------------------------Prototypes---------------------------------*/
0057 
0058 /*
0059  * Do the test call to the server
0060  */
0061 int main(int argc, char** argv) {
0062 
0063     UBFH *p_ub = (UBFH *)tpalloc("UBF", NULL, 156000);
0064     long rsplen;
0065     int i, j;
0066     int ret=EXSUCCEED;
0067     double d;
0068     double cps;
0069     char bench_mode[16]=":0:1:8:";
0070     char buf[1024];
0071     char test_buf_carray[56*1024];
0072     char test_buf_small[1024];
0073     ndrx_stopwatch_t timer;
0074     int call_num = MAX_ASYNC_CALLS *10;
0075     short callnum_s;
0076     int bench_call_num;
0077     short warm_up=0;
0078     int first = EXTRUE;
0079     /* Load cache definitions... */
0080     tpinit(NULL);
0081     
0082     /*start with 1 byte, then with 1 kb, then +4 kb up till 56... */
0083     for (j=0; j<56; j+=(j==0?1:4))
0084     {
0085         int callsz = j*1024;
0086         if (0==j)
0087         {
0088             callsz = 1; /* send 1 byte.. */
0089         }
0090 
0091 warmed_up:
0092         if (EXSUCCEED!=Bchg(p_ub, T_SHORT_FLD, 0, (char *)&warm_up, 0L))
0093         {
0094             NDRX_LOG(log_error, "TESTERROR: Failed to set T_SHORT_FLD to %d: %s",
0095                     callsz, Bstrerror(Berror));
0096             EXFAIL_OUT(ret);
0097         }
0098 
0099         if (EXSUCCEED!=Bchg(p_ub, T_CARRAY_FLD, 0, test_buf_carray, callsz))
0100         {
0101             NDRX_LOG(log_error, "TESTERROR: Failed to set T_CARRAY_FLD to %d: %s",
0102                     callsz, Bstrerror(Berror));
0103             EXFAIL_OUT(ret);
0104         }
0105 
0106         if (j<10)
0107         {
0108             bench_call_num = call_num*2;
0109         }
0110         else
0111         {
0112             bench_call_num = call_num;
0113         }
0114 
0115         ndrx_stopwatch_reset(&timer);
0116 
0117         /* Do the loop call! */
0118         for (i=0; i<bench_call_num; i++) /* Test the cd loop */
0119         {
0120             /*
0121             * Test the case when some data should be returned
0122             */
0123             if (EXFAIL==tpcall("BENCH48", (char *)p_ub, 0L, (char **)&p_ub, 
0124                     &rsplen, TPNOTIME))
0125             {
0126                 NDRX_LOG(log_error, "TESTERROR: BENCH48 failed: %s", tpstrerror(tperrno));
0127                 ret=EXFAIL;
0128                 goto out;
0129             }
0130         }
0131 
0132         d = (double)(sizeof(test_buf_carray)*(call_num))/(double)((double)
0133                 ndrx_stopwatch_get_delta(&timer)/1000.0f);
0134 
0135         cps = (double)(bench_call_num)/((double)ndrx_stopwatch_get_delta(&timer)/1000.0f);
0136 
0137         printf("%dKB Performance: %d bytes in %ld (sec) = %lf bytes/sec = %lf "
0138                 "bytes/MB sec, calls/sec = %lf\n", 
0139                 callsz,
0140                 (int)(sizeof(test_buf_carray)*(call_num)), 
0141                 (long)ndrx_stopwatch_get_delta_sec(&timer),  
0142                 d,
0143                 (d/1024)/1024, 
0144                 cps);
0145 
0146         fflush(stdout);
0147 
0148         warm_up++;
0149 
0150         if (first)
0151         {
0152             first = EXFALSE;
0153             goto warmed_up;
0154         }
0155 
0156 
0157         /* first loop goes for warmup... */
0158 
0159         if (EXSUCCEED!=ndrx_bench_write_stats((double)j, cps))
0160         {
0161             NDRX_LOG(log_always, "Failed to write stats!");
0162             EXFAIL_OUT(ret);
0163         }
0164 
0165         
0166     }
0167     
0168 out:
0169     tpterm();
0170 
0171     return ret;
0172 }
0173 
0174 /* vim: set ts=4 sw=4 et smartindent: */