adelapena commented on a change in pull request #1202:
URL: https://github.com/apache/cassandra/pull/1202#discussion_r718575379
##########
File path: src/java/org/apache/cassandra/streaming/StreamManager.java
##########
@@ -62,41 +63,62 @@ public static StreamRateLimiter
getRateLimiter(InetAddressAndPort peer)
public static class StreamRateLimiter
{
- private static final double BYTES_PER_MEGABIT = (1024 * 1024) / 8; //
from bits
- private static final RateLimiter limiter =
RateLimiter.create(Double.MAX_VALUE);
- private static final RateLimiter interDCLimiter =
RateLimiter.create(Double.MAX_VALUE);
+ public static final double BYTES_PER_MEGABIT = (1024 * 1024) / 8; //
from bits
+ private static final RateLimiter limiter =
RateLimiter.create(calculateRateInBytes());
+ private static final RateLimiter interDCLimiter =
RateLimiter.create(calculateInterDCRateInBytes());
private final boolean isLocalDC;
public StreamRateLimiter(InetAddressAndPort peer)
{
- double throughput =
DatabaseDescriptor.getStreamThroughputOutboundMegabitsPerSec() *
BYTES_PER_MEGABIT;
- mayUpdateThroughput(throughput, limiter);
-
- double interDCThroughput =
DatabaseDescriptor.getInterDCStreamThroughputOutboundMegabitsPerSec() *
BYTES_PER_MEGABIT;
- mayUpdateThroughput(interDCThroughput, interDCLimiter);
-
if (DatabaseDescriptor.getLocalDataCenter() != null &&
DatabaseDescriptor.getEndpointSnitch() != null)
isLocalDC = DatabaseDescriptor.getLocalDataCenter().equals(
DatabaseDescriptor.getEndpointSnitch().getDatacenter(peer));
else
isLocalDC = true;
}
- private void mayUpdateThroughput(double limit, RateLimiter rateLimiter)
- {
- // if throughput is set to 0, throttling is disabled
- if (limit == 0)
- limit = Double.MAX_VALUE;
- if (rateLimiter.getRate() != limit)
- rateLimiter.setRate(limit);
- }
-
public void acquire(int toTransfer)
{
limiter.acquire(toTransfer);
if (!isLocalDC)
interDCLimiter.acquire(toTransfer);
}
+
+ public static synchronized void updateThroughput()
+ {
+ limiter.setRate(calculateRateInBytes());
+ }
+
+ public static synchronized void updateInterDCThroughput()
+ {
+ interDCLimiter.setRate(calculateInterDCRateInBytes());
+ }
+
+ private static double calculateRateInBytes()
+ {
+ return
DatabaseDescriptor.getStreamThroughputOutboundMegabitsPerSec() *
BYTES_PER_MEGABIT > 0
+ ?
DatabaseDescriptor.getStreamThroughputOutboundMegabitsPerSec() *
BYTES_PER_MEGABIT
+ : Double.MAX_VALUE; // if throughput is set to 0,
throttling is disabled
+ }
+
+ private static double calculateInterDCRateInBytes()
+ {
+ return
DatabaseDescriptor.getInterDCStreamThroughputOutboundMegabitsPerSec() *
BYTES_PER_MEGABIT > 0
Review comment:
Good idea, done.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]