|
15 | 15 |
|
16 | 16 | package com.rabbitmq.perf; |
17 | 17 |
|
| 18 | +import com.rabbitmq.client.ConnectionFactory; |
| 19 | +import com.rabbitmq.client.DefaultSaslConfig; |
| 20 | +import com.rabbitmq.client.impl.ClientVersion; |
| 21 | +import com.rabbitmq.client.impl.nio.NioParams; |
| 22 | +import io.micrometer.core.instrument.composite.CompositeMeterRegistry; |
| 23 | +import org.apache.commons.cli.*; |
| 24 | +import org.slf4j.Logger; |
| 25 | +import org.slf4j.LoggerFactory; |
| 26 | + |
| 27 | +import javax.net.ssl.SSLContext; |
18 | 28 | import java.io.*; |
19 | 29 | import java.nio.charset.Charset; |
20 | 30 | import java.security.NoSuchAlgorithmException; |
21 | 31 | import java.text.SimpleDateFormat; |
22 | | -import java.util.Calendar; |
23 | | -import java.util.HashMap; |
24 | | -import java.util.List; |
25 | | -import java.util.Locale; |
26 | | -import java.util.Map; |
27 | | -import java.util.Properties; |
| 32 | +import java.util.*; |
28 | 33 | import java.util.concurrent.SynchronousQueue; |
29 | 34 | import java.util.concurrent.ThreadPoolExecutor; |
30 | 35 | import java.util.concurrent.TimeUnit; |
31 | 36 | import java.util.function.Function; |
32 | 37 |
|
33 | | -import com.rabbitmq.client.impl.ClientVersion; |
34 | | -import com.rabbitmq.client.impl.nio.NioParams; |
35 | | -import io.micrometer.core.instrument.MeterRegistry; |
36 | | -import io.micrometer.core.instrument.composite.CompositeMeterRegistry; |
37 | | -import org.apache.commons.cli.CommandLine; |
38 | | -import org.apache.commons.cli.CommandLineParser; |
39 | | -import org.apache.commons.cli.GnuParser; |
40 | | -import org.apache.commons.cli.HelpFormatter; |
41 | | -import org.apache.commons.cli.Option; |
42 | | -import org.apache.commons.cli.Options; |
43 | | -import org.apache.commons.cli.ParseException; |
44 | | - |
45 | | -import com.rabbitmq.client.ConnectionFactory; |
46 | | -import com.rabbitmq.client.DefaultSaslConfig; |
47 | | -import org.slf4j.Logger; |
48 | | -import org.slf4j.LoggerFactory; |
49 | | - |
50 | | -import javax.net.ssl.SSLContext; |
51 | | - |
52 | 38 | import static com.rabbitmq.perf.OptionsUtils.forEach; |
53 | 39 | import static java.lang.String.format; |
54 | 40 | import static java.util.Arrays.asList; |
@@ -562,176 +548,6 @@ private static String getExchangeName(CommandLineProxy cmd, String def) { |
562 | 548 | return exchangeName; |
563 | 549 | } |
564 | 550 |
|
565 | | - private static class PrintlnStats extends Stats { |
566 | | - private final boolean sendStatsEnabled; |
567 | | - private final boolean recvStatsEnabled; |
568 | | - private final boolean returnStatsEnabled; |
569 | | - private final boolean confirmStatsEnabled; |
570 | | - private final boolean legacyMetrics; |
571 | | - private final boolean useMillis; |
572 | | - |
573 | | - private final String testID; |
574 | | - private final PrintWriter out; |
575 | | - |
576 | | - public PrintlnStats(String testID, long interval, |
577 | | - boolean sendStatsEnabled, boolean recvStatsEnabled, |
578 | | - boolean returnStatsEnabled, boolean confirmStatsEnabled, |
579 | | - boolean legacyMetrics, boolean useMillis, |
580 | | - PrintWriter out, MeterRegistry registry, String metricsPrefix) { |
581 | | - super(interval, useMillis, registry, metricsPrefix); |
582 | | - this.sendStatsEnabled = sendStatsEnabled; |
583 | | - this.recvStatsEnabled = recvStatsEnabled; |
584 | | - this.returnStatsEnabled = returnStatsEnabled; |
585 | | - this.confirmStatsEnabled = confirmStatsEnabled; |
586 | | - this.testID = testID; |
587 | | - this.legacyMetrics = legacyMetrics; |
588 | | - this.useMillis = useMillis; |
589 | | - this.out = out; |
590 | | - if (out != null) { |
591 | | - out.printf("id,time (s),published (msg/s),returned (msg/s)," + |
592 | | - "confirmed (msg/s),nacked (msg/s)," + |
593 | | - "received (msg/s),min latency (%s),median latency (%s)," + |
594 | | - "75th p. latency (%s),95th p. latency (%s),99th p. latency (%s)%n", |
595 | | - units(), units(), units(), units(), units()); |
596 | | - } |
597 | | - } |
598 | | - |
599 | | - @Override |
600 | | - protected void report(long now) { |
601 | | - String output = "id: " + testID + ", "; |
602 | | - |
603 | | - double ratePublished = 0.0; |
604 | | - double rateReturned = 0.0; |
605 | | - double rateConfirmed = 0.0; |
606 | | - double rateNacked = 0.0; |
607 | | - double rateConsumed = 0.0; |
608 | | - |
609 | | - if (sendStatsEnabled) { |
610 | | - ratePublished = rate(sendCountInterval, elapsedInterval); |
611 | | - published(ratePublished); |
612 | | - } |
613 | | - if (sendStatsEnabled && returnStatsEnabled) { |
614 | | - rateReturned = rate(returnCountInterval, elapsedInterval); |
615 | | - returned(rateReturned); |
616 | | - } |
617 | | - if (sendStatsEnabled && confirmStatsEnabled) { |
618 | | - rateConfirmed = rate(confirmCountInterval, elapsedInterval); |
619 | | - confirmed(rateConfirmed); |
620 | | - } |
621 | | - if (sendStatsEnabled && confirmStatsEnabled) { |
622 | | - rateNacked = rate(nackCountInterval, elapsedInterval); |
623 | | - nacked(rateNacked); |
624 | | - } |
625 | | - if (recvStatsEnabled) { |
626 | | - rateConsumed = rate(recvCountInterval, elapsedInterval); |
627 | | - received(rateConsumed); |
628 | | - } |
629 | | - |
630 | | - output += "time: " + format("%.3f", (now - startTime)/1000.0) + "s"; |
631 | | - output += |
632 | | - getRate("sent", ratePublished, sendStatsEnabled) + |
633 | | - getRate("returned", rateReturned, sendStatsEnabled && returnStatsEnabled) + |
634 | | - getRate("confirmed", rateConfirmed, sendStatsEnabled && confirmStatsEnabled) + |
635 | | - getRate("nacked", rateNacked, sendStatsEnabled && confirmStatsEnabled) + |
636 | | - getRate("received", rateConsumed, recvStatsEnabled); |
637 | | - |
638 | | - if (legacyMetrics) { |
639 | | - output += (latencyCountInterval > 0 ? |
640 | | - ", min/avg/max latency: " + |
641 | | - minLatency/1000L + "/" + |
642 | | - cumulativeLatencyInterval / (1000L * latencyCountInterval) + "/" + |
643 | | - maxLatency/1000L + " µs " : |
644 | | - ""); |
645 | | - } else { |
646 | | - output += (latencyCountInterval > 0 ? |
647 | | - ", min/median/75th/95th/99th latency: " |
648 | | - + div(latency.getSnapshot().getMin()) + "/" |
649 | | - + div(latency.getSnapshot().getMedian()) + "/" |
650 | | - + div(latency.getSnapshot().get75thPercentile()) + "/" |
651 | | - + div(latency.getSnapshot().get95thPercentile()) + "/" |
652 | | - + div(latency.getSnapshot().get99thPercentile()) + " " + units() : |
653 | | - ""); |
654 | | - } |
655 | | - |
656 | | - System.out.println(output); |
657 | | - if (out != null) { |
658 | | - out.println(testID + "," + format("%.3f", (now - startTime)/1000.0) + "," + |
659 | | - rate(ratePublished, sendStatsEnabled)+ "," + |
660 | | - rate(rateReturned, sendStatsEnabled && returnStatsEnabled)+ "," + |
661 | | - rate(rateConfirmed, sendStatsEnabled && confirmStatsEnabled)+ "," + |
662 | | - rate(rateNacked, sendStatsEnabled && confirmStatsEnabled)+ "," + |
663 | | - rate(rateConsumed, recvStatsEnabled) + "," + |
664 | | - (latencyCountInterval > 0 ? |
665 | | - div(latency.getSnapshot().getMin()) + "," + |
666 | | - div(latency.getSnapshot().getMedian()) + "," + |
667 | | - div(latency.getSnapshot().get75thPercentile()) + "," + |
668 | | - div(latency.getSnapshot().get95thPercentile()) + "," + |
669 | | - div(latency.getSnapshot().get99thPercentile()) |
670 | | - : ",,,,") |
671 | | - ); |
672 | | - } |
673 | | - |
674 | | - } |
675 | | - |
676 | | - private String units() { |
677 | | - if (useMillis) { |
678 | | - return "ms"; |
679 | | - } else { |
680 | | - return "µs"; |
681 | | - } |
682 | | - } |
683 | | - |
684 | | - private long div(double p) { |
685 | | - if (useMillis) { |
686 | | - return (long)p; |
687 | | - } else { |
688 | | - return (long)(p / 1000L); |
689 | | - } |
690 | | - } |
691 | | - |
692 | | - private String getRate(String descr, double rate, boolean display) { |
693 | | - if (display) { |
694 | | - return ", " + descr + ": " + formatRate(rate) + " msg/s"; |
695 | | - } else { |
696 | | - return ""; |
697 | | - } |
698 | | - } |
699 | | - |
700 | | - public void printFinal() { |
701 | | - long now = System.currentTimeMillis(); |
702 | | - |
703 | | - System.out.println("id: " + testID + ", sending rate avg: " + |
704 | | - formatRate(sendCountTotal * 1000.0 / (now - startTime)) + |
705 | | - " msg/s"); |
706 | | - |
707 | | - long elapsed = now - startTime; |
708 | | - if (elapsed > 0) { |
709 | | - System.out.println("id: " + testID + ", receiving rate avg: " + |
710 | | - formatRate(recvCountTotal * 1000.0 / elapsed) + |
711 | | - " msg/s"); |
712 | | - } |
713 | | - } |
714 | | - |
715 | | - private static String formatRate(double rate) { |
716 | | - if (rate == 0.0) return format("%d", (long)rate); |
717 | | - else if (rate < 1) return format("%1.2f", rate); |
718 | | - else if (rate < 10) return format("%1.1f", rate); |
719 | | - else return format("%d", (long)rate); |
720 | | - } |
721 | | - |
722 | | - private static String rate(double rate, boolean display) { |
723 | | - if (display) { |
724 | | - return formatRate(rate); |
725 | | - } else { |
726 | | - return ""; |
727 | | - } |
728 | | - } |
729 | | - |
730 | | - private static double rate(long count, long elapsed) { |
731 | | - return 1000.0 * count / elapsed; |
732 | | - } |
733 | | - } |
734 | | - |
735 | 551 | private static void versionInformation() { |
736 | 552 | String lineSeparator = System.getProperty("line.separator"); |
737 | 553 | String version = format( |
|
0 commit comments