-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathumpub.c
More file actions
1894 lines (1745 loc) · 61.4 KB
/
umpub.c
File metadata and controls
1894 lines (1745 loc) · 61.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
"umpub.c: application that sends messages to a given topic (multiple sources)
Copyright (c) 2005-2014 Informatica Corporation Permission is granted to licensees to use
or alter this software for any purpose, including commercial applications,
according to the terms laid out in the Software License Agreement.
This source code example is provided by Informatica for educational
and evaluation purposes only.
THE SOFTWARE IS PROVIDED "AS IS" AND INFORMATICA DISCLAIMS ALL WARRANTIES
EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY IMPLIED WARRANTIES OF
NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR
PURPOSE. INFORMATICA DOES NOT WARRANT THAT USE OF THE SOFTWARE WILL BE
UNINTERRUPTED OR ERROR-FREE. INFORMATICA SHALL NOT, UNDER ANY CIRCUMSTANCES, BE
LIABLE TO LICENSEE FOR LOST PROFITS, CONSEQUENTIAL, INCIDENTAL, SPECIAL OR
INDIRECT DAMAGES ARISING OUT OF OR RELATED TO THIS AGREEMENT OR THE
TRANSACTIONS CONTEMPLATED HEREUNDER, EVEN IF INFORMATICA HAS BEEN APPRISED OF
THE LIKELIHOOD OF SUCH DAMAGES.
*/
#ifdef __VOS__
#define _POSIX_C_SOURCE 200112L
#include <sys/time.h>
#endif
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>
#ifdef _WIN32
#include <winsock2.h>
#include <sys/timeb.h>
#define strcasecmp stricmp
#define snprintf _snprintf
#else
#include <unistd.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <signal.h>
#include <sys/time.h>
#if defined(__TANDEM)
#include <strings.h>
#if defined(HAVE_TANDEM_SPT)
#include <ktdmtyp.h>
#include <spthread.h>
#else
#include <pthread.h>
#endif
#else
#include <pthread.h>
#endif
#endif
#include "replgetopt.h"
#include <lbm/lbm.h>
#include <lbm/lbmmon.h>
#include "monmodopts.h"
#include "lbm-example-util.h"
#if !defined(_WIN32)
#include <sys/utsname.h>
#endif
#define UM_PUB_VERSION "0.1"
#if defined(_MSC_VER)
#define TSTLONGLONG LONGLONG
#define TST_LARGE_INT_UNION LARGE_INTEGER
#else
#define TSTLONGLONG signed long long
typedef union {
struct {
unsigned long LowPart; long HighPart;
} u;
TSTLONGLONG QuadPart;
} TST_LARGE_INT_UNION;
#endif
/* high-res time stats at startup */
TST_LARGE_INT_UNION hrt_freq;
TST_LARGE_INT_UNION hrt_start_cnt;
#if defined(_WIN32)
# define SLEEP_SEC(x) Sleep((x)*1000)
# define SLEEP_MSEC(x) Sleep(x)
#else
# define SLEEP_SEC(x) sleep(x)
# define SLEEP_MSEC(x) \
do{\
\
if ((x) >= 1000){\
\
sleep((x) / 1000); \
usleep((x) % 1000 * 1000); \
} \
else{\
\
usleep((x)* 1000); \
} \
} while (0)
#endif /* _WIN32 */
#define MIN_ALLOC_MSGLEN 25
#define DEFAULT_MAX_MESSAGES 10000000
#define DEFAULT_RTT_MESSAGES 1000000
#define MAX_NUM_SRCS 100000
#define MAX_NUM_CTX 101
#define DEFAULT_NUM_SRCS 100
#define DEFAULT_NUM_CTXS 1
#define DEFAULT_NUM_THREADS 1
#define DEFAULT_MSGS_PER_SEC 10000
#define DEFAULT_TOPIC_ROOT "29west.example.multi"
#define DEFAULT_INITIAL_TOPIC_NUMBER 0
#define DEFAULT_MAX_NUM_TRANSPORTS 10
#define DEFAULT_FLIGHT_SZ -1
#define MAX_MESSAGES_INFINITE 0xEFFFFFFF
lbm_event_queue_t *evq = NULL;
lbm_src_t **srcs = NULL;
char *message = NULL;
int stats_timer_id = -1, done_sending = 0, second_timer_id;
lbm_ulong_t stats_sec = 0;
/* Performance Metrics */
int force_reclaim_total = 0;
int is_reg_complete = 1;
int msgs_stabilized = 0;
int naks_Received = 0;
double time_insecs = 0.0;
int test_active = 1;
int msgs_sent_out = 0;
int perf_msgs_sent_out = 0;
int eouldblok_sec = 0;
int msg_length = 0;
int rcv_start_thres = 0;
int rcv_start = 0;
int is_combine_test = 0;
int is_rcvapp_ready = 0;
int num_of_reg_success = 0;
int no_of_dereg_success = 0;
int num_of_reg_comp = 0;
int stop_timer = 0;
int *src_flight_size;
struct timeval *source_registration_tv;
struct timeval src_create_starttv;
struct timeval reclaim_tsp = { 0, 0 };
struct timeval starttv, curtv, endtv, msgstarttv, msgendtv;
double rtt_total = 0.0, rtt_min = 100.0, rtt_max = 0.0, rtt_median = 0.0, rtt_stddev = 0.0, rtt_avg = 0.0;
double *rtt_data = NULL;
int rtts = 0;
int rtt_min_idx = -1;
int rtt_max_idx = -1;
int msg_count = 0;
int stats_use_ump = 0;
int stats_use_umq = 0;
int stats_rtt = 0;
double stab_min_secs = 100.0;
double stab_max_secs = 0.0;
double stab_tot_secs = 0.0;
const char Purpose[] = "Purpose: Send rate-controlled messages on multiple topics.";
const char Usage[] =
"Usage: %s [options]\n"
" Topic names generated as a root, followed by a dot, followed by an integer.\n"
" By default, the first topic created will be '29west.example.multi.0'\n"
"Available options:\n"
" -a, --stability Measure Latency for message stability.\n"
" -c, --config=FILE Use LBM configuration file FILE.\n"
" Multiple config files are allowed.\n"
" Example: '-c file1.cfg -c file2.cfg'\n"
" -C --contexts=NUM use NUM contexts\n"
" -d, --delay=NUM delay sending for NUM seconds after source creation\n"
" -f, --flight-size=NUM allow NUM unstabilized messages in flight (determines message rate)\n"
" -h, --help display this help and exit\n"
" -H, --hf Use hot failover sources\n"
" -i, --initial-topic=NUM use NUM as initial topic number [0]\n"
" -I, --ignore=NUM send and ignore msgs messages to warm up\n"
" -K, --measure-latency Calculate latency based on message payload timestamp. Use twice for round trip latency\n"
" -j, --late-join=NUM enable Late Join with specified retention buffer size (in bytes)\n"
" -l, --length=NUM send messages of length NUM bytes [25]\n"
" -L, --linger=NUM linger for NUM seconds after done [10]\n"
" -m, --message-rate=NUM send at NUM messages per second [10000]\n"
" -M, --messages=NUM send maximum of NUM messages [10000000]\n"
" -p, --print-metrics Print metrics to stdout every N milliseconds\n"
" -n, --non-block use non-blocking I/O\n"
" -r, --root=STRING use topic names with root of STRING [29west.example.multi]\n"
" -R, --rate=[UM]DATA/RETR Set transport type to LBT-R[UM], set data rate limit to\n"
" DATA bits per second, and set retransmit rate limit to\n"
" RETR bits per second. For both limits, the optional\n"
" k, m, and g suffixes may be used. For example,\n"
" '-R 1m/500k' is the same as '-R 1000000/500000'\n"
" -s, --statistics=NUM print stats every NUM seconds\n"
" -S, --sources=NUM use NUM sources [100]\n"
" -t, --tight tight loop (cpu-bound) for even message spacing\n"
" -T, --threads=NUM use NUM threads [1]\n"
" -v, --verbose be verbose about incoming messages\n"
" -x, --bits=NUM use NUM bits for hot failover sequence number size (32 or 64)\n"
MONOPTS_SENDER
MONMODULEOPTS_SENDER;
const char * OptionString = "ac:C:Dd:hHi:I:f:j:l:L:m:M:np:r:R:s:S:tT:vx:K";
#define OPTION_MONITOR_SRC 0
#define OPTION_MONITOR_CTX 1
#define OPTION_MONITOR_TRANSPORT 2
#define OPTION_MONITOR_TRANSPORT_OPTS 3
#define OPTION_MONITOR_FORMAT 4
#define OPTION_MONITOR_FORMAT_OPTS 5
#define OPTION_MONITOR_APPID 6
const struct option OptionTable[] =
{
{ "stability", no_argument, NULL, 'a' },
{ "config", required_argument, NULL, 'c' },
{ "contexts", required_argument, NULL, 'C' },
{ "delay", required_argument, NULL, 'd' },
{ "deregister", no_argument, NULL, 'D' },
{ "help", no_argument, NULL, 'h' },
{ "hf", no_argument, NULL, 'H' },
{ "initial-topic", required_argument, NULL, 'i' },
{ "ignore", required_argument, NULL, 'I' },
{ "flight-size", required_argument, NULL, 'f' },
{ "late-join", required_argument, NULL, 'j' },
{ "length", required_argument, NULL, 'l' },
{ "linger", required_argument, NULL, 'L' },
{ "message-rate", required_argument, NULL, 'm' },
{ "messages", required_argument, NULL, 'M' },
{ "non-block", no_argument, NULL, 'n' },
{ "print-metrics", required_argument, NULL, 'p' },
{ "root", required_argument, NULL, 'r' },
{ "rate", required_argument, NULL, 'R' },
{ "statistics", required_argument, NULL, 's' },
{ "sources", required_argument, NULL, 'S' },
{ "tight", no_argument, NULL, 't' },
{ "threads", required_argument, NULL, 'T' },
{ "verbose", no_argument, NULL, 'v' },
{ "bits", required_argument, NULL, 'x' },
{ "measure-latency", no_argument, NULL, 'K' },
{ "monitor-src", required_argument, NULL, OPTION_MONITOR_SRC },
{ "monitor-ctx", required_argument, NULL, OPTION_MONITOR_CTX },
{ "monitor-transport", required_argument, NULL, OPTION_MONITOR_TRANSPORT },
{ "monitor-transport-opts", required_argument, NULL, OPTION_MONITOR_TRANSPORT_OPTS },
{ "monitor-format", required_argument, NULL, OPTION_MONITOR_FORMAT },
{ "monitor-format-opts", required_argument, NULL, OPTION_MONITOR_FORMAT_OPTS },
{ "monitor-appid", required_argument, NULL, OPTION_MONITOR_APPID },
{ NULL, 0, NULL, 0 }
};
struct Options {
char transport_options_string[1024]; /* Transport Options given to lbmmon_sctl_create() */
char format_options_string[1024]; /* Format Options given to lbmmon_sctl_create() */
char application_id_string[1024]; /* Application ID given to lbmmon_context_monitor() */
int totalmsgsleft; /* Number of messages to be sent */
size_t msglen; /* Length of messages to be sent */
unsigned long int latejoin_threshold; /* Maximum Late Join buffer size, in bytes */
int pause; /* Pause interval between messages */
int delay, linger; /* Interval to linger before and after sending messages */
int block; /* Flag to control whether blocking sends are used */
lbm_uint64_t rm_rate, rm_retrans; /* Rate control values */
lbm_ulong_t stats_sec; /* Interval for dumping statistics */
int verifiable_msgs; /* Flag to control message verification (verifymsg.h) */
int verbose; /* Flag to control program verbosity */
int monitor_context; /* Flag to control context level monitoring */
int monitor_context_ivl; /* Interval for context level monitoring */
int monitor_source; /* Flag to control source level monitoring */
int monitor_source_ivl; /* Interval for source level monitoring */
lbmmon_transport_func_t * transport; /* Function pointer to chosen transport module */
lbmmon_format_func_t * format; /* Function pointer to chosen format module */
char topicroot[80]; /* The topic to be sent on */
int initial_topic_number; /* Topic number to start at xxx.i */
int msgs_per_sec; /* Rate to run sources at */
int num_thrds; /* Number of threads to send on */
int num_srcs; /* Number of soruces to send on */
int tight_loop; /* Use a tight loop algorithm vs sleeping */
char rm_protocol; /* LBTRM or LBTRU protocol */
int hf; /* Use Hot Failover Sources */
int bits; /* HF sequence number bit size, 32 or 64 */
int num_ctx; /* Number of contexts to use*/
int deregister; /* deregister ump sources after sending */
int eventq; /* use event queue */
int flightsz; /* set flight size */
long channel_number; /* The channel (sub-topic) number to use */
int rtt; /* Measure RTT if true */
int rtt_ignore; /* TODO: Ignore this number of messages */
int print_metrics; /* How often to print advanced metrics (milliseconds)*/
int stability; /* Measure stability latency */
};
void print_platform_info()
{
#if defined(__linux__) || defined(Darwin)
struct utsname unm;
if (uname(&unm) == 0)
printf("* %s %s %s %s %s \n", unm.sysname, unm.nodename, unm.release, unm.version, unm.machine);
else
printf("* Could not determine system type\n");
#elif defined(_WIN32)
SYSTEM_INFO sinfo;
OSVERSIONINFO vinfo;
struct utsname unm;
DWORD namelen = sizeof(unm.nodename);
GetSystemInfo(&sinfo);
vinfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
GetVersionEx(&vinfo);
mul_snprintf(unm.sysname, sizeof(unm.sysname), "Windows");
if (vinfo.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS) {
mul_snprintf(unm.release, sizeof(unm.release), "Windows 95/98/Me (%d.%d)", vinfo.dwMajorVersion, vinfo.dwMinorVersion);
} else if (vinfo.dwPlatformId = VER_PLATFORM_WIN32_NT) {
mul_snprintf(unm.release, sizeof(unm.release), "Windows NT %d.%d", vinfo.dwMajorVersion, vinfo.dwMinorVersion);
} else {
mul_snprintf(unm.release, sizeof(unm.release), "Unknown(%d %d.%d)", vinfo.dwPlatformId, vinfo.dwMajorVersion, vinfo.dwMinorVersion);
}
mul_snprintf(unm.version, sizeof(unm.version), "Build %d %s", vinfo.dwBuildNumber, vinfo.szCSDVersion);
switch (sinfo.wProcessorArchitecture) {
case PROCESSOR_ARCHITECTURE_AMD64:
mul_snprintf(unm.machine, sizeof(unm.machine), "x64-%x-%x %dx", sinfo.wProcessorLevel, sinfo.wProcessorRevision, sinfo.dwNumberOfProcessors);
break;
case PROCESSOR_ARCHITECTURE_IA64:
mul_snprintf(unm.machine, sizeof(unm.machine), "IA64-%x-%x %dx", sinfo.wProcessorLevel, sinfo.wProcessorRevision, sinfo.dwNumberOfProcessors);
break;
case PROCESSOR_ARCHITECTURE_INTEL:
mul_snprintf(unm.machine, sizeof(unm.machine), "x86-%x-%x %dx", sinfo.wProcessorLevel, sinfo.wProcessorRevision, sinfo.dwNumberOfProcessors);
break;
default:
mul_snprintf(unm.machine, sizeof(unm.machine), "%x-%x-%x %dx", sinfo.wProcessorArchitecture,
sinfo.wProcessorLevel, sinfo.wProcessorRevision, sinfo.dwNumberOfProcessors);
break;
}
GetComputerName(unm.nodename, &namelen);
printf("* %s %s %s %s %s\n", unm.sysname, unm.nodename, unm.release, unm.version, unm.machine);
#endif /* Linux */
}
struct Options options;
void cur_usec_ofs(TSTLONGLONG *quadp)
{
TST_LARGE_INT_UNION hrt_now_cnt;
static TSTLONGLONG onemillion = 1000000;
#if defined(_MSC_VER)
QueryPerformanceCounter(&hrt_now_cnt);
#else
struct timeval now_tv;
TSTLONGLONG perf_cnt;
gettimeofday(&now_tv, NULL);
perf_cnt = now_tv.tv_sec;
perf_cnt *= 1000000;
perf_cnt += now_tv.tv_usec;
hrt_now_cnt.QuadPart = perf_cnt;
#endif
*quadp = (((hrt_now_cnt.QuadPart - hrt_start_cnt.QuadPart) * onemillion) / hrt_freq.QuadPart);
} /* cur_usec_ofs */
void print_latency(FILE *fp, struct timeval *tv, size_t count)
{
double sec = 0.0, rtt = 0.0, latency = 0.0;
sec = (double)tv->tv_sec + (double)tv->tv_usec / 1000000.0;
printf("sec= %.04g\n", sec);
rtt = (sec/(double)count) * 1000.0;
latency = rtt / 2.0;
fprintf(fp, "Elapsed time %.04g secs. %d messages (RTTs). %.04g msec RTT, %.04g msec latency\n", sec,
(int) count, rtt, latency);
fflush(fp);
}
void print_rtt(FILE *file, struct timeval *tsp, struct timeval *etv)
{
double sec = 0.0;
etv->tv_sec -= tsp->tv_sec;
etv->tv_usec -= tsp->tv_usec;
normalize_tv(etv);
sec = (double)etv->tv_sec + (double)etv->tv_usec / 1000000.0;
//printf("sec= %f\n", sec);
rtt_total += sec;
if (sec < rtt_min) {
rtt_min = sec;
rtt_min_idx = rtts;
}
if (sec >= rtt_max) {
rtt_max = sec;
rtt_max_idx = rtts;
}
if (rtt_data)
rtt_data[rtts] = sec;
rtts++;
/* Only dump data if not collecting */
if (options.verbose) {
fprintf(file, "RTT %.04g msec\n", sec * 1000.0);
fflush(file);
}
}
/* Print RTT summary */
void print_rtt_results(FILE *file)
{
if (rtt_data) {
fprintf(file, "min/max msg = %d/%d median/stddev %.04g/%.04g msec\n",
rtt_min_idx, rtt_max_idx, rtt_median, rtt_stddev);
}
fprintf(file, "%u RTT measurements. ", rtts);
fprintf(file, "RTT min/avg/max = %.04g/%.04g/%.04g ms\n", rtt_min*1000.0, rtt_avg*1000.0, rtt_max*1000.0);
if (rtt_max > 10) /* Reasonableness test */
fprintf(file, "Large RTT detected--perhaps you forgot the '-R' in 'lbmpong -R pong'?\n");
fflush(file);
}
double calc_med()
{
int r, changed;
double t;
/* sort the result set */
do {
changed = 0;
for (r = 0; r < options.totalmsgsleft - 1; r++) {
if (rtt_data[r] > rtt_data[r + 1]) {
t = rtt_data[r];
rtt_data[r] = rtt_data[r + 1];
rtt_data[r + 1] = t;
changed = 1;
}
}
} while (changed);
if (options.totalmsgsleft & 1) {
/* Odd number of data elements - take middle */
return rtt_data[(options.totalmsgsleft / 2) + 1];
}
else {
/* Even number of data element avg the two middle ones */
return (rtt_data[(options.totalmsgsleft / 2)] + rtt_data[(options.totalmsgsleft / 2) + 1]) / 2;
}
}
double calc_stddev(double mean) {
int r;
double sum;
/* Subtract the mean from the data points, square them and sum them */
sum = 0.0;
for (r = 0; r < options.totalmsgsleft; r++) {
rtt_data[r] -= mean;
rtt_data[r] *= rtt_data[r];
sum += rtt_data[r];
}
sum /= (options.totalmsgsleft - 1);
return sqrt(sum);
}
void print_rtt_data(FILE *file)
{
/* If data was collected during the run, dump all the data and the idx of the min and max */
if (rtt_data)
{
int r;
for (r = 0; r < options.totalmsgsleft; r++)
fprintf(file, "RTT %.04g msec, msg %d\n", rtt_data[r] * 1000.0, r);
/* Calculate median and stddev */
rtt_median = calc_med() * 1000.0;
rtt_stddev = calc_stddev(rtt_avg) * 1000.0;
print_rtt_results(file);
fflush(file);
}
}
/* Message handling callback (passed into lbm_rcv_create()) */
int rcv_handle_msg(lbm_rcv_t *rcv, lbm_msg_t *msg, void *clientd)
{
switch (msg->type) {
case LBM_MSG_DATA:
//should be if RTT
if (options.rtt) {
stats_rtt = 1;
current_tv(&msgendtv);
memcpy(&msgstarttv, msg->data, sizeof(msgstarttv));
print_rtt(stdout, &msgstarttv, &msgendtv);
msg_count++;
rtt_avg = (rtt_total / (double)rtts);
if (msg_count == options.totalmsgsleft) {
/* Send data to stderr so it can be redirected separately */
print_rtt_data(stderr);
exit(0);
}
}
else if (options.rtt) {
/* Return timestamp message */
memcpy(message, msg->data, options.msglen);
}
break;
case LBM_MSG_BOS:
printf("[%s][%s], Beginning of Transport Session\n", msg->topic_name, msg->source);
break;
case LBM_MSG_EOS:
printf("[%s][%s], End of Transport Session\n", msg->topic_name, msg->source);
break;
case LBM_MSG_UNRECOVERABLE_LOSS:
printf("[%s][%s][%u], LOST\n", msg->topic_name, msg->source, msg->sequence_number);
/* Any kind of loss makes this test invalid */
fprintf(stderr, "Unrecoverable loss occurred. Quitting...\n");
exit(1);
break;
case LBM_MSG_UNRECOVERABLE_LOSS_BURST:
printf("[%s][%s][%u], LOST BURST\n", msg->topic_name, msg->source, msg->sequence_number);
/* Any kind of loss makes this test invalid */
fprintf(stderr, "Unrecoverable loss occurred. Quitting...\n");
exit(1);
break;
case LBM_MSG_UME_REGISTRATION_SUCCESS_EX:
case LBM_MSG_UME_REGISTRATION_COMPLETE_EX:
case LBM_MSG_UMQ_REGISTRATION_COMPLETE_EX:
/* Provided to enable quiet usage of lbmstrm with UME */
break;
default:
printf("Unknown lbm_msg_t type %x [%s][%s]\n", msg->type, msg->topic_name, msg->source);
break;
}
/* LBM automatically deletes the lbm_msg_t object unless we retain it. */
return 0;
}
int print_reg_stats()
{
char buff[1048] = { '\0' };
double time_in_seconds = 0.0;
double total_time = 0.0;
double min_time = 1000.0;
double max_time = -1.0;
char time_stats_buff[256];
int i = 0;
if (num_of_reg_success < options.num_srcs)
{
sprintf(time_stats_buff, "Error, not enough registrations completed\n");
}
else {
/* Calculate Registration Timestamps Max/Avg */
for (i = 0; i < options.num_srcs; i++) {
source_registration_tv[i].tv_sec -= src_create_starttv.tv_sec;
source_registration_tv[i].tv_usec -= src_create_starttv.tv_usec;
normalize_tv(&source_registration_tv[i]);
time_in_seconds = (double)source_registration_tv[i].tv_sec + (double)source_registration_tv[i].tv_usec / 1000000.0;
if (time_in_seconds < min_time) {
min_time = time_in_seconds;
}
if (time_in_seconds > max_time) {
max_time = time_in_seconds;
}
total_time += time_in_seconds;
sprintf(time_stats_buff, "Min/Avg/Max: %f/%f/%f sec", min_time, total_time / num_of_reg_comp, max_time);
}
}
sprintf(buff, "-----------------------------------------------------------------------------\n"
"Registration Statistics: "
"Reg Success[%d] "
"Reg Complete[%d]\n"
"Registration time statistics: %s\n"
"-----------------------------------------------------------------------------\n",
num_of_reg_success,
num_of_reg_comp,
time_stats_buff
);
printf("%s", buff);
return 0;
}
int increment_insecs(lbm_context_t *ctx, const void *clientd)
{
lbm_context_t **ctx_array = (lbm_context_t **)clientd;
if (test_active) //TODO: Figure out where this is set in umeperfstream
{
current_tv(&curtv);
curtv.tv_sec -= starttv.tv_sec;
curtv.tv_usec -= starttv.tv_usec;
normalize_tv(&curtv);
time_insecs = (double)curtv.tv_sec + (double)curtv.tv_usec / 1000000.0;
}
if ((second_timer_id = lbm_schedule_timer(ctx, increment_insecs, (void *)clientd, NULL, options.print_metrics)) == -1){
fprintf(stderr, "lbm_schedule_timer: %s\n", lbm_errmsg());
exit(1);
}
print_perf_stats(ctx_array);
return 0;
}
void getTotalNaks(lbm_context_t *ctx)
{
lbm_src_transport_stats_t stats[DEFAULT_MAX_NUM_TRANSPORTS];
int num_transports = DEFAULT_MAX_NUM_TRANSPORTS;
if (lbm_context_retrieve_src_transport_stats(ctx, &num_transports, stats) != LBM_FAILURE) {
naks_Received += stats->transport.lbtrm.naks_rcved;
}
}
int print_perf_stats(lbm_context_t **ctx_array)
{
char buff[1048] = { '\0' };
int temp_Average_Message = 0;
int temp_eouldblok_sec = 0;
static double last_time_insec = 0.0;
static int last_perf_msgs_sent_out = 0;
static int last_eouldblok_sec = 0;
int i = 0;
int total_flight = 0, max_flight = -1, min_flight = 1000000;
if (time_insecs > 0.01)
{
temp_Average_Message = (int)(((double)(perf_msgs_sent_out - last_perf_msgs_sent_out))/ (time_insecs - last_time_insec));
temp_eouldblok_sec = (int)(((double)(eouldblok_sec - last_eouldblok_sec)) / (time_insecs - last_time_insec));
}
else
{
temp_Average_Message = perf_msgs_sent_out;
temp_eouldblok_sec = eouldblok_sec;
}
// Reset Counters for next iteration
last_time_insec = time_insecs;
last_perf_msgs_sent_out = perf_msgs_sent_out;
last_eouldblok_sec = eouldblok_sec;
naks_Received = 0;
//accumulate all context nak stats
for (i = 0; i < MAX_NUM_CTX; i++)
{
if (ctx_array[i] != NULL)
getTotalNaks(ctx_array[i]);
}
for (i = 0; i < options.num_srcs; i++) {
total_flight+=src_flight_size[i];
if (src_flight_size[i] > max_flight)
max_flight = src_flight_size[i];
if (src_flight_size[i] < min_flight)
min_flight = src_flight_size[i];
}
printf("Msgs/Second[%6d]", temp_Average_Message);
if (stats_rtt)
printf(" Latency Min/Avg/Max[%.06f/%.06f/%.06f]", rtt_min, rtt_avg, rtt_max);
if (stats_use_ump)
printf(" Msgs Stable[%6d] Flight Size Min/Avg/Max[%4d/%4d/%4d]", msgs_stabilized, min_flight, (total_flight / options.num_srcs), max_flight);
if (force_reclaim_total > 0)
printf(" Forced Reclaims[%d]", force_reclaim_total);
if (temp_eouldblok_sec > 0)
printf(" NAKs[%d]", naks_Received);
if (naks_Received > 0)
printf(" EWOULDBLOCKS / Second[%d]", temp_eouldblok_sec);
if (options.stability)
printf("\n Stability Latency Min/Avg/Max[%.06f/%.06f/%.06f]", stab_min_secs, stab_tot_secs/msgs_stabilized, stab_max_secs);
printf("\n");
}
void print_final_test_results()
{
double stab_per = 0.0;
printf("------------\n");
printf("Test Results\n");
printf("------------\n");
printf(" Seconds Elapsed: %.04g\n", time_insecs);
stab_per = (100 * msgs_stabilized) / perf_msgs_sent_out;
printf(" Messages Published: %i\n", perf_msgs_sent_out);
printf(" Stability Percentage: %.04g%%\n", stab_per);
//print_perf_stats();
}
int handle_force_reclaim(const char *topic, lbm_uint_t sqn, void *clientd)
{
struct timeval *tsp = (struct timeval *)clientd;
struct timeval endtv, nowtv;
double secs = 0;
if (tsp == NULL)
fprintf(stderr, "WARNING: source for topic \"%s\" forced reclaim %x\n", topic, sqn);
else {
current_tv(&endtv);
endtv.tv_sec -= tsp->tv_sec;
endtv.tv_usec -= tsp->tv_usec;
normalize_tv(&endtv);
secs = (double)endtv.tv_sec + (double)endtv.tv_usec / 1000000.0;
force_reclaim_total++;
if (secs > 5.0) {
fprintf(stderr, "WARNING: source for topic \"%s\" forced reclaim. Total %d.\n", topic, force_reclaim_total);
current_tv(&nowtv);
memcpy(tsp, &nowtv, sizeof(nowtv));
}
}
return 0;
}
int handle_src_event(lbm_src_t *src, int event, void *ed, void *cd)
{
struct Options *opts = &options;
int src_index = *((int*)cd);
switch (event) {
case LBM_SRC_EVENT_CONNECT:
{
const char *clientname = (const char *)ed;
printf("Receiver connect [%s]\n", clientname);
break;
}
case LBM_SRC_EVENT_DISCONNECT:
{
const char *clientname = (const char *)ed;
printf("Receiver disconnect [%s]\n", clientname);
break;
}
case LBM_SRC_EVENT_WAKEUP:
break;
case LBM_SRC_EVENT_SEQUENCE_NUMBER_INFO:
{
lbm_src_event_sequence_number_info_t *info = (lbm_src_event_sequence_number_info_t *)ed;
if (info->first_sequence_number != info->last_sequence_number)
printf("SQN [%x,%x] (cd %p)\n", info->first_sequence_number, info->last_sequence_number, (char*)(info->msg_clientd) - 1);
else
printf("SQN %x (cd %p)\n", info->last_sequence_number, (char*)(info->msg_clientd) - 1);
}
break;
case LBM_SRC_EVENT_UME_REGISTRATION_ERROR:
{
const char *errstr = (const char *)ed;
printf("Error registering source with UME store: %s\n", errstr);
}
break;
case LBM_SRC_EVENT_UME_REGISTRATION_SUCCESS:
{
int i, semval;
lbm_src_event_ume_registration_t *reg = (lbm_src_event_ume_registration_t *)ed;
}
break;
case LBM_SRC_EVENT_UME_REGISTRATION_SUCCESS_EX:
{
lbm_src_event_ume_registration_ex_t *reg = (lbm_src_event_ume_registration_ex_t *)ed;
num_of_reg_success++;
stats_use_ump = 1;
if (opts->verbose) {
printf("UME store %u: %s registration success. RegID %u. Flags %x ", reg->store_index, reg->store, reg->registration_id, reg->flags);
if (reg->flags & LBM_SRC_EVENT_UME_REGISTRATION_SUCCESS_EX_FLAG_OLD)
printf("OLD[SQN %x] ", reg->sequence_number);
if (reg->flags & LBM_SRC_EVENT_UME_REGISTRATION_SUCCESS_EX_FLAG_NOACKS)
printf("NOACKS ");
printf("\n");
}
}
break;
case LBM_SRC_EVENT_UME_DEREGISTRATION_SUCCESS_EX:
{
lbm_src_event_ume_registration_ex_t *reg = (lbm_src_event_ume_registration_ex_t *)ed;
no_of_dereg_success++;
if (opts->verbose) {
printf("UME store %u: %s de-registration success. RegID %u. Flags %x ", reg->store_index, reg->store, reg->registration_id, reg->flags);
if (reg->flags & LBM_SRC_EVENT_UME_REGISTRATION_SUCCESS_EX_FLAG_OLD)
printf("OLD[SQN %x] ", reg->sequence_number);
if (reg->flags & LBM_SRC_EVENT_UME_REGISTRATION_SUCCESS_EX_FLAG_NOACKS)
printf("NOACKS ");
printf("\n");
}
}
break;
case LBM_SRC_EVENT_UME_DEREGISTRATION_COMPLETE_EX:
{
if (opts->verbose)
printf("UME DEREGISTRATION IS COMPLETE\n");
}
break;
case LBM_SRC_EVENT_UME_REGISTRATION_COMPLETE_EX:
{
int i, semval;
lbm_src_event_ume_registration_complete_ex_t *reg = (lbm_src_event_ume_registration_complete_ex_t *)ed;
is_reg_complete = 0;
num_of_reg_comp++;
stop_timer = 1;
current_tv(&source_registration_tv[src_index]);
if (opts->verbose) {
printf("UME registration complete. SQN %x. Flags %x ", reg->sequence_number, reg->flags);
if (reg->flags & LBM_SRC_EVENT_UME_REGISTRATION_COMPLETE_EX_FLAG_QUORUM)
printf("QUORUM ");
printf("\n");
}
}
break;
case LBM_SRC_EVENT_UME_STORE_UNRESPONSIVE:
{
const char *infostr = (const char *)ed;
if (opts->verbose)
printf("UME store (STORE_UNRESPONSIVE): %s\n", infostr);
}
break;
case LBM_SRC_EVENT_UME_MESSAGE_STABLE:
{
int i, semval;
lbm_src_event_ume_ack_info_t *ackinfo = (lbm_src_event_ume_ack_info_t *)ed;
if (opts->verbose)
printf("UME message stable - sequence number %x (cd %p)\n", ackinfo->sequence_number, (char*)(ackinfo->msg_clientd) - 1);
}
break;
case LBM_SRC_EVENT_UME_MESSAGE_STABLE_EX:
{
int i, semval;
struct timeval *stab_latency_tv;
struct timeval now;
lbm_src_event_ume_ack_ex_info_t *info = (lbm_src_event_ume_ack_ex_info_t *)ed;
if (opts->stability && info->msg_clientd != NULL)
{
float time_secs = 0.0;
stab_latency_tv = (struct timeval*)info->msg_clientd;
current_tv(&now);
now.tv_sec -= stab_latency_tv->tv_sec;
now.tv_usec -= stab_latency_tv->tv_usec;
normalize_tv(&now);
time_secs = (double)now.tv_sec + (double)now.tv_usec / 1000000.0;
if (time_secs < stab_min_secs)
stab_min_secs = time_secs;
if (time_secs > stab_max_secs)
stab_max_secs = time_secs;
stab_tot_secs += time_secs;
free(stab_latency_tv);
}
msgs_stabilized++;
if (opts->verbose) {
if (info->flags & LBM_SRC_EVENT_UME_MESSAGE_STABLE_EX_FLAG_STORE) {
printf("UME store %u: %s message stable. SQN %x (cd %p). Flags 0x%x ", info->store_index, info->store,
info->sequence_number, info->msg_clientd, info->flags);
}
else {
printf("UME message stable. SQN %x (cd %p). Flags 0x%x ",
info->sequence_number, info->msg_clientd, info->flags);
}
if (info->flags & LBM_SRC_EVENT_UME_MESSAGE_STABLE_EX_FLAG_INTRAGROUP_STABLE)
printf("IA ");
if (info->flags & LBM_SRC_EVENT_UME_MESSAGE_STABLE_EX_FLAG_INTERGROUP_STABLE)
printf("IR ");
if (info->flags & LBM_SRC_EVENT_UME_MESSAGE_STABLE_EX_FLAG_STABLE)
printf("STABLE ");
if (info->flags & LBM_SRC_EVENT_UME_MESSAGE_STABLE_EX_FLAG_STORE)
printf("STORE ");
if (info->flags & LBM_SRC_EVENT_UME_MESSAGE_STABLE_EX_FLAG_WHOLE_MESSAGE_STABLE)
printf("MESSAGE");
printf("\n");
}
}
break;
case LBM_SRC_EVENT_UME_DELIVERY_CONFIRMATION:
{
lbm_src_event_ume_ack_info_t *ackinfo = (lbm_src_event_ume_ack_info_t *)ed;
if (opts->verbose)
printf("UME delivery confirmation - sequence number %x, Rcv RegID %u (cd %p)\n", ackinfo->sequence_number, ackinfo->rcv_registration_id, (char*)(ackinfo->msg_clientd) - 1);
}
break;
case LBM_SRC_EVENT_UME_DELIVERY_CONFIRMATION_EX:
{
lbm_src_event_ume_ack_ex_info_t *info = (lbm_src_event_ume_ack_ex_info_t *)ed;
if (opts->verbose) {
printf("UME delivery confirmation. SQN %x, RcvRegID %u (cd %p). Flags 0x%x ",
info->sequence_number, info->rcv_registration_id, (char*)(info->msg_clientd) - 1, info->flags);
if (info->flags & LBM_SRC_EVENT_UME_DELIVERY_CONFIRMATION_EX_FLAG_UNIQUEACKS)
printf("UNIQUEACKS ");
if (info->flags & LBM_SRC_EVENT_UME_DELIVERY_CONFIRMATION_EX_FLAG_UREGID)
printf("UREGID ");
if (info->flags & LBM_SRC_EVENT_UME_DELIVERY_CONFIRMATION_EX_FLAG_OOD)
printf("OOD ");
if (info->flags & LBM_SRC_EVENT_UME_DELIVERY_CONFIRMATION_EX_FLAG_EXACK)
printf("EXACK ");
if (info->flags & LBM_SRC_EVENT_UME_DELIVERY_CONFIRMATION_EX_FLAG_WHOLE_MESSAGE_CONFIRMED)
printf("MESSAGE");
printf("\n");
}
}
break;
case LBM_SRC_EVENT_UME_MESSAGE_RECLAIMED:
{
lbm_src_event_ume_ack_info_t *ackinfo = (lbm_src_event_ume_ack_info_t *)ed;
printf("UME message reclaimed - sequence number %x (cd %p)\n", ackinfo->sequence_number, (char*)(ackinfo->msg_clientd) - 1);
}
break;
case LBM_SRC_EVENT_UME_MESSAGE_RECLAIMED_EX:
{
lbm_src_event_ume_ack_ex_info_t *ackinfo = (lbm_src_event_ume_ack_ex_info_t *)ed;
if (opts->verbose) {
printf("UME message reclaimed (ex) - sequence number %x (cd %p). Flags 0x%x ",
ackinfo->sequence_number, (char*)(ackinfo->msg_clientd) - 1, ackinfo->flags);
if (ackinfo->flags & LBM_SRC_EVENT_UME_MESSAGE_RECLAIMED_EX_FLAG_FORCED)
printf("FORCED");
printf("\n");
}
}
break;
case LBM_SRC_EVENT_UME_MESSAGE_NOT_STABLE:
{
lbm_src_event_ume_ack_ex_info_t *info = (lbm_src_event_ume_ack_ex_info_t *)ed;
if (opts->verbose) {
if (info->flags & LBM_SRC_EVENT_UME_MESSAGE_NOT_STABLE_FLAG_STORE) {
printf("UME store %u: %s message NOT stable!! SQN %x (cd %p). Flags 0x%x ", info->store_index, info->store,
info->sequence_number, info->msg_clientd, info->flags);
}
else {
printf("UME message NOT stable!! SQN %x (cd %p). Flags 0x%x ",
info->sequence_number, info->msg_clientd, info->flags);
}
printf("\n");
}
}
break;
case LBM_SRC_EVENT_FLIGHT_SIZE_NOTIFICATION:
{
lbm_src_event_flight_size_notification_t *fsnote = (lbm_src_event_flight_size_notification_t *)ed;
if (opts->verbose) {
printf("Flight Size Notification. Type ");
switch (fsnote->type) {
case LBM_SRC_EVENT_FLIGHT_SIZE_NOTIFICATION_TYPE_UME:
printf("UME");
break;
case LBM_SRC_EVENT_FLIGHT_SIZE_NOTIFICATION_TYPE_ULB:
printf("ULB");
break;
case LBM_SRC_EVENT_FLIGHT_SIZE_NOTIFICATION_TYPE_UMQ:
printf("UMQ");
break;
default:
printf("unknown");
break;
}
printf(". Inflight is %s specified flight size\n",
fsnote->state == LBM_SRC_EVENT_FLIGHT_SIZE_NOTIFICATION_STATE_OVER ? "OVER" : "UNDER");
}
}
break;
default:
printf("Unknown source event %d\n", event);
break;
}
return 0;
}
/* Print transport statistics */
void print_stats(FILE *fp, lbm_src_transport_stats_t *stats)
{
fprintf(fp, "[%s]", stats->source);
switch (stats->type) {
case LBM_TRANSPORT_STAT_TCP:
fprintf(fp, " buffered %lu, clients %lu\n", stats->transport.tcp.bytes_buffered,
stats->transport.tcp.num_clients);
break;
case LBM_TRANSPORT_STAT_LBTRM:
fprintf(fp, " sent %lu/%lu, txw %lu/%lu, naks %lu/%lu, ignored %lu/%lu, shed %lu, rxs %lu, rctlr %lu/%lu\n",
stats->transport.lbtrm.msgs_sent, stats->transport.lbtrm.bytes_sent,
stats->transport.lbtrm.txw_msgs, stats->transport.lbtrm.txw_bytes,
stats->transport.lbtrm.naks_rcved, stats->transport.lbtrm.nak_pckts_rcved,
stats->transport.lbtrm.naks_ignored, stats->transport.lbtrm.naks_rx_delay_ignored,
stats->transport.lbtrm.naks_shed,
stats->transport.lbtrm.rxs_sent,
stats->transport.lbtrm.rctlr_data_msgs, stats->transport.lbtrm.rctlr_rx_msgs);
break;
case LBM_TRANSPORT_STAT_LBTRU:
fprintf(fp, " clients %lu, sent %lu/%lu, naks %lu/%lu, ignored %lu/%lu, shed %lu, rxs %lu\n",
stats->transport.lbtru.num_clients,
stats->transport.lbtru.msgs_sent, stats->transport.lbtru.bytes_sent,
stats->transport.lbtru.naks_rcved, stats->transport.lbtru.nak_pckts_rcved,
stats->transport.lbtru.naks_ignored, stats->transport.lbtru.naks_rx_delay_ignored,
stats->transport.lbtru.naks_shed,
stats->transport.lbtru.rxs_sent);
break;
case LBM_TRANSPORT_STAT_LBTIPC:
fprintf(fp, " clients %lu, sent %lu/%lu\n",
stats->transport.lbtipc.num_clients,
stats->transport.lbtipc.msgs_sent, stats->transport.lbtipc.bytes_sent);
break;
case LBM_TRANSPORT_STAT_LBTSMX:
fprintf(fp, " clients %lu, sent %lu/%lu\n",
stats->transport.lbtsmx.num_clients,
stats->transport.lbtsmx.msgs_sent, stats->transport.lbtsmx.bytes_sent);
break;