SSU: More synchronization in PeerState

This commit is contained in:
zzz
2015-05-30 14:25:40 +00:00
parent 4fdcb6ce29
commit f02b401b7a

View File

@ -172,23 +172,23 @@ class PeerState {
private long _consecutiveSmall; private long _consecutiveSmall;
/** when did we last check the MTU? */ /** when did we last check the MTU? */
//private long _mtuLastChecked; //private long _mtuLastChecked;
private long _mtuIncreases; private int _mtuIncreases;
private long _mtuDecreases; private int _mtuDecreases;
/** current round trip time estimate */ /** current round trip time estimate */
private volatile int _rtt; private int _rtt;
/** smoothed mean deviation in the rtt */ /** smoothed mean deviation in the rtt */
private volatile int _rttDeviation; private int _rttDeviation;
/** current retransmission timeout */ /** current retransmission timeout */
private volatile int _rto; private int _rto;
/** how many packets will be considered within the retransmission rate calculation */ /** how many packets will be considered within the retransmission rate calculation */
static final long RETRANSMISSION_PERIOD_WIDTH = 100; static final long RETRANSMISSION_PERIOD_WIDTH = 100;
private long _messagesReceived; private int _messagesReceived;
private long _messagesSent; private int _messagesSent;
private long _packetsTransmitted; private int _packetsTransmitted;
/** how many packets were retransmitted within the last RETRANSMISSION_PERIOD_WIDTH packets */ /** how many packets were retransmitted within the last RETRANSMISSION_PERIOD_WIDTH packets */
private long _packetsRetransmitted; private int _packetsRetransmitted;
/** how many packets were transmitted within the last RETRANSMISSION_PERIOD_WIDTH packets */ /** how many packets were transmitted within the last RETRANSMISSION_PERIOD_WIDTH packets */
//private long _packetsPeriodTransmitted; //private long _packetsPeriodTransmitted;
@ -196,8 +196,8 @@ class PeerState {
//private int _packetRetransmissionRate; //private int _packetRetransmissionRate;
/** how many dup packets were received within the last RETRANSMISSION_PERIOD_WIDTH packets */ /** how many dup packets were received within the last RETRANSMISSION_PERIOD_WIDTH packets */
private long _packetsReceivedDuplicate; private int _packetsReceivedDuplicate;
private long _packetsReceived; private int _packetsReceived;
/** list of InboundMessageState for active message */ /** list of InboundMessageState for active message */
private final Map<Long, InboundMessageState> _inboundMessages; private final Map<Long, InboundMessageState> _inboundMessages;
@ -621,7 +621,7 @@ class PeerState {
/** return the smoothed send transfer rate */ /** return the smoothed send transfer rate */
public int getSendBps() { return _sendBps; } public int getSendBps() { return _sendBps; }
public int getReceiveBps() { return _receiveBps; } public synchronized int getReceiveBps() { return _receiveBps; }
public int incrementConsecutiveFailedSends() { public int incrementConsecutiveFailedSends() {
synchronized(_outboundMessages) { synchronized(_outboundMessages) {
@ -774,8 +774,7 @@ class PeerState {
/** we received the message specified completely */ /** we received the message specified completely */
public void messageFullyReceived(Long messageId, int bytes) { messageFullyReceived(messageId, bytes, false); } public void messageFullyReceived(Long messageId, int bytes) { messageFullyReceived(messageId, bytes, false); }
/** FIXME synch */ public synchronized void messageFullyReceived(Long messageId, int bytes, boolean isForACK) {
public void messageFullyReceived(Long messageId, int bytes, boolean isForACK) {
if (bytes > 0) { if (bytes > 0) {
_receiveBytes += bytes; _receiveBytes += bytes;
//if (isForACK) //if (isForACK)
@ -1256,60 +1255,36 @@ class PeerState {
} }
/** we are resending a packet, so lets jack up the rto */ /** we are resending a packet, so lets jack up the rto */
public void messageRetransmitted(int packets) { public synchronized void messageRetransmitted(int packets) {
//long now = _context.clock().now();
//if (true || _retransmissionPeriodStart + 1000 <= now) {
_packetsRetransmitted += packets;
/*****
} else {
_packetRetransmissionRate = (int)((float)(0.9f*_packetRetransmissionRate) + (float)(0.1f*_packetsRetransmitted));
//_packetsPeriodTransmitted = _packetsTransmitted - _retransmissionPeriodStart;
_packetsPeriodRetransmitted = (int)_packetsRetransmitted;
_retransmissionPeriodStart = now;
_packetsRetransmitted = packets;
}
*****/
_context.statManager().addRateData("udp.congestionOccurred", _sendWindowBytes); _context.statManager().addRateData("udp.congestionOccurred", _sendWindowBytes);
_context.statManager().addRateData("udp.congestedRTO", _rto, _rttDeviation); _context.statManager().addRateData("udp.congestedRTO", _rto, _rttDeviation);
synchronized (this) { _packetsRetransmitted += packets;
congestionOccurred(); congestionOccurred();
adjustMTU(); adjustMTU();
}
//_rto *= 2;
} }
public void packetsTransmitted(int packets) { public synchronized void packetsTransmitted(int packets) {
//long now = _context.clock().now();
_packetsTransmitted += packets; _packetsTransmitted += packets;
//_packetsPeriodTransmitted += packets;
/*****
if (false && _retransmissionPeriodStart + 1000 <= now) {
_packetRetransmissionRate = (int)((float)(0.9f*_packetRetransmissionRate) + (float)(0.1f*_packetsRetransmitted));
_retransmissionPeriodStart = 0;
_packetsPeriodRetransmitted = (int)_packetsRetransmitted;
_packetsRetransmitted = 0;
}
*****/
} }
/** how long does it usually take to get a message ACKed? */ /** how long does it usually take to get a message ACKed? */
public int getRTT() { return _rtt; } public synchronized int getRTT() { return _rtt; }
/** how soon should we retransmit an unacked packet? */ /** how soon should we retransmit an unacked packet? */
public int getRTO() { return _rto; } public synchronized int getRTO() { return _rto; }
/** how skewed are the measured RTTs? */ /** how skewed are the measured RTTs? */
public long getRTTDeviation() { return _rttDeviation; } public synchronized int getRTTDeviation() { return _rttDeviation; }
public long getMessagesSent() { return _messagesSent; } public synchronized int getMessagesSent() { return _messagesSent; }
public long getMessagesReceived() { return _messagesReceived; } public synchronized int getMessagesReceived() { return _messagesReceived; }
public long getPacketsTransmitted() { return _packetsTransmitted; } public synchronized int getPacketsTransmitted() { return _packetsTransmitted; }
public long getPacketsRetransmitted() { return _packetsRetransmitted; } public synchronized int getPacketsRetransmitted() { return _packetsRetransmitted; }
//public long getPacketsPeriodTransmitted() { return _packetsPeriodTransmitted; } //public long getPacketsPeriodTransmitted() { return _packetsPeriodTransmitted; }
//public int getPacketsPeriodRetransmitted() { return _packetsPeriodRetransmitted; } //public int getPacketsPeriodRetransmitted() { return _packetsPeriodRetransmitted; }
/** avg number of packets retransmitted for every 100 packets */ /** avg number of packets retransmitted for every 100 packets */
//public long getPacketRetransmissionRate() { return _packetRetransmissionRate; } //public long getPacketRetransmissionRate() { return _packetRetransmissionRate; }
public long getPacketsReceived() { return _packetsReceived; } public synchronized int getPacketsReceived() { return _packetsReceived; }
public long getPacketsReceivedDuplicate() { return _packetsReceivedDuplicate; } public synchronized int getPacketsReceivedDuplicate() { return _packetsReceivedDuplicate; }
private static final int MTU_RCV_DISPLAY_THRESHOLD = 20; private static final int MTU_RCV_DISPLAY_THRESHOLD = 20;
/** 60 */ /** 60 */
@ -1322,7 +1297,7 @@ class PeerState {
/** /**
* @param size not including IP header, UDP header, MAC or IV * @param size not including IP header, UDP header, MAC or IV
*/ */
public void packetReceived(int size) { public synchronized void packetReceived(int size) {
_packetsReceived++; _packetsReceived++;
int minMTU; int minMTU;
if (_remoteIP.length == 4) { if (_remoteIP.length == 4) {
@ -2077,6 +2052,7 @@ class PeerState {
if (_remotePeer != null) if (_remotePeer != null)
buf.append(" ").append(_remotePeer.toBase64().substring(0,6)); buf.append(" ").append(_remotePeer.toBase64().substring(0,6));
buf.append(_isInbound? " IB " : " OB ");
long now = _context.clock().now(); long now = _context.clock().now();
buf.append(" recvAge: ").append(now-_lastReceiveTime); buf.append(" recvAge: ").append(now-_lastReceiveTime);
buf.append(" sendAge: ").append(now-_lastSendFullyTime); buf.append(" sendAge: ").append(now-_lastSendFullyTime);