Solution: Use LinkedBlockingQueue with fixed capacity. The MAXQUEUESIZE is now set to 50,000. With the change, the system become stable.
Solution: Implemented more efficient way to compute header checksum. As a result, the throughout has more than doubled.See test results below. Used Cbench for testing.
Before:
RESULT: 16 switches 9 tests min/max/avg/stdev =
9598.35/10395.48/10193.23/225.24 responses/s
After:
RESULT: 16 switches 9 tests min/max/avg/stdev =
28767.44/32073.92/30335.74/999.70 responses/s
Solution: Transmit messages in a tight while loop until the Tx queue is empty.
Signed-off-by: Jason Ye <yisye@cisco.com>
// only 1 switch state listener
private ISwitchStateListener switchStateListener;
private AtomicInteger switchInstanceNumber;
+ private int MAXQUEUESIZE = 50000;
/*
* this thread monitors the switchEvents queue for new incoming events from
public void init() {
logger.debug("Initializing!");
this.switches = new ConcurrentHashMap<Long, ISwitch>();
- this.switchEvents = new LinkedBlockingQueue<SwitchEvent>();
+ this.switchEvents = new LinkedBlockingQueue<SwitchEvent>(MAXQUEUESIZE);
this.messageListeners = new ConcurrentHashMap<OFType, IMessageListener>();
this.switchStateListener = null;
this.switchInstanceNumber = new AtomicInteger(0);
running = true;
while (running) {
try {
- if (!transmitQ.isEmpty()) {
+ while (!transmitQ.isEmpty()) {
PriorityMessage pmsg = transmitQ.poll();
msgReadWriteService.asyncSend(pmsg.msg);
logger.trace("Message sent: {}", pmsg);
*/
short computeChecksum(byte[] data, int start) {
int sum = 0, carry = 0, finalSum = 0;
+ int wordData;
int end = start + this.getHeaderSize() / NetUtils.NumBitsInAByte
+ rawPayload.length;
int checksumStartByte = start + getfieldOffset(CHECKSUM)
if (i == checksumStartByte) {
continue;
}
- StringBuffer sbuffer = new StringBuffer();
- sbuffer.append(String.format("%02X", data[i]));
- if (i < (data.length - 1)) {
- sbuffer.append(String.format("%02X", data[i + 1]));
- }
- sum += Integer.valueOf(sbuffer.toString(), 16);
+ wordData = ((data[i] << 8) & 0xFF00) + (data[i + 1] & 0xFF);
+ sum = sum + wordData;
}
carry = (sum >> 16) & 0xFF;
finalSum = (sum & 0xFFFF) + carry;
int end = start + getHeaderLen();
short checkSum = (short) 0;
int sum = 0, carry = 0, finalSum = 0;
- int parsedHex = 0;
+ int wordData;
int checksumStart = start
+ (getfieldOffset(CHECKSUM) / NetUtils.NumBitsInAByte);
if (i == checksumStart) {
continue;
}
- StringBuffer sbuffer = new StringBuffer();
- sbuffer.append(String.format("%02X", data[i]));
- if (i < (data.length - 1)) {
- sbuffer.append(String.format("%02X", data[i + 1]));
- }
-
- parsedHex = Integer.valueOf(sbuffer.toString(), 16);
- sum += parsedHex;
+ wordData = ((data[i] << 8) & 0xFF00) + (data[i + 1] & 0xFF);
+ sum = sum + wordData;
}
carry = (sum >> 16) & 0xFF;
finalSum = (sum & 0xFFFF) + carry;