I have a jar file with a couple of methods that do decryption that I am
calling in a loop. The loop is big, 6000 iterations and while its running
the server is basically brought to a grinding halt and other requests start
to queue and/or execute very slowly.
The cpu is at 40% or so, memory usage does not spike.
How does one thread cause the entire server to grind to a halt?
The funny thing is, If I add a thread.sleep(10) in between each iteration
then the server is able to serve other requests fairly quickly and nothing
queues.
This code does not cause the server to queue all other requests because of
the thread.sleep(), without it, this loop takes over and everything else
queues (or completes very slowly):
<cfset thread = CreateObject("java", "java.lang.Thread")>
<cfloop from="1" to="6000" index="i">
<!--- adding this sleep command, saves the day and allows processing
to continue --->
<cfset thread.sleep(10)>
<cfinvoke
component="#application.util.RSACrypt#"
method="decrypt"
inputCollection="#encryptedData#"
key="#private_key#"
returnvariable="encryptedData">
</cfloop>
This is the method that is being called:
/**
* Decodes a string encoded using its corresponding private key.
This must be done manually due to the unusual padding and
* byte ordering involved.
* @param encryptedString the encrypted string, in aec/TRSA's
version of RSA, in aec's version of base-64 encoding.
* @param aecPrivateKey the corresponding private key, in
aec/TRSA's version of base-64 encoding.
* @return a String representing the original plaintext message.
*/
public static String aecDecrypt(String encryptedString, String
aecPrivateKey) {
RSAPrivateKeySpec privKeySpec =
AECKeyToPrivateKeySpec(aecPrivateKey);
BigInteger d = privKeySpec.getPrivateExponent();
BigInteger n = privKeySpec.getModulus();
byte[] src = unpackAECEncodedBase64(encryptedString); //
this is where the time is spent..
BigInteger c = new BigInteger(1,src);
BigInteger m = c.modPow(d,n);
byte[] decrypted = m.toByteArray();
for(int i=0; i<decrypted.length/2; i+=1) {
byte a = decrypted[decrypted.length-i-1];
byte b = decrypted[i];
decrypted[decrypted.length-i-1] = b;
decrypted[i] = a;
}
int padBytes = decrypted[decrypted.length-1];
String dest = "";
for(int i=0; i<(64-padBytes-1); i++)
dest+=(char)decrypted[i];
d.finalize(); //just to be helpful...
return dest;
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Order the Adobe Coldfusion Anthology now!
http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion
Archive:
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:351563
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm