pulzr 0.3.2

A http load testing tool for performance testing.
Documentation
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
# Pulzr ⚡

[![Rust](https://img.shields.io/badge/rust-%23000000.svg?style=for-the-badge&logo=rust&logoColor=white)](https://www.rust-lang.org/)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg?style=for-the-badge)](https://opensource.org/licenses/MIT)
[![GitHub release](https://img.shields.io/github/v/release/arnonsang/pulzr?style=for-the-badge)](https://github.com/arnonsang/pulzr/releases)
[![GitHub stars](https://img.shields.io/github/stars/arnonsang/pulzr?style=for-the-badge)](https://github.com/arnonsang/pulzr/stargazers)
[![Build Status](https://img.shields.io/github/actions/workflow/status/arnonsang/pulzr/ci.yml?branch=main&style=for-the-badge)](https://github.com/arnonsang/pulzr/actions)

High-performance HTTP load testing tool written in Rust with real-time metrics, TUI, and WebUI.


> ⚠️**Note:** This is a my rust practice project I put together in just 2 days to explore a use case of my own.
> I’m still pretty new to Rust, but I’ve really loved it since my first try!
>
> The code isn’t production-ready, but I’ve done my best to follow good practices where I can.
>
> If you find any issues or have suggestions, feel free to open an issue or pull request — I’d really appreciate it!


![Pulzr WebUI Monitor](assets/screenshot.png)


## Key Features

- **Fast & Concurrent**: Multi-threaded load testing with configurable concurrency
- **WebSocket Streaming**: Real-time metrics broadcasting for external integrations
- **curl-Compatible Flags**: `-X`, `--data`, `--no-follow-redirects` for familiar syntax
- **Retry Support**: Automatic retry of failed requests with `--retry`
- **Warmup Period**: Discard early results with `--warmup` before recording stats
- **Response Validation**: Fail requests that don't contain expected body text with `--expect-body`
- **CI/CD Integration**: `--json-output`, `--output-file`, `--fail-on-error-rate` for pipeline use
- **Baseline Comparison**: Save and compare test runs to catch regressions with `--save-baseline` / `--compare-baseline`
- **Configurable Alerts**: Override error rate and latency thresholds with `--alert-error-rate` / `--alert-latency`
- **User-Agent Management**: Custom, random, or file-based User-Agent rotation (25+ built-in agents)
- **Rate Limiting**: Precise RPS control with token bucket algorithm
- **CSV Export**: Detailed request logs and aggregated summary reports
- **Flexible HTTP**: Support for all HTTP methods, custom headers, JSON/form payloads
- **Scenario Testing**: JSON/YAML config files for complex multi-step tests
- **Ramp-up Patterns**: Gradual load increase with linear, exponential, or step patterns
- **Multiple Endpoints**: Test different APIs simultaneously with weighted distribution
- **Debug Mode**: Detailed request/response logging with 3 verbosity levels
- **Authentication**: JWT tokens with auto-refresh and API key support
- **Prometheus Export**: Standard metrics endpoint for monitoring integrations
- **Memory Optimization**: Streaming stats with bounded memory usage for long tests
- **HTTP/2 Support**: Modern protocol with multiplexing and header compression
- **Distributed Load Testing**: Scale tests across multiple machines with coordinator-worker architecture

## Installation

### From Cargo (Recommended)
```bash
cargo install pulzr
```

### Quick Install Script
```bash
curl -fsSL https://raw.githubusercontent.com/arnonsang/pulzr/main/install.sh | bash
```

### From Source
```bash
git clone https://github.com/arnonsang/pulzr.git
cd pulzr
cargo install --path .
```

### From GitHub Releases
Download pre-compiled binaries from [GitHub Releases](https://github.com/arnonsang/pulzr/releases)

**Available platforms:**
- Linux x86_64 (amd64)
- Windows x86_64 (amd64)
- macOS x86_64 (amd64)
- macOS ARM64 (Apple Silicon)

**Note for ARM64 Linux users:** Pre-compiled binaries are not available for ARM64 Linux. Please build from source using the instructions above.


## Quick Start

### Basic Load Test (TUI Mode)
```bash
# Run until manually stopped (Ctrl+C or 'q')
pulzr https://httpbin.org/get -c 10

# Run for specific duration
pulzr https://httpbin.org/get -c 10 -d 30

# Run for specific number of requests
pulzr https://httpbin.org/get -c 10 -n 500
```

### WebUI Mode (Recommended)
```bash
# Clean web interface - run until stopped
pulzr https://httpbin.org/get --webui --open-browser -c 10

# WebUI with specific duration
pulzr https://httpbin.org/get --webui --open-browser -c 10 -d 30

# Request count mode - run exactly 1000 requests
pulzr https://httpbin.org/get --webui --open-browser -c 10 -n 1000
```

## Table of Contents

- [Pulzr ⚡]#pulzr-
  - [Key Features]#key-features
  - [Installation]#installation
    - [Quick Install (Recommended)]#quick-install-recommended
    - [From Source]#from-source
    - [From GitHub Releases]#from-github-releases
  - [Quick Start]#quick-start
    - [Basic Load Test (TUI Mode)]#basic-load-test-tui-mode
    - [WebUI Mode (Recommended)]#webui-mode-recommended
  - [Table of Contents]#table-of-contents
  - [Usage Examples]#usage-examples
    - [WebUI Testing]#webui-testing
    - [TUI Testing]#tui-testing
    - [HTTP Methods \& Payloads](#http-methods--payloads)
    - [Data Export \& Analysis](#data-export--analysis)
    - [Specialized Testing]#specialized-testing
    - [Performance Testing]#performance-testing
    - [Scenario-Based Testing]#scenario-based-testing
    - [Ramp-up Load Testing]#ramp-up-load-testing
    - [Multiple Endpoints Testing]#multiple-endpoints-testing
    - [Integration Testing]#integration-testing
    - [CI/CD Integration]#cicd-integration
    - [Distributed Load Testing]#distributed-load-testing
    - [Command Line Options]#command-line-options
  - [Output Formats]#output-formats
    - [Available Formats]#available-formats
    - [Output Format Examples]#output-format-examples
      - [Detailed Format (Default)]#detailed-format-default
      - [Compact Format]#compact-format
      - [Minimal Format]#minimal-format
      - [Quiet Mode]#quiet-mode
    - [Compatible CLI Syntax]#compatible-cli-syntax
    - [Alternative Output Formats]#alternative-output-formats
    - [Output Control Options]#output-control-options
    - [Migration Examples]#migration-examples
  - [Scenario Files]#scenario-files
    - [Features]#features
    - [Example JSON Scenario]#example-json-scenario
    - [Example YAML Scenario]#example-yaml-scenario
    - [Scenario Usage]#scenario-usage
    - [Scenario Configuration]#scenario-configuration
    - [Step Configuration]#step-configuration
    - [Variable Substitution]#variable-substitution
    - [Weighted Distribution]#weighted-distribution
  - [Ramp-up Patterns]#ramp-up-patterns
    - [Features]#features-1
    - [Ramp-up Patterns]#ramp-up-patterns-1
      - [1. **Linear Pattern** (`--ramp-pattern linear`)]#1-linear-pattern---ramp-pattern-linear
      - [2. **Exponential Pattern** (`--ramp-pattern exponential`)]#2-exponential-pattern---ramp-pattern-exponential
      - [3. **Step Pattern** (`--ramp-pattern step`)]#3-step-pattern---ramp-pattern-step
    - [Ramp-up Usage Examples]#ramp-up-usage-examples
    - [Ramp-up Configuration]#ramp-up-configuration
    - [Ramp-up Behavior]#ramp-up-behavior
    - [Best Practices]#best-practices
  - [Multiple Endpoints]#multiple-endpoints
    - [Features]#features-2
    - [Example Endpoints Configuration]#example-endpoints-configuration
      - [JSON Format:]#json-format
    - [Multiple Endpoints Usage]#multiple-endpoints-usage
    - [Endpoint Configuration]#endpoint-configuration
    - [Weighted Distribution]#weighted-distribution-1
    - [Use Cases]#use-cases
      - [**Microservices Testing**:]#microservices-testing
      - [**API Gateway Load Testing**:]#api-gateway-load-testing
      - [**CI/CD Integration Testing**:]#cicd-integration-testing
      - [**Capacity Planning**:]#capacity-planning
    - [Best Practices]#best-practices-1
  - [Debug Mode]#debug-mode
    - [Features]#features-3
    - [Debug Levels]#debug-levels
      - [**Level 1: Basic** (`--debug-level 1`)]#level-1-basic---debug-level-1
      - [**Level 2: Headers** (`--debug-level 2`)]#level-2-headers---debug-level-2
      - [**Level 3: Full** (`--debug-level 3`)]#level-3-full---debug-level-3
    - [Debug Usage Examples]#debug-usage-examples
    - [Debug Output Example]#debug-output-example
    - [Use Cases]#use-cases-1
      - [**API Development \& Testing**:](#api-development--testing)
      - [**Issue Troubleshooting**:]#issue-troubleshooting
      - [**Performance Analysis**:]#performance-analysis
      - [**Authentication Debugging**:]#authentication-debugging
    - [Debug Best Practices]#debug-best-practices
    - [Important Notes]#important-notes
  - [Web Dashboard]#web-dashboard
    - [Features]#features-4
    - [WebUI vs TUI]#webui-vs-tui
    - [Usage Examples]#usage-examples-1
  - [WebSocket API]#websocket-api
    - [Connection]#connection
    - [Message Types]#message-types
    - [Message Examples]#message-examples
      - [Test Started]#test-started
      - [Metrics Update]#metrics-update
      - [Request Log (New!)]#request-log-new
    - [Integration Examples]#integration-examples
      - [JavaScript WebSocket Client]#javascript-websocket-client
      - [Python Monitoring Script]#python-monitoring-script
  - [CSV Export]#csv-export
  - [User-Agent Management]#user-agent-management
    - [Random User-Agents]#random-user-agents
    - [Custom User-Agent File]#custom-user-agent-file
  - [TUI Interface]#tui-interface
    - [TUI Features:]#tui-features
    - [When to Use TUI vs WebUI:]#when-to-use-tui-vs-webui
    - [TUI Controls:]#tui-controls
    - [TUI Examples:]#tui-examples
  - [Advanced Metrics \& Monitoring](#advanced-metrics--monitoring)
    - [Advanced Metrics Features]#advanced-metrics-features
    - [Percentile Metrics]#percentile-metrics
    - [Latency Histograms]#latency-histograms
    - [Smart Alerts]#smart-alerts
    - [Performance Degradation Detection]#performance-degradation-detection
  - [Authentication \& Security](#authentication--security)
    - [Authentication Features:]#authentication-features
    - [JWT Authentication:]#jwt-authentication
    - [API Key Authentication:]#api-key-authentication
    - [Security Best Practices:]#security-best-practices
  - [Prometheus Export \& Monitoring](#prometheus-export--monitoring)
    - [Prometheus Features:]#prometheus-features
    - [Prometheus Setup:]#prometheus-setup
    - [Grafana Dashboard Integration:]#grafana-dashboard-integration
    - [Integration Example:]#integration-example
  - [Memory Optimization]#memory-optimization
    - [Memory Optimization Features:]#memory-optimization-features
    - [Memory Profiles:]#memory-profiles
    - [Memory Configuration Options:]#memory-configuration-options
    - [Memory Monitoring:]#memory-monitoring
  - [HTTP/2 Support]#http2-support
    - [HTTP/2 Features:]#http2-features
    - [HTTP/2 Configuration:]#http2-configuration
    - [HTTP/2 Configuration Options:]#http2-configuration-options
    - [Protocol Information:]#protocol-information
    - [Performance Benefits:]#performance-benefits
    - [HTTP/2 Best Practices:]#http2-best-practices
  - [Distributed Load Testing]#distributed-load-testing-1
    - [Distributed Features]#distributed-features
    - [Architecture Overview]#architecture-overview
    - [Quick Start Guide]#quick-start-guide
      - [1. **Start the Coordinator**]#1-start-the-coordinator
      - [2. **Connect Workers** (run on different machines)]#2-connect-workers-run-on-different-machines
      - [3. **Run Distributed Tests** (from coordinator)]#3-run-distributed-tests-from-coordinator
    - [Coordinator Configuration]#coordinator-configuration
    - [Worker Configuration]#worker-configuration
    - [Load Distribution Algorithms]#load-distribution-algorithms
      - [**1. Round Robin Distribution** (Default)]#1-round-robin-distribution-default
      - [**2. Load-Based Distribution**]#2-load-based-distribution
      - [**3. Weighted Distribution**]#3-weighted-distribution
    - [Real-time Metrics Aggregation]#real-time-metrics-aggregation
    - [Geographic Distribution Examples]#geographic-distribution-examples
      - [**Multi-Region Setup**]#multi-region-setup
      - [**Hybrid Cloud Setup**]#hybrid-cloud-setup
    - [Fault Tolerance \& Recovery](#fault-tolerance--recovery)
      - [**Automatic Worker Recovery**]#automatic-worker-recovery
      - [**Network Resilience**]#network-resilience
    - [Use Cases \& Best Practices](#use-cases--best-practices)
      - [**Large-Scale Load Testing**]#large-scale-load-testing
      - [**Geographic Performance Testing**]#geographic-performance-testing
      - [**Microservices Stress Testing**]#microservices-stress-testing
      - [**CI/CD Distributed Testing**]#cicd-distributed-testing
    - [Performance Tips]#performance-tips
    - [Important Considerations]#important-considerations
  - [Real-World Examples]#real-world-examples
    - [API Testing with WebUI]#api-testing-with-webui
    - [Performance Benchmarking]#performance-benchmarking
    - [Stealth \& Security Testing](#stealth--security-testing)
    - [CI/CD Integration]#cicd-integration
    - [Distributed Load Testing]#distributed-load-testing-2
  - [License]#license

## Usage Examples

### WebUI Testing
```bash
# Simple WebUI test with auto-browser opening (unlimited duration)
pulzr https://httpbin.org/get --webui --open-browser

# Production API test with WebUI (runs until stopped)
pulzr https://httpbin.org/get --webui --open-browser \
      -c 25 -r 10 --random-ua

# Load test with custom payload and specific duration
pulzr https://httpbin.org/post --method post \
      --payload '{"title": "test", "body": "content"}' \
      --webui --open-browser -c 15 -d 45
```

### TUI Testing
```bash
# Basic TUI load test
pulzr https://httpbin.org/get -c 10 -d 30

# High-concurrency test with rate limiting
pulzr https://httpbin.org/get -c 50 -r 100 -d 120

# Stealth testing with random User-Agents
pulzr https://httpbin.org/user-agent --random-ua -c 3 -r 5 -d 300
```

### HTTP Methods & Payloads
```bash
# POST JSON data (curl-style)
pulzr https://httpbin.org/post -X POST --data '{"key": "value"}' -c 5

# POST with long-form flags
pulzr https://httpbin.org/post --method post \
      --payload '{"key": "value", "test": true}' -c 5

# PUT request with custom headers
pulzr https://httpbin.org/put -X PUT \
      --data '{"name": "updated"}' \
      -H "Authorization: Bearer token123" \
      -H "Content-Type: application/json"

# DELETE request test
pulzr https://httpbin.org/delete -X DELETE \
      -H "Authorization: Bearer token123" -c 3 -d 10
```

### Data Export & Analysis
```bash
# Export detailed CSV reports
pulzr https://httpbin.org/get -c 20 -d 60 --output load_test_results

# WebUI with CSV export
pulzr https://httpbin.org/get --webui --output results \
      -c 15 -r 25 -d 90 --random-ua

# Headless mode with CSV only
pulzr https://httpbin.org/get --headless --output batch_test \
      -c 30 -d 120 -r 50
```

### Specialized Testing
```bash
# Error testing (expect failures)
pulzr https://httpbin.org/status/500 --webui -c 5 -d 30

# Redirect testing
pulzr https://httpbin.org/redirect/3 --webui -c 5 -d 20

# Custom User-Agent testing
pulzr https://httpbin.org/user-agent --user-agent "MyBot/2.0" \
      --webui -c 10 -d 45

# File-based User-Agent rotation
echo -e "Bot-1/1.0\nBot-2/1.0\nBot-3/1.0" > agents.txt
pulzr https://httpbin.org/user-agent --ua-file agents.txt --webui -c 5
```

### Performance Testing
```bash
# High-throughput test
pulzr https://httpbin.org/get -c 100 -r 500 -d 300 --headless

# Sustained load test
pulzr https://httpbin.org/get -c 25 -r 50 -d 1800 --webui

# Burst testing
pulzr https://httpbin.org/get -c 200 -d 60 --webui

# Request count performance test
pulzr https://httpbin.org/get -c 50 -n 10000 --headless --output perf_test
```

### Scenario-Based Testing
```bash
# JSON scenario file
pulzr --scenario examples/api_test.json --concurrent 10 --duration 60

# YAML scenario file  
pulzr --scenario examples/load_test.yaml --webui --open-browser

# Scenario with custom concurrency and duration
pulzr --scenario examples/complex_test.json -c 25 -d 300 --webui
```

### Ramp-up Load Testing
```bash
# Linear ramp-up over 30 seconds
pulzr https://httpbin.org/get --ramp-up 30 --ramp-pattern linear -c 50

# Exponential ramp-up with WebUI
pulzr https://httpbin.org/get --ramp-up 60 --ramp-pattern exponential \
      -c 100 -d 300 --webui --open-browser

# Step ramp-up pattern (25%, 50%, 75%, 100% at quarters)
pulzr https://httpbin.org/get --ramp-up 20 --ramp-pattern step -c 20

# Scenario with ramp-up
pulzr --scenario load_test.json --ramp-up 45 --ramp-pattern linear -c 30 -d 180
```

### Multiple Endpoints Testing
```bash
# Test multiple API endpoints simultaneously
pulzr --endpoints examples/api_endpoints.json --concurrent 10 --duration 60

# Multi-endpoint test with WebUI
pulzr --endpoints examples/api_endpoints.json --webui --open-browser -c 20 -d 300

# Multi-endpoint with ramp-up pattern
pulzr --endpoints examples/api_endpoints.json --ramp-up 30 --ramp-pattern linear \
      -c 50 -d 600 --webui

# High-throughput multi-endpoint test
pulzr --endpoints examples/api_endpoints.json -c 100 -r 200 -d 1800 --output results
```

### Integration Testing
```bash
# WebSocket server for external monitoring
pulzr https://httpbin.org/get --websocket --websocket-port 9621 \
      -c 20 -d 120

# Combined WebUI + WebSocket
pulzr https://httpbin.org/get --webui --websocket \
      --webui-port 9622 --websocket-port 9621 -c 15 -d 90
```

### CI/CD Integration
```bash
# Print final summary as JSON (pipe to jq, save, etc.)
pulzr https://httpbin.org/get -c 10 -n 100 --json-output | jq .

# Write JSON summary to file
pulzr https://httpbin.org/get -c 10 -d 30 --output-file summary.json

# Abort if error rate exceeds 5%
pulzr https://httpbin.org/get -c 20 -d 60 --fail-on-error-rate 5

# Validate response content
pulzr https://httpbin.org/get -c 5 -n 50 --expect-body '"url"'

# Save a baseline, then compare on next run
pulzr https://httpbin.org/get -c 10 -d 30 --save-baseline base.json
pulzr https://httpbin.org/get -c 10 -d 30 --compare-baseline base.json

# Custom alert thresholds
pulzr https://httpbin.org/get -c 10 -d 30 --alert-error-rate 2 --alert-latency 200

# Warmup + headless with JSON output
pulzr https://httpbin.org/get -c 20 -d 60 --warmup 10 --headless --json-output

# Retry transient network errors
pulzr https://httpbin.org/get -c 5 -n 50 --retry 3
```

### Distributed Load Testing
```bash
# Start coordinator (central control)
pulzr --coordinator --coordinator-port 9630 --max-workers 10

# Connect workers from multiple machines
pulzr --worker --coordinator-host 192.168.1.100 --coordinator-port 9630 \
      --worker-id "worker-1"

# Distributed test with automatic load distribution
pulzr https://httpbin.org/get --coordinator --webui --open-browser \
      -c 100 -r 200 -d 600

# Worker with specific capabilities
pulzr --worker --coordinator-host coordinator.example.com \
      --worker-id "high-perf-worker" --max-concurrent 200 --max-rps 500
```

### Command Line Options

| Option | Short | Description | Default |
|--------|-------|-------------|---------|
| `URL` (positional) | | Target URL to test (optional with --scenario) | Required |
| `--scenario` | `-s` | Load test scenario from JSON/YAML file | None |
| `--endpoints` | | Multiple endpoints configuration file (JSON/YAML) | None |
| `--ramp-up` | | Ramp-up duration in seconds (gradual load increase) | None |
| `--ramp-pattern` | | Ramp-up pattern (linear, exponential, step) | linear |
| `--concurrent` | `-c` | Number of concurrent requests | 10 |
| `--duration` | `-d` | Test duration in seconds (default: run until stopped) | Until stopped |
| `--rps` | `-r` | Requests per second limit | None |
| `--method` | `-m` | HTTP method (get, post, put, delete, etc.) | get |
| `--payload` | `-p` | Request payload (JSON or plain text) | None |
| `--headers` | `-H` | Custom headers (format: 'Key: Value') | None |
| `--user-agent` | | Custom User-Agent string | "pulzr" |
| `--random-ua` | | Use random User-Agent rotation | false |
| `--ua-file` | | User-Agent list file (one per line) | None |
| `--output` | `-o` | CSV export path (creates .detailed.csv & .summary.csv) | None |
| `--websocket` | | Enable WebSocket server for metrics streaming | false |
| `--websocket-port` | | WebSocket server port | 9621 |
| `--webui` | | Enable Web Dashboard (auto-disables TUI) | false |
| `--webui-port` | | Web Dashboard port | 9622 |
| `--open-browser` | | Auto-open WebUI in default browser | false |
| `--headless` | | Run in headless mode (disable TUI display) | false |
| `--no-tui` | | Alias for --headless (backward compatibility) | false |
| `--quiet` | `-q` | Quiet mode - minimal output (only final summary) | false |
| `--output-format` | | Output format (detailed, compact, minimal) | detailed |
| `--timeout` | `-t` | Request timeout in seconds | None |
| `--latencies` | `-l` | Print latency statistics (enables latency distribution) | false |
| `--requests` | `-n` | Total number of requests to make | None |
| `--body` | `-b` | Request body (alias for payload) | None |
| `--body-file` | `-f` | File to use as request body | None |
| `--insecure` | `-k` | Skip TLS certificate verification | false |
| `--http1` | | Force HTTP/1.x protocol | false |
| `--http2` | | Enable HTTP/2.0 protocol | false |
| `--cert` | | Path to client TLS certificate | None |
| `--key` | | Path to client TLS certificate private key | None |
| `--print` | `-P` | Control output sections (intro,progress,result) | All |
| `--no-print` | | Don't output anything (compatibility mode) | false |
| `--format` | `-O` | Output format (plain-text, json) | None |
| `--connections` | | Alias for --concurrent | 10 |
| `--rate` | | Alias for --rps | None |
| `--verbose` | `-v` | Verbose output | false |
| `--debug` | | Enable debug mode with detailed request/response logging | false |
| `--debug-level` | | Debug verbosity level (1-3): 1=basic, 2=headers, 3=full | 1 |
| `--coordinator` | | Run as distributed coordinator (central control) | false |
| `--coordinator-port` | | Coordinator listening port | 9630 |
| `--max-workers` | | Maximum workers allowed to connect | 100 |
| `--worker` | | Run as distributed worker (connects to coordinator) | false |
| `--coordinator-host` | | Coordinator hostname/IP to connect to | localhost |
| `--worker-id` | | Unique worker identifier | auto-generated |
| `--max-concurrent` | | Worker maximum concurrent requests | 100 |
| `--max-rps` | | Worker maximum requests per second | None |
| `--examples` | | Show usage examples and exit | N/A |
| `--retry` | | Retry failed requests N times (network errors only) | 0 |
| `--warmup` | | Warmup period in seconds before recording stats | None |
| `--json-output` | | Print final summary as JSON to stdout (CI-friendly) | false |
| `--output-file` | | Write final JSON summary to a file | None |
| `--fail-on-error-rate` | | Abort and exit 1 if error rate exceeds N% | None |
| `--save-baseline` | | Save final summary as a JSON baseline file | None |
| `--compare-baseline` | | Compare run against saved baseline; exit 1 on regression | None |
| `--alert-error-rate` | | Override alert error rate threshold in percent | 10 |
| `--alert-latency` | | Override alert latency threshold in milliseconds | 500 |
| `--expect-body` | | Fail request if response body does not contain this string | None |
| `--follow-redirects` | `-L` | Follow HTTP redirects (enabled by default) | false |
| `--no-follow-redirects` | | Disable following HTTP redirects | false |

## Output Formats

Pulzr supports multiple output formats to match different use cases and preferences:

### Available Formats

| Format | Description | Use Case |
|--------|-------------|----------|
| `detailed` | Full verbose output with all statistics (default) | Development, analysis |
| `compact` | Aligned statistics output with progress bar | Automation, CI/CD |
| `minimal` | Single-line summary | Scripts, quiet automation |

### Output Format Examples

#### Detailed Format (Default)
```bash
pulzr https://httpbin.org/get -c 10 -d 30
# Shows full statistics with sections for response times, status codes, errors, etc.
```

#### Compact Format
```bash
pulzr https://httpbin.org/get -c 10 -d 30 --output-format compact
# Output:
# Load testing https://httpbin.org/get for 30s using 10 connections
# [=========================================================================] 30s Done!
# Statistics        Avg      Stdev        Max
#   Reqs/sec       45.67      4.56        52
#   Latency      21.86ms    2.45ms    89.23ms
#   Latency Distribution
#      50%    20.15ms
#      75%    22.67ms
#      90%    25.89ms
#      99%    45.12ms
#   HTTP codes:
#     1xx - 0, 2xx - 1370, 3xx - 0, 4xx - 0, 5xx - 0
#   Throughput:     2.34MB/s
```

#### Minimal Format
```bash
pulzr https://httpbin.org/get -c 10 -d 30 --output-format minimal
# Output: 1370 requests in 30.00s, 0 failed, 45.67 req/s
```

#### Quiet Mode
```bash
pulzr https://httpbin.org/get -c 10 -d 30 --quiet
# Shows only minimal output regardless of format, suppresses progress messages
```

### Compatible CLI Syntax

Pulzr supports alternative command-line syntax for easy migration:

```bash
# Positional URL argument
pulzr https://httpbin.org/get -c 50 -d 30

# Alternative flag names
pulzr https://example.com --connections 25 --rate 100 --timeout 10 --latencies

# Request body options
pulzr https://api.example.com -c 10 --body '{"test": "data"}' --method POST
pulzr https://api.example.com -c 10 --body-file request.json --method PUT

# Output control
pulzr https://example.com -c 10 -d 30 --format json --no-print
pulzr https://example.com -c 10 -d 30 --format plain-text --latencies
pulzr https://example.com -c 10 --print result --format json
```

### Alternative Output Formats

| Format | Flag | Description |
|--------|------|-------------|
| `plain-text` (alias: `pt`) | `--format plain-text` | Structured text output with statistics table |
| `json` (alias: `j`) | `--format json` | JSON formatted results for parsing |

### Output Control Options

| Flag | Description | Example |
|------|-------------|---------|
| `--print intro,progress,result` | Control which sections to show | `--print result` |
| `--no-print` | Silent mode (no output) | `--no-print` |
| `--latencies` | Enable latency distribution display | `-l` |

### Migration Examples

```bash
# Basic load test with structured output
pulzr -c 125 -d 10 --latencies --format plain-text https://example.com

# JSON output for automation
pulzr --connections 50 --duration 30 --format json https://api.example.com

# Silent operation with request count
pulzr -c 10 -n 1000 --no-print https://example.com

# File-based request body
pulzr -c 25 -d 60 --body-file payload.json --method POST https://api.example.com
```

## Scenario Files

Scenario files enable complex, multi-step load testing with variable substitution and weighted request distribution. Both JSON and YAML formats are supported.

### Features

- **Multi-step Testing**: Define multiple HTTP requests in sequence
- **Weighted Distribution**: Control request frequency with weights  
- **Variable Substitution**: Use `${variable}` syntax for dynamic values
- **Per-step Configuration**: Custom headers, payloads, timeouts per step
- **Format Support**: Both JSON and YAML scenario files
- **Default Overrides**: Scenario defaults can override CLI options

### Example JSON Scenario
```json
{
  "name": "API Load Test",
  "description": "Multi-endpoint testing scenario",
  "version": "1.0",
  "variables": {
    "host": "httpbin.org",
    "api_key": "your-api-key",
    "user_id": "12345"
  },
  "defaults": {
    "concurrent": 10,
    "duration": 120,
    "rps": 20,
    "timeout": 15,
    "headers": {
      "Authorization": "Bearer ${api_key}",
      "User-Agent": "LoadTest/1.0"
    }
  },
  "steps": [
    {
      "name": "Get User Profile",
      "url": "https://${host}/users/${user_id}",
      "method": "GET",
      "weight": 3.0
    },
    {
      "name": "Update Profile",
      "url": "https://${host}/users/${user_id}",
      "method": "PUT",
      "payload": "{\"status\": \"active\", \"timestamp\": \"${timestamp}\"}",
      "headers": {
        "Content-Type": "application/json"
      },
      "weight": 1.0
    },
    {
      "name": "Health Check",
      "url": "https://${host}/health",
      "method": "GET",
      "weight": 0.5
    }
  ]
}
```

### Example YAML Scenario
```yaml
name: "E-commerce Load Test"
description: "Shopping cart and checkout flow testing"
version: "1.0"

variables:
  host: "httpbin.org"
  product_id: "abc123"
  user_token: "user-session-token"

defaults:
  concurrent: 15
  duration: 300
  rps: 25
  timeout: 10
  headers:
    Authorization: "Bearer ${user_token}"
    User-Agent: "ShopBot/2.0"

steps:
  - name: "Browse Products"
    url: "https://${host}/get"
    method: "GET"
    weight: 5.0

  - name: "Add to Cart"
    url: "https://${host}/post"
    method: "POST"
    payload: '{"product_id": "${product_id}", "quantity": 1}'
    headers:
      Content-Type: "application/json"
    weight: 2.0

  - name: "Checkout"
    url: "https://${host}/post"
    method: "POST"
    payload: '{"payment_method": "card", "shipping": "standard"}'
    headers:
      Content-Type: "application/json"
    weight: 1.0
```

### Scenario Usage
```bash
# Run JSON scenario file
pulzr --scenario load_test.json

# Run YAML scenario with WebUI
pulzr --scenario api_test.yaml --webui --open-browser

# Override scenario defaults with CLI options
pulzr --scenario test.json -c 50 -d 600 --rps 100

# Scenario with CSV export
pulzr --scenario complex_test.yaml --output results --webui
```

### Scenario Configuration

| Field | Type | Description |
|-------|------|-------------|
| `name` | String | Scenario name (displayed in output) |
| `description` | String | Optional scenario description |
| `version` | String | Optional version number |
| `variables` | Object | Key-value pairs for `${variable}` substitution |
| `defaults` | Object | Default test configuration (overrides CLI) |
| `steps` | Array | List of HTTP requests to execute |

### Step Configuration

| Field | Type | Description |
|-------|------|-------------|
| `name` | String | Step name for logging |
| `url` | String | Request URL (supports variables) |
| `method` | String | HTTP method (GET, POST, PUT, etc.) |
| `headers` | Object | Custom headers for this step |
| `payload` | String | Request body (supports variables) |
| `timeout` | Number | Request timeout in seconds |
| `weight` | Number | Request frequency weight (default: 1.0) |

### Variable Substitution
- Use `${variable_name}` syntax in URLs, payloads, and headers
- Variables defined in the `variables` section
- Special built-in variables: `${timestamp}` (current Unix timestamp)
- Variables are replaced at runtime for each request

### Weighted Distribution
- Each step has a `weight` value (default: 1.0)
- Higher weights = more frequent requests
- Example: weight 3.0 = 3x more likely than weight 1.0
- Total weights are normalized to create probability distribution

## Ramp-up Patterns

Ramp-up patterns enable gradual load increase over time instead of starting with maximum concurrency immediately. This helps identify breaking points and simulates realistic traffic growth.

### Features
- **Gradual Load Increase**: Start with low concurrency and gradually increase
- **Multiple Patterns**: Linear, exponential, and step-wise increase patterns
- **Flexible Duration**: Configure ramp-up period from seconds to minutes
- **Real-time Progress**: Live console output showing current concurrency levels
- **Scenario Integration**: Works seamlessly with scenario-based testing
- **Smart Transition**: Smooth transition from ramp-up to steady-state testing

### Ramp-up Patterns

#### 1. **Linear Pattern** (`--ramp-pattern linear`)
Increases concurrency evenly over time:
- **0%****25%****50%****75%****100%** (smooth progression)
- Best for: General load testing, finding gradual breaking points
- Example: 0 → 25 → 50 → 75 → 100 concurrent requests over 20 seconds

#### 2. **Exponential Pattern** (`--ramp-pattern exponential`)
Slow start with rapid acceleration:
- **0%****6%****25%****56%****100%** (curved growth)
- Best for: Stress testing, simulating viral/sudden traffic spikes
- Example: 0 → 6 → 25 → 56 → 100 concurrent requests over 20 seconds

#### 3. **Step Pattern** (`--ramp-pattern step`)
Discrete jumps at quarter intervals:
- **25%****50%****75%****100%** (stepwise increases)
- Best for: Testing specific load thresholds, capacity planning
- Example: 25 → 50 → 75 → 100 concurrent requests over 20 seconds

### Ramp-up Usage Examples

```bash
# Basic linear ramp-up (30s to reach 50 concurrent)
pulzr https://httpbin.org/get --ramp-up 30 --ramp-pattern linear -c 50 -d 120

# Exponential stress test with WebUI
pulzr https://httpbin.org/get --ramp-up 60 --ramp-pattern exponential \
      -c 200 -d 300 --webui --open-browser

# Step-wise capacity testing
pulzr https://httpbin.org/get --ramp-up 40 --ramp-pattern step \
      -c 100 -d 600 --output capacity_test

# Scenario-based ramp-up
pulzr --scenario examples/api_test.json --ramp-up 45 --ramp-pattern linear \
      -c 75 -d 180 --webui

# Production readiness test (15-minute ramp + 45-minute sustained)
pulzr https://httpbin.org/get --ramp-up 900 --ramp-pattern linear \
      -c 500 -d 3600 --rps 100 --output prod_readiness
```

### Ramp-up Configuration

| Parameter | Description | Values |
|-----------|-------------|---------|
| `--ramp-up` | Ramp-up duration in seconds | 1-3600 (1 second to 1 hour) |
| `--ramp-pattern` | Increase pattern type | `linear`, `exponential`, `step` |
| `--concurrent` | Maximum concurrent requests | Final target concurrency |
| `--duration` | Total test duration | Includes ramp-up + steady-state time |

### Ramp-up Behavior

1. **Initialization**: Starts with minimum concurrency (calculated based on pattern)
2. **Ramp-up Phase**: Gradually increases workers every 500ms based on pattern
3. **Progress Reporting**: Real-time console output showing current worker count
4. **Completion Detection**: Automatically transitions to steady-state when target reached
5. **Steady State**: Continues at maximum concurrency for remaining test duration

### Best Practices

- **Linear**: Use for general load testing and finding gradual performance degradation
- **Exponential**: Use for stress testing and simulating sudden traffic bursts  
- **Step**: Use for capacity planning and testing specific load thresholds
- **Duration**: Allow enough ramp-up time (30-120s) for meaningful traffic patterns
- **Monitoring**: Use WebUI (`--webui`) for visual monitoring during ramp-up
- **Scenarios**: Combine with scenario files for realistic multi-endpoint ramp-up

## Multiple Endpoints

Multiple endpoints testing enables simultaneous load testing of different APIs with weighted distribution, perfect for testing microservices, API gateways, and complex system integrations.

### Features
- **Simultaneous Testing**: Test multiple APIs concurrently in one session
- **Weighted Distribution**: Control request frequency per endpoint with weights
- **Per-Endpoint Configuration**: Custom methods, headers, payloads, timeouts per endpoint
- **Expected Status Validation**: Define expected status codes per endpoint
- **Real-time Monitoring**: Live endpoint-specific logging with success indicators
- **Integration Ready**: Works with ramp-up patterns and all existing features
- **Flexible Config**: JSON/YAML configuration files

### Example Endpoints Configuration

#### JSON Format:
```json
{
  "name": "Multi-API Load Test",
  "description": "Testing multiple microservices",
  "version": "1.0",
  "defaults": {
    "method": "GET",
    "headers": {
      "User-Agent": "pulzr-endpoints/1.0",
      "Accept": "application/json"
    },
    "timeout": 15,
    "weight": 1.0
  },
  "endpoints": [
    {
      "name": "Get User Data",
      "url": "https://httpbin.org/get",
      "method": "GET",
      "weight": 3.0,
      "expected_status": [200]
    },
    {
      "name": "Create User",
      "url": "https://httpbin.org/post",
      "method": "POST",
      "payload": "{\"name\": \"test\", \"email\": \"test@example.com\"}",
      "headers": {
        "Content-Type": "application/json"
      },
      "weight": 1.0,
      "expected_status": [200]
    },
    {
      "name": "Update User",
      "url": "https://httpbin.org/put",
      "method": "PUT",
      "weight": 2.0,
      "expected_status": [200]
    },
    {
      "name": "Health Check",
      "url": "https://httpbin.org/status/200",
      "method": "GET",
      "weight": 0.5,
      "expected_status": [200]
    }
  ]
}
```

### Multiple Endpoints Usage

```bash
# Basic multi-endpoint testing
pulzr --endpoints api_config.json --concurrent 20 --duration 300

# Multi-endpoint with WebUI monitoring
pulzr --endpoints api_config.json --webui --open-browser -c 50 -d 600

# Gradual ramp-up across endpoints
pulzr --endpoints api_config.json --ramp-up 60 --ramp-pattern linear \
      -c 100 -d 1800 --webui

# High-throughput production test
pulzr --endpoints api_config.json -c 200 -r 500 -d 3600 \
      --output production_test --webui

# Rate-limited multi-endpoint test
pulzr --endpoints api_config.json -c 30 -r 100 -d 900 \
      --random-ua --output microservices_test
```

### Endpoint Configuration

| Field | Type | Description |
|-------|------|-------------|
| `name` | String | Endpoint name for logging and identification |
| `url` | String | Target URL for this endpoint |
| `method` | String | HTTP method (GET, POST, PUT, DELETE, etc.) |
| `headers` | Object | Custom headers for this endpoint |
| `payload` | String | Request body (for POST/PUT requests) |
| `timeout` | Number | Request timeout in seconds |
| `weight` | Number | Request frequency weight (default: 1.0) |
| `expected_status` | Array | Expected HTTP status codes (default: 2xx) |

### Weighted Distribution
- **Weight Values**: Higher weights = more frequent requests
- **Example**: weight 3.0 = 3x more likely than weight 1.0
- **Distribution**: Weights are normalized to create probability distribution
- **Real-time**: Live console output shows which endpoints are being hit

### Use Cases

#### **Microservices Testing**:
```bash
# Test user, payment, and notification services simultaneously
pulzr --endpoints microservices.json --ramp-up 30 -c 50 -d 600 --webui
```

#### **API Gateway Load Testing**:
```bash
# Test multiple routes through API gateway
pulzr --endpoints gateway_routes.json -c 100 -r 200 -d 1800 --output gateway_test
```

#### **CI/CD Integration Testing**:
```bash
# Validate all API endpoints after deployment
pulzr --endpoints integration_tests.json -c 20 -d 300 --output ci_validation
```

#### **Capacity Planning**:
```bash
# Test system capacity across all services
pulzr --endpoints capacity_test.json --ramp-up 120 --ramp-pattern exponential \
      -c 500 -d 3600 --webui --output capacity_analysis
```

### Best Practices

- **Weight Distribution**: Use weights to simulate realistic traffic patterns
- **Expected Status**: Define expected status codes to catch regressions
- **Timeouts**: Set appropriate timeouts per endpoint based on SLAs
- **Monitoring**: Use WebUI for real-time endpoint monitoring
- **Ramp-up**: Combine with ramp-up patterns for realistic load progression
- **Documentation**: Document endpoint purposes and expected behaviors

## Debug Mode

Debug mode provides detailed request/response logging with multiple verbosity levels, perfect for troubleshooting API issues, analyzing request patterns, and understanding HTTP interactions during load testing.

### Features
- **Request/Response Correlation**: Each request gets a unique session ID for easy tracking
- **Three Verbosity Levels**: Choose the right level of detail for your needs
- **Timing Information**: Precise request timing and duration tracking
- **Scenario Integration**: Works seamlessly with scenario and endpoint testing
- **Structured Output**: Clean, readable debug output with timestamps
- **CLI Integration**: Simple command-line options for immediate debugging

### Debug Levels

#### **Level 1: Basic** (`--debug-level 1`)
Shows essential request/response information:
- HTTP method and URL
- Response status code and timing
- Content length
- Session ID for correlation

#### **Level 2: Headers** (`--debug-level 2`)
Includes everything from Level 1 plus:
- Request headers (including User-Agent)
- Response headers
- Custom headers from scenarios/endpoints

#### **Level 3: Full** (`--debug-level 3`)
Includes everything from Level 2 plus:
- Request body content
- Response body content (truncated for large responses)
- Complete HTTP transaction details

### Debug Usage Examples

```bash
# Basic debug mode (Level 1) with scenarios
pulzr --scenario examples/api_test.json --debug --debug-level 1 -c 2 -d 10

# Debug mode with headers (Level 2) for endpoint testing
pulzr --endpoints examples/api_endpoints.json --debug --debug-level 2 -c 1 -d 5

# Full debug mode (Level 3) for detailed troubleshooting
pulzr --scenario examples/complex_test.json --debug --debug-level 3 -c 1 -d 15

# Debug mode with WebUI for visual monitoring
pulzr --scenario examples/api_test.json --debug --debug-level 2 --webui --open-browser

# Debug mode with ramp-up patterns
pulzr --endpoints examples/api_endpoints.json --debug --debug-level 1 \
      --ramp-up 30 --ramp-pattern linear -c 10 -d 120
```

### Debug Output Example

```
[DEBUG] Request 000001 [14:30:15.123]
  POST https://httpbin.org/post
  Headers:
    Authorization: Bearer token123
    Content-Type: application/json
    User-Agent: pulzr-test/1.0
  Body: {"name": "test", "email": "test@httpbin.org"}

[DEBUG] Response 000001 [14:30:15.456]
  Status: 201 (332ms)
  Content-Length: 156 bytes
  Headers:
    Location: /users/12345
    Content-Type: application/json
  Body: {"id": 12345, "name": "test", "email": "test@httpbin.org", "created": "2024-01-01T14:30:15Z"}
```

### Use Cases

#### **API Development & Testing**:
```bash
# Debug new API endpoints during development
pulzr https://localhost:3000/api/test --debug --debug-level 3 -c 1 -d 30
```

#### **Issue Troubleshooting**:
```bash
# Debug failing requests with full details
pulzr --scenario failing_test.json --debug --debug-level 3 -c 1 -d 60
```

#### **Performance Analysis**:
```bash
# Analyze request patterns with timing information
pulzr --endpoints production_apis.json --debug --debug-level 1 -c 5 -d 300
```

#### **Authentication Debugging**:
```bash
# Debug authentication headers and responses
pulzr --scenario auth_test.json --debug --debug-level 2 -c 1 -d 120
```

### Debug Best Practices

- **Level 1**: Use for performance testing to track basic request/response flow
- **Level 2**: Use for authentication and header debugging
- **Level 3**: Use for payload debugging and detailed troubleshooting
- **Combine with WebUI**: Use `--webui` alongside debug mode for visual monitoring
- **Single Concurrency**: Use `-c 1` for cleaner debug output during troubleshooting
- **Scenario Testing**: Debug mode works best with scenario and endpoint configurations

### Important Notes

- **Performance Impact**: Debug mode has minimal impact on Level 1, increasing with higher levels
- **Output Volume**: Level 3 can generate significant output with large payloads
- **Security**: Be cautious with Level 3 when debugging sensitive data
- **Session Correlation**: Use session IDs to track request/response pairs in concurrent tests

## Web Dashboard

The WebUI provides a modern, self-contained web interface with real-time monitoring, charts, and detailed request logging.

### Features
- **3-Tab Layout**: Live metrics, Summary, and Logs tabs — auto-switches to Summary when test completes
- **Canvas Line Chart**: Dual-axis real-time chart showing RPS (green) and avg response time (amber) over a 120-point rolling window
- **Test Progress Bar**: Smooth animated bar for both duration mode and request-count mode
- **Color-coded Metric Cards**: Cards turn amber or red as error rate / latency thresholds are exceeded; critical values pulse
- **Canvas Histogram**: Latency distribution with hover tooltips showing bucket range, count, and percentage
- **Filterable Logs Tab**: Filter by 2xx/3xx/4xx/5xx/Errors, auto-scroll toggle, up to 1000 recent entries
- **Final Summary Tab**: Full percentile breakdown and test config rendered after test completion
- **Responsive Design**: Works on desktop and mobile; canvases resize automatically
- **Dynamic Connection Status**: Shows "Connected — waiting for test" vs "Connecting..." state
- **Auto Port Selection**: Finds available ports automatically (default: 9622)
- **Browser Integration**: Auto-open in default browser with `--open-browser`

### WebUI vs TUI
- **WebUI Mode**: `--webui` automatically disables TUI for clean web-only experience
- **TUI Mode**: Default terminal interface with sparkline charts and live metrics
- **Headless Mode**: `--headless` for automation and CI/CD pipelines (alias: `--no-tui`)

### Usage Examples
```bash
# Quick WebUI test with auto-open browser
pulzr https://httpbin.org/get --webui --open-browser

# Production load test with WebUI
pulzr https://httpbin.org/get --webui --open-browser \
      -c 25 -r 10 -d 300 --random-ua --output results

# Custom ports for WebUI
pulzr https://httpbin.org/get --webui --webui-port 8080 \
      --websocket-port 8081

# WebUI + WebSocket for external monitoring
pulzr https://httpbin.org/get --webui --websocket \
      --open-browser -c 50 -r 100 -d 600
```

## WebSocket API

WebSocket server provides real-time metrics streaming for external monitoring and integrations.

### Connection
- **Default Port**: `9621` (auto-selected if busy)
- **URL Format**: `ws://localhost:9621`
- **Enabled by**: `--websocket` or `--webui` flags

### Message Types

| Type | Description | Frequency |
|------|-------------|-----------|
| `test_started` | Test configuration and parameters | Once at start |
| `metrics_update` | Aggregated statistics (RPS, response times, etc.) | Every 1 second |
| `request_log` | Individual HTTP request details | Real-time per request |
| `test_completed` | Final summary with percentiles | Once at end |
| `error_event` | Error notifications and issues | As needed |

### Message Examples

#### Test Started
```json
{
  "type": "test_started",
  "timestamp": "2024-01-01T12:00:00Z",
  "config": {
    "url": "https://httpbin.org/get",
    "concurrent_requests": 10,
    "rps": 50,
    "duration_secs": 60,
    "method": "Get",
    "user_agent_mode": "Random (25 agents)"
  }
}
```

#### Metrics Update  
```json
{
  "type": "metrics_update", 
  "timestamp": "2024-01-01T12:00:05Z",
  "metrics": {
    "requests_sent": 25,
    "requests_completed": 23, 
    "requests_failed": 2,
    "current_rps": 4.6,
    "avg_response_time": 245.8,
    "min_response_time": 89,
    "max_response_time": 1205,
    "bytes_received": 15420,
    "status_codes": {"200": 21, "500": 2},
    "errors": {"Connection timeout": 2}
  }
}
```

#### Request Log (New!)
```json
{
  "type": "request_log",
  "timestamp": "2024-01-01T12:00:05.123Z", 
  "log": {
    "timestamp": "2024-01-01T12:00:05.120Z",
    "duration_ms": 245,
    "status_code": 200,
    "error": null,
    "user_agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36",
    "bytes_received": 1024
  }
}
```

### Integration Examples

#### JavaScript WebSocket Client
```javascript
const ws = new WebSocket('ws://localhost:9621');

ws.onmessage = (event) => {
  const message = JSON.parse(event.data);
  
  switch(message.type) {
    case 'test_started':
      console.log('Test started:', message.config);
      break;
    case 'metrics_update':
      updateDashboard(message.metrics);
      break;
    case 'request_log':
      logRequest(message.log);
      break;
    case 'test_completed':
      showSummary(message.summary);
      break;
  }
};

function logRequest(log) {
  console.log(`${log.status_code} ${log.duration_ms}ms`);
}
```

#### Python Monitoring Script
```python
import asyncio
import websockets
import json

async def monitor_test():
    uri = "ws://localhost:9621"
    async with websockets.connect(uri) as websocket:
        async for message in websocket:
            data = json.loads(message)
            
            if data['type'] == 'request_log':
                log = data['log']
                print(f"Request: {log['status_code']} in {log['duration_ms']}ms")
            elif data['type'] == 'metrics_update':
                metrics = data['metrics']
                print(f"RPS: {metrics['current_rps']:.1f}, "
                      f"Avg: {metrics['avg_response_time']:.0f}ms")

# Usage: Run this while pulzr test is running
asyncio.run(monitor_test())
```

## CSV Export

When using `--output filename`, two CSV files are generated:

- `filename.detailed.csv`: Individual request results
- `filename.summary.csv`: Aggregated test summary

## User-Agent Management

### Random User-Agents

Use `--random-ua` to rotate between 25 built-in realistic User-Agents including:
- Chrome (Windows, macOS, Linux)
- Firefox (Windows, macOS, Linux)
- Safari (macOS, iOS)
- Edge (Windows)
- Mobile browsers (Android, iOS)

### Custom User-Agent File

Create a file with one User-Agent per line:

```
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36
Custom-Bot/1.0
```

Then use: `--ua-file agents.txt`

## TUI Interface

The Terminal User Interface provides a rich, real-time monitoring experience in your terminal.

### TUI Features:
- **Live Metrics**: Real-time RPS, response times, success rates
- **Sparkline Charts**: Visual response time trends over time
- **Status Code Distribution**: Color-coded HTTP response breakdown
- **Error Tracking**: Real-time error monitoring and counts
- **Test Progress**: Duration, remaining time, and completion status
- **Interactive Controls**: `q` key or `Ctrl+C` to quit early
- **Responsive Layout**: Adapts to terminal size

### When to Use TUI vs WebUI:
- **TUI**: Default mode, great for development and quick tests
- **WebUI**: Use `--webui` for detailed request logging and browser-based monitoring
- **Headless**: Use `--headless` for automation, CI/CD, or background processes

### TUI Controls:
| Key | Action |
|-----|--------|
| `q` | Quit test early |
| `Ctrl+C` | Force quit |
| `Esc` | Alternative quit |

### TUI Examples:
```bash
# Basic TUI load test
pulzr https://httpbin.org/get -c 10 -d 30

# High-performance test with TUI monitoring
pulzr https://httpbin.org/get -c 100 -r 200 -d 300

# Stealth testing with TUI
pulzr https://httpbin.org/user-agent --random-ua -c 3 -r 2 -d 600
```

## Advanced Metrics & Monitoring

Pulzr provides comprehensive real-time metrics analysis and monitoring capabilities for deep performance insights.

### Advanced Metrics Features
- **Response Time Percentiles**: Real-time P50, P90, P95, and P99 calculations
- **Latency Histograms**: Visual distribution charts with configurable buckets
- **Smart Alerts**: Configurable error rate and performance degradation detection
- **Trend Analysis**: Automatic performance baseline tracking
- **Real-time Updates**: Live streaming metrics via WebSocket
- **Custom Thresholds**: User-defined alert thresholds for different scenarios

### Percentile Metrics
```bash
# Basic load test with percentile monitoring
pulzr https://api.example.com --webui --open-browser -c 50 -d 300

# High-performance test with detailed percentiles
pulzr https://api.example.com -c 100 -r 200 -d 600 --webui
```

**Available Percentiles:**
- **P50 (Median)**: 50% of requests complete within this time
- **P90**: 90% of requests complete within this time  
- **P95**: 95% of requests complete within this time
- **P99**: 99% of requests complete within this time

### Latency Histograms
The WebUI displays real-time latency distribution charts showing:
- **Response Time Buckets**: Configurable time ranges (e.g., 0-10ms, 10-50ms, 50-100ms)
- **Request Distribution**: Visual representation of response time spread
- **Performance Patterns**: Identify outliers and performance trends
- **Real-time Updates**: Live histogram updates during testing

### Smart Alerts
Configure intelligent alerts for automated monitoring:

```bash
# Enable alerts with custom thresholds
pulzr https://api.example.com --webui -c 50 -d 300 \
      --error-threshold 5.0 --degradation-threshold 150.0
```

**Alert Types:**
- **Error Rate Alerts**: Trigger when error percentage exceeds threshold
- **Performance Degradation**: Detect when response times increase significantly
- **Threshold Monitoring**: Custom alerts for specific performance criteria
- **Real-time Notifications**: Instant alerts in TUI and WebUI interfaces

### Performance Degradation Detection
Automatic performance monitoring with baseline comparison:
- **Baseline Tracking**: Establishes performance baselines during test execution
- **Trend Analysis**: Monitors response time trends over time
- **Degradation Alerts**: Automatic warnings when performance degrades
- **Severity Levels**: Low, Medium, High, and Critical alert classifications

## Authentication & Security

Comprehensive authentication support for testing secured APIs and services.

### Authentication Features:
- **JWT Token Support**: Bearer tokens with automatic refresh capability
- **API Key Management**: Multiple API key locations and formats
- **Auto-Refresh**: Automatic token renewal before expiration
- **Multiple Providers**: Support for various authentication services
- **Flexible Placement**: Headers, query parameters, or Bearer format

### JWT Authentication:
```bash
# Basic JWT authentication
pulzr https://httpbin.org/bearer --jwt-token "eyJhbGciOiJIUzI1NiIs..." \
      --webui -c 20 -d 300

# JWT with auto-refresh
pulzr https://httpbin.org/bearer --jwt-token "token123" \
      --jwt-secret "secret123" --jwt-auto-refresh \
      --jwt-refresh-endpoint "https://httpbin.org/post" \
      -c 50 -d 600

# JWT with custom claims
pulzr https://httpbin.org/bearer --jwt-token "token123" \
      --jwt-issuer "httpbin.org" --jwt-audience "test-users" \
      --webui --open-browser -c 30 -d 400
```

**JWT Configuration Options:**
- `--jwt-token`: JWT token string
- `--jwt-secret`: Secret key for token validation
- `--jwt-auto-refresh`: Enable automatic token refresh
- `--jwt-refresh-endpoint`: Token refresh URL
- `--jwt-issuer`: Token issuer validation
- `--jwt-audience`: Token audience validation

### API Key Authentication:
```bash
# API key in header (default)
pulzr https://httpbin.org/headers --api-key "abc123" \
      --api-key-header "X-API-Key" -c 25 -d 300

# API key in query parameter
pulzr https://httpbin.org/get --api-key "abc123" \
      --api-key-location query --api-key-header "apikey" \
      --webui -c 30 -d 400

# API key as Bearer token
pulzr https://httpbin.org/bearer --api-key "abc123" \
      --api-key-location bearer --webui --open-browser -c 40 -d 500
```

**API Key Locations:**
- **Header**: Custom header name (default: `X-API-Key`)
- **Query**: URL query parameter
- **Bearer**: Authorization header with Bearer format

### Security Best Practices:
- **Token Security**: Tokens are not logged in debug mode
- **Automatic Refresh**: Prevents authentication failures during long tests
- **Multiple Methods**: Use different auth methods for different endpoints
- **Validation**: Built-in token validation and error handling

## Prometheus Export & Monitoring

Export load testing metrics to Prometheus for advanced monitoring and alerting.

### Prometheus Features:
- **Standard Metrics**: Request counts, response times, error rates
- **Custom Labels**: Endpoint, method, status code labeling
- **Real-time Export**: Live metrics during test execution
- **Grafana Integration**: Compatible with Grafana dashboards
- **Multiple Formats**: Counter, Histogram, and Gauge metrics

### Prometheus Setup:
```bash
# Enable Prometheus metrics endpoint
pulzr https://httpbin.org/get --prometheus --webui \
      -c 50 -d 300

# Custom Prometheus port
pulzr https://httpbin.org/get --prometheus --prometheus-port 9090 \
      --webui --open-browser -c 75 -d 600

# Prometheus with scenario testing
pulzr --scenario test_scenario.json --prometheus \
      -c 100 -d 900 --webui
```

**Available Metrics:**
- `pulzr_requests_total`: Total number of HTTP requests
- `pulzr_request_duration_seconds`: Request duration histogram
- `pulzr_response_time_p50`: 50th percentile response time
- `pulzr_response_time_p90`: 90th percentile response time
- `pulzr_response_time_p95`: 95th percentile response time
- `pulzr_response_time_p99`: 99th percentile response time
- `pulzr_error_rate`: Current error rate percentage
- `pulzr_requests_per_second`: Current requests per second

### Grafana Dashboard Integration:
```bash
# List available dashboards
pulzr --list-dashboards

# Get dashboard information
pulzr --dashboard-info pulzr-overview

# Generate import instructions
pulzr --dashboard-import pulzr-overview

# Validate dashboard configuration
pulzr --dashboard-validate pulzr-overview
```

**Pre-built Dashboards:**
- **Pulzr Overview**: Comprehensive load testing dashboard
- **Performance Details**: Detailed response time and throughput analysis
- **Error Analysis**: Error rate monitoring and debugging dashboard

### Integration Example:
```yaml
# Prometheus configuration (prometheus.yml)
scrape_configs:
  - job_name: 'pulzr-load-tests'
    static_configs:
      - targets: ['localhost:9621']
    scrape_interval: 5s
```

## Memory Optimization

Advanced memory management for long-running and high-throughput load tests.

### Memory Optimization Features:
- **Streaming Statistics**: Bounded memory usage with rolling windows
- **Smart Aggregation**: Time-based data bucketing (minute/hour intervals)
- **Automatic Cleanup**: Configurable cleanup intervals and retention
- **Multiple Profiles**: Pre-configured optimization profiles
- **Memory Monitoring**: Real-time memory usage tracking
- **Performance Tuning**: Optimized for different use cases

### Memory Profiles:
```bash
# Streaming profile (default for long tests)
pulzr https://httpbin.org/get --memory-profile streaming \
      -c 100 -d 3600 --webui

# Low memory profile (minimal RAM usage)
pulzr https://httpbin.org/get --memory-profile low-memory \
      -c 50 -d 1800 --max-results 1000

# High throughput profile (performance optimized)
pulzr https://httpbin.org/get --memory-profile high-throughput \
      -c 200 -r 500 -d 900 --webui

# Custom memory configuration
pulzr https://httpbin.org/get --memory-optimize \
      --max-results 5000 --max-result-age 300 --auto-cleanup \
      --cleanup-interval 60 -c 150 -d 1200
```

**Memory Profile Configurations:**

| Profile | Max Results | Result Age | Cleanup | Best For |
|---------|-------------|------------|---------|----------|
| `default` | 10,000 | 3600s | Manual | General testing |
| `streaming` | 5,000 | 1800s | Auto (300s) | Long tests |
| `low-memory` | 1,000 | 900s | Auto (60s) | Limited RAM |
| `high-throughput` | 20,000 | 7200s | Auto (600s) | High performance |

### Memory Configuration Options:
- `--memory-profile`: Pre-configured optimization profile
- `--memory-optimize`: Enable memory optimization features
- `--max-results`: Maximum results kept in memory
- `--max-result-age`: Maximum age of results in seconds
- `--auto-cleanup`: Enable automatic memory cleanup
- `--cleanup-interval`: Cleanup interval in seconds

### Memory Monitoring:
```bash
# Memory optimization demo with monitoring
pulzr --memory-optimize

# Show current memory usage during tests
pulzr https://httpbin.org/get --webui --memory-profile streaming \
      -c 100 -d 1800 --show-memory-stats
```

**Memory Monitoring Features:**
- **System Memory**: Total and available system RAM
- **Process Memory**: Current Pulzr memory usage
- **Optimization Status**: Active memory settings and cleanup intervals
- **Usage Trends**: Memory usage patterns over time

## HTTP/2 Support

Modern HTTP/2 protocol support for enhanced performance and efficiency.

### HTTP/2 Features:
- **Multiplexing**: Multiple requests over single connection
- **Header Compression**: Reduced bandwidth usage with HPACK
- **Binary Framing**: Efficient binary protocol processing
- **Configurable Settings**: Custom window sizes and frame sizes
- **Prior Knowledge**: Force HTTP/2 without negotiation
- **Performance Monitoring**: Protocol-specific metrics

### HTTP/2 Configuration:
```bash
# Enable HTTP/2 with fallback
pulzr https://httpbin.org/get --http2 --webui -c 50 -d 300

# Force HTTP/2 prior knowledge
pulzr https://httpbin.org/get --http2 --http2-prior-knowledge \
      -c 100 -d 600 --webui

# Force HTTP/1.1 only
pulzr https://httpbin.org/get --http1-only --webui -c 75 -d 400

# Custom HTTP/2 window sizes
pulzr https://httpbin.org/get --http2 \
      --http2-initial-connection-window-size 1048576 \
      --http2-initial-stream-window-size 262144 \
      --http2-max-frame-size 32768 \
      --webui -c 80 -d 500
```

### HTTP/2 Configuration Options:
- `--http2`: Enable HTTP/2 support with fallback
- `--http2-prior-knowledge`: Force HTTP/2 without negotiation
- `--http1-only`: Force HTTP/1.1 only (disable HTTP/2)
- `--http2-initial-connection-window-size`: Connection window size in bytes
- `--http2-initial-stream-window-size`: Stream window size in bytes  
- `--http2-max-frame-size`: Maximum frame size in bytes

### Protocol Information:
During test execution, Pulzr displays active protocol information:
```
Protocol: HTTP/2 (with fallback)
Features: HTTP/2 multiplexing, Header compression, Binary framing, Adaptive window, Keep-alive
```

### Performance Benefits:
- **Connection Efficiency**: Fewer connections, reduced overhead
- **Bandwidth Optimization**: Header compression reduces data transfer
- **Latency Reduction**: Multiplexing eliminates head-of-line blocking
- **Server Push**: Compatible with HTTP/2 server push (if supported)

### HTTP/2 Best Practices:
- **High Concurrency**: HTTP/2 performs better with higher concurrency
- **Single Domain**: Most effective when testing single domains/hosts
- **Window Tuning**: Optimize window sizes for your specific use case
- **Fallback Support**: Allow fallback for broader compatibility

## Distributed Load Testing

Scale your load tests across multiple machines with Pulzr's distributed architecture. Perfect for testing high-capacity systems, simulating geographically distributed traffic, and breaking through single-machine limitations.

### Distributed Features
- **Coordinator-Worker Architecture**: Central coordination with distributed execution
- **Automatic Load Distribution**: Intelligent request distribution across workers
- **Real-time Metrics Aggregation**: Centralized statistics from all workers
- **WebSocket Communication**: Low-latency coordination protocol
- **Load Balancing Algorithms**: Round-robin, load-based, and custom distribution
- **Worker Auto-Discovery**: Automatic worker registration and management
- **Fault Tolerance**: Automatic worker failure detection and recovery
- **WebUI Integration**: Real-time monitoring of distributed tests
- **Geographic Distribution**: Deploy workers across different regions/networks

### Architecture Overview

```
┌─────────────────┐    WebSocket    ┌─────────────────┐
│   Coordinator   │◄───────────────►│    Worker 1     │
│  (Control Hub)  │                 │ (Test Execution)│
│                 │    WebSocket    ┌─────────────────┐
│ • Load Balancing│◄───────────────►│    Worker 2     │
│ • Metrics Agg.  │                 │ (Test Execution)│
│ • WebUI Dashboard│   WebSocket    ┌─────────────────┐
│ • Test Control  │◄───────────────►│    Worker N     │
└─────────────────┘                 │ (Test Execution)│
                                    └─────────────────┘
```

### Quick Start Guide

#### 1. **Start the Coordinator**
```bash
# Basic coordinator setup
pulzr --coordinator --coordinator-port 9630

# Coordinator with WebUI monitoring
pulzr --coordinator --webui --open-browser --coordinator-port 9630 --max-workers 20

# Production coordinator with advanced settings
pulzr --coordinator --coordinator-port 9630 --max-workers 50 \
      --webui --websocket --output distributed_test_results
```

#### 2. **Connect Workers** (run on different machines)
```bash
# Basic worker connection
pulzr --worker --coordinator-host 192.168.1.100 --coordinator-port 9630

# High-performance worker
pulzr --worker --coordinator-host coordinator.example.com \
      --worker-id "gpu-server-1" --max-concurrent 500 --max-rps 1000

# Regional worker with specific configuration
pulzr --worker --coordinator-host 10.0.1.100 --coordinator-port 9630 \
      --worker-id "us-east-worker" --max-concurrent 200 --max-rps 400
```

#### 3. **Run Distributed Tests** (from coordinator)
```bash
# Automatic distributed load test
pulzr https://api.example.com --coordinator --webui --open-browser \
      -c 500 -r 1000 -d 1800

# Distributed scenario testing
pulzr --scenario production_test.json --coordinator --webui \
      -c 1000 -r 2000 -d 3600 --output large_scale_test

# Multi-endpoint distributed testing
pulzr --endpoints api_suite.json --coordinator --webui --open-browser \
      -c 750 -r 1500 -d 2400
```

### Coordinator Configuration

| Parameter | Description | Default | Example |
|-----------|-------------|---------|---------|
| `--coordinator` | Enable coordinator mode | false | `--coordinator` |
| `--coordinator-port` | Listening port for workers | 9630 | `--coordinator-port 9630` |
| `--max-workers` | Maximum concurrent workers | 100 | `--max-workers 50` |
| `--auto-balance-load` | Enable automatic load balancing | true | `--auto-balance-load` |
| `--heartbeat-timeout` | Worker timeout in seconds | 30 | `--heartbeat-timeout 60` |

### Worker Configuration

| Parameter | Description | Default | Example |
|-----------|-------------|---------|---------|
| `--worker` | Enable worker mode | false | `--worker` |
| `--coordinator-host` | Coordinator hostname/IP | localhost | `--coordinator-host 10.0.1.100` |
| `--coordinator-port` | Coordinator port | 9630 | `--coordinator-port 9630` |
| `--worker-id` | Unique worker identifier | auto-generated | `--worker-id "worker-gpu-1"` |
| `--max-concurrent` | Max concurrent requests | 100 | `--max-concurrent 500` |
| `--max-rps` | Max requests per second | unlimited | `--max-rps 1000` |

### Load Distribution Algorithms

#### **1. Round Robin Distribution** (Default)
Evenly distributes requests across all available workers:
```bash
# Coordinator automatically balances 1000 concurrent across all workers
pulzr https://httpbin.org/get --coordinator --webui -c 1000 -d 600
```
- **Best for**: Uniform worker capabilities
- **Distribution**: Equal load per worker
- **Use case**: Homogeneous infrastructure

#### **2. Load-Based Distribution**
Dynamically adjusts based on worker performance and current load:
```bash
# Intelligent load balancing based on worker performance
pulzr https://httpbin.org/get --coordinator --load-strategy load-based \
      --webui -c 1000 -r 2000 -d 1800
```
- **Best for**: Mixed worker capabilities
- **Distribution**: Performance-weighted allocation
- **Use case**: Heterogeneous infrastructure

#### **3. Weighted Distribution**
Manual weight assignment for custom load distribution:
```bash
# Custom worker weights (worker-1: 50%, worker-2: 30%, worker-3: 20%)
pulzr https://httpbin.org/get --coordinator --load-strategy weighted \
      --worker-weights "worker-1:0.5,worker-2:0.3,worker-3:0.2" \
      --webui -c 1000 -d 900
```
- **Best for**: Known performance characteristics
- **Distribution**: User-defined weights
- **Use case**: Capacity planning and testing

### Real-time Metrics Aggregation

The coordinator automatically aggregates metrics from all workers:

**Global Metrics:**
- **Total Requests**: Cumulative requests across all workers
- **Aggregated RPS**: Combined requests per second
- **Response Time Percentiles**: Weighted percentiles (P50, P90, P95, P99)
- **Success/Error Rates**: Combined success and failure statistics
- **Throughput**: Total bandwidth across all workers

**Per-Worker Metrics:**
- **Individual Performance**: Each worker's specific metrics
- **Load Distribution**: Current request allocation per worker
- **Health Status**: Worker connectivity and performance status
- **Resource Usage**: CPU, memory, and connection utilization

### Geographic Distribution Examples

#### **Multi-Region Setup**
```bash
# US East Coordinator (Virginia)
pulzr --coordinator --coordinator-port 9630 --webui \
      --coordinator-id "us-east-coordinator"

# EU West Worker (Ireland)
pulzr --worker --coordinator-host us-east.example.com \
      --worker-id "eu-west-worker" --max-concurrent 300

# Asia Pacific Worker (Singapore)
pulzr --worker --coordinator-host us-east.example.com \
      --worker-id "apac-worker" --max-concurrent 250

# Distributed global test
pulzr https://global-api.example.com --coordinator \
      --webui --open-browser -c 1500 -r 3000 -d 3600 \
      --output global_load_test
```

#### **Hybrid Cloud Setup**
```bash
# On-premises coordinator
pulzr --coordinator --coordinator-port 9630 --max-workers 25

# AWS worker (high-performance instance)
pulzr --worker --coordinator-host corporate.example.com \
      --worker-id "aws-c5.4xlarge" --max-concurrent 800 --max-rps 1500

# Azure worker (standard instance)
pulzr --worker --coordinator-host corporate.example.com \
      --worker-id "azure-d4s-v3" --max-concurrent 400 --max-rps 800

# Google Cloud worker (CPU-optimized)
pulzr --worker --coordinator-host corporate.example.com \
      --worker-id "gcp-c2-standard-8" --max-concurrent 600 --max-rps 1200
```

### Fault Tolerance & Recovery

#### **Automatic Worker Recovery**
- **Heartbeat Monitoring**: Regular health checks (default: 10 seconds)
- **Automatic Failover**: Redistribute load when workers disconnect
- **Graceful Reconnection**: Workers automatically rejoin when available
- **Load Rebalancing**: Dynamic adjustment when worker count changes

#### **Network Resilience**
```bash
# Coordinator with extended timeouts for unstable networks
pulzr --coordinator --heartbeat-timeout 60 --connection-timeout 30 \
      --webui --coordinator-port 9630

# Worker with connection retry
pulzr --worker --coordinator-host coordinator.example.com \
      --connection-retry-interval 10 --max-connection-retries 5 \
      --worker-id "resilient-worker"
```

### Use Cases & Best Practices

#### **Large-Scale Load Testing**
```bash
# 10,000 concurrent users across 20 workers
pulzr https://httpbin.org/get --coordinator --webui --open-browser \
      -c 10000 -r 5000 -d 3600 --output massive_load_test
```

#### **Geographic Performance Testing**
```bash
# Test CDN and edge performance from multiple regions
pulzr --scenario cdn_test.json --coordinator --webui \
      -c 2000 -d 1800 --output cdn_performance_test
```

#### **Microservices Stress Testing**
```bash
# Distributed testing of microservices architecture
pulzr --endpoints microservices.json --coordinator --webui \
      -c 5000 -r 10000 -d 7200 --output microservices_stress_test
```

#### **CI/CD Distributed Testing**
```bash
# Automated distributed testing in CI pipeline
pulzr $API_ENDPOINT --coordinator --headless \
      --output-format compact -c 1000 -d 300 --output ci_distributed_test
```

### Performance Tips

- **Network Bandwidth**: Ensure adequate bandwidth between coordinator and workers
- **Worker Placement**: Distribute workers across different networks/regions for realistic testing
- **Resource Monitoring**: Monitor coordinator and worker resource usage during tests
- **Load Balancing**: Use load-based distribution for heterogeneous worker environments
- **WebUI Monitoring**: Use coordinator WebUI for real-time visibility into distributed tests
- **Gradual Scaling**: Start with fewer workers and scale up to identify bottlenecks

### Important Considerations

- **Coordinator Capacity**: The coordinator can handle up to 100 workers by default
- **Network Requirements**: Stable WebSocket connections between coordinator and workers
- **Synchronization**: All workers should have synchronized clocks for accurate metrics
- **Security**: Use secure networks or VPN for distributed setups across untrusted networks
- **Resource Planning**: Factor in network overhead and coordination latency

## Real-World Examples

### API Testing with WebUI
```bash
# Comprehensive API test with browser dashboard
pulzr https://httpbin.org/get \
      --webui --open-browser -c 20 -r 50 -d 300 \
      --random-ua --output api_test_results

# E-commerce API stress test
pulzr https://httpbin.org/post --webui --open-browser \
      --method post --payload '{"category": "electronics"}' \
      --headers "Authorization: Bearer token123" \
      -c 50 -r 100 -d 600
```

### Performance Benchmarking
```bash
# High-throughput performance test
pulzr https://httpbin.org/get -c 200 -r 1000 -d 300 --headless \
      --output performance_benchmark

# Sustained load test (30 minutes)
pulzr https://httpbin.org/get --webui --open-browser \
      -c 25 -r 50 -d 1800 --random-ua
```

### Stealth & Security Testing
```bash
# Low-profile reconnaissance
pulzr https://httpbin.org/user-agent --random-ua \
      -c 2 -r 1 -d 3600 --output stealth_scan

# User-Agent rotation test
echo -e "Bot-Scanner/1.0\nSecurity-Audit/2.1\nPenTest-Tool/1.5" > custom_agents.txt
pulzr https://httpbin.org/user-agent --ua-file custom_agents.txt \
      --webui -c 5 -r 3 -d 600
```

### CI/CD Integration
```bash
# Automated testing in CI pipeline - compact output
pulzr $API_ENDPOINT --headless --output-format compact \
      -c 10 -r 20 -d 60 --output ci_test_results --timeout 5

# Quiet automation for scripts
pulzr $API_ENDPOINT --quiet -c 5 -d 30

# Health check with WebSocket monitoring
pulzr https://httpbin.org/get --websocket --headless \
      -c 5 -r 10 -d 120 | curl -X POST -d @- $MONITORING_WEBHOOK

# Minimal output for log parsing
pulzr $API_ENDPOINT --output-format minimal --headless \
      -c 10 -d 60 >> load_test.log

# Request count mode for CI testing
pulzr $API_ENDPOINT --headless -c 5 -n 100 --output ci_results --timeout 10
```

### Distributed Load Testing
```bash
# Large-scale e-commerce platform testing (Black Friday simulation)
# Coordinator (main control server)
pulzr --coordinator --webui --open-browser --coordinator-port 9630 \
      --max-workers 50 --output black_friday_test

# Multi-region workers
# US East worker (Virginia)
pulzr --worker --coordinator-host coordinator.company.com \
      --worker-id "us-east-1" --max-concurrent 1000 --max-rps 2000

# EU West worker (Ireland)  
pulzr --worker --coordinator-host coordinator.company.com \
      --worker-id "eu-west-1" --max-concurrent 800 --max-rps 1500

# Asia Pacific worker (Singapore)
pulzr --worker --coordinator-host coordinator.company.com \
      --worker-id "apac-1" --max-concurrent 600 --max-rps 1200

# Execute distributed test (run from coordinator)
pulzr --scenario ecommerce_load_test.json --coordinator --webui \
      -c 5000 -r 10000 -d 3600 --output distributed_ecommerce_test

# Global API performance testing
# Coordinator for global CDN testing
pulzr --coordinator --webui --coordinator-port 9630 --max-workers 20

# Regional workers testing different CDN edges
pulzr https://api.global-service.com --coordinator --webui \
      -c 2000 -r 4000 -d 1800 --output global_cdn_performance

# Microservices stress testing with mixed workloads
pulzr --endpoints microservices_suite.json --coordinator --webui \
      -c 3000 -r 6000 -d 2400 --output microservices_distributed_test

# Financial services compliance testing (high-security, multi-region)
pulzr --scenario fintech_compliance.json --coordinator --webui \
      -c 1500 -d 7200 --output compliance_distributed_test \
      --random-ua --output-format compact
```

## License

MIT License