Sidebar

QIE system uses a lot of CPU when processing large files, how do I fix this?

0 votes
22 views
asked Jul 6 by ben-s-7515 (11,340 points)
I have a channel that runs just fine until we receive a large file.  The file is between 2-3 MB.  When it receives this large file the CPU spikes to 100% and everything goes very slowly until the process is completed.

1 Answer

0 votes

In some cases the high CPU is a result of string concatination.  So, if you have your large file and are creating a string with that using the string = string1 + string2, or string1 = string1 + string2 syntax you will see degrading performances as the string gets larger and larger.  This is a known behavior with java.

When dealing with larger strings, it is recommended that you use the java StringBuilder object.  This allows you to concatinate large strings in an efficient manner.

So, if we have the following script:

var data = "prefixData" + fileContents + "suffixData";
data = data + "moreContent";

We can change it to this:

var stringBuilder = new java.lang.StringBuilder();
stringBuilder.append("prefixData").append(fileContents);
stringBuilder.append("suffixData").append("moreContent");
var data = stringBuilder.toString();

The StringBuilder approach will be much more efficient at concatinating a large string and will use a lot less CPU to process.

answered Jul 6 by ben-s-7515 (11,340 points)
...