This method suppose to execute 20000 times, I check that everything is fine until this code is called.
I think the performance issue is with the StringBuilder; What I can tell is that when the loop is in the 275~ elements it blocks and it continue but very very slow (maybe son excepts in object creation). As soon I remove the call for this method everything run more faster and finish the loop; so the issue is here in this method. Can anyone enlighten me?
I tried to reuse the StringBuilder and it is not working.
private void sendTrafficDataToServer(InetAddress srcIp, InetAddress destIp, String protocolSource,
String protocolDest, int length, long epochTime, String sourceMac,
String destMac, String network, String _interface) throws MalformedURLException, IOException {
StringBuilder subtree = new StringBuilder(network);
//subtree.append(".").append(URLEncoder.encode(_interface, "UTF-8"));
//=====================================================================
// package protocol host source
String fqdnSource = srcIp.getCanonicalHostName().replaceAll("[.]", "+");
subtree.append(".").append(URLEncoder.encode(fqdnSource, "UTF-8"));
subtree.append(".").append(URLEncoder.encode(protocolSource, "UTF-8"));
StringBuilder message = new StringBuilder();
message.append("c=").append("packethostsrc").append("&");
message.append("s=").append(subtree).append("&");
message.append("t=").append(epochTime).append("&");
message.append("v=").append(length);
// send data to server
//ServerDataSource.insertData(message.toString(), hostname);
logger.info("Message sent: {}", message.toString());
logger.debug("Counter: {}", ++counter);
//=====================================================================
// package protocol host dest
String fqdnDest = destIp.getCanonicalHostName().replaceAll("[.]", "+");
subtree = subtree.delete(network.length(), subtree.length());
subtree.append(".").append(URLEncoder.encode(fqdnDest, "UTF-8"));
subtree.append(".").append(URLEncoder.encode(protocolDest, "UTF-8"));
message.setLength(0);
message.append("c=").append("packethostdest").append("&");
message.append("s=").append(subtree).append("&");
message.append("t=").append(epochTime).append("&");
message.append("v=").append(length);
// send data to server
//ServerDataSource.insertData(message.toString(), hostname);
//=====================================================================
// package protocol source
subtree = subtree.delete(network.length(), subtree.length());
subtree.append(".").append(URLEncoder.encode(protocolSource, "UTF-8"));
message.setLength(0);
message.append("c=").append("packetprotocolsrc").append("&");
message.append("s=").append(subtree).append("&");
message.append("t=").append(epochTime).append("&");
message.append("v=").append(length);
// send data to server
//ServerDataSource.insertData(message.toString(), hostname);
//=====================================================================
// package protocol dest
subtree = subtree.delete(network.length(), subtree.length());
subtree.append(".").append(URLEncoder.encode(protocolDest, "UTF-8"));
message.setLength(0);
message.append("c=").append("packetprotocoldest").append("&");
message.append("s=").append(subtree).append("&");
message.append("t=").append(epochTime).append("&");
message.append("v=").append(length);
// send data to server
//ServerDataSource.insertData(message.toString(), hostname);
//=====================================================================
// package conversation
subtree = subtree.delete(network.length(), subtree.length());
subtree.append(".").append(URLEncoder.encode(fqdnSource, "UTF-8"));
subtree.append(".").append(URLEncoder.encode(fqdnDest, "UTF-8"));
message.setLength(0);
message.append("c=").append("packetconversation").append("&");
message.append("s=").append(subtree).append("&");
message.append("t=").append(epochTime).append("&");
message.append("v=").append(length);
// send data to server
//ServerDataSource.insertData(message.toString(), hostname);
//=====================================================================
// package network card source
subtree = subtree.delete(network.length(), subtree.length());
subtree.append(".").append(URLEncoder.encode(sourceMac, "UTF-8"));
message.setLength(0);
message.append("c=").append("packetnetworkcardsrc").append("&");
message.append("s=").append(subtree).append("&");
message.append("t=").append(epochTime).append("&");
message.append("v=").append(length);
// send data to server
//ServerDataSource.insertData(message.toString(), hostname);
//=====================================================================
// package network card dest
subtree = subtree.delete(network.length(), subtree.length());
subtree.append(".").append(URLEncoder.encode(destMac, "UTF-8"));
message.setLength(0);
message.append("c=").append("packetnetworkcarddest").append("&");
message.append("s=").append(subtree).append("&");
message.append("t=").append(epochTime).append("&");
message.append("v=").append(length);
// send data to server
//ServerDataSource.insertData(message.toString(), hostname);
}