Jasypt-Solaris上的性能不佳

时间:2019-02-15 15:33:43

标签: performance encryption java-8 solaris jasypt

我正在使用PooledPBEStringEncryptor解密一些字符串。我正在多个线程上运行测试。

我正在多个线程上执行以下方法

public static long decryptJasypt (String str)
{
  long time = System.currentTimeMillis();
  encryptor.decrypt(str);
  return System.currentTimeMillis()-time;
}

其中

encryptor = new PooledPBEStringEncryptor();

encryptor.setPoolSize(4);

我正在Ubuntu和Solaris上运行相同的测试。在Solaris上,同一测试需要10倍的时间才能完成。

对于Solaris,作为安全提供程序,我曾经使用过

sun.security.pkcs11.SunPKCS11 ${java.home}/lib/security/sunpkcs11-solaris.cfg 

com.oracle.security.ucrypto.UcryptoProvider ${java.home}/lib/security/ucrypto-solaris.cfg

对于第一个提供程序,我的线程留在这里:

"Thread-86" #104 prio=5 os_prio=64 tid=0x00000000014ab800 nid=0x78 runnable [0xffff80ffb3971000]
java.lang.Thread.State: RUNNABLE
at sun.security.pkcs11.wrapper.PKCS11.C_CloseSession(Native Method)
at sun.security.pkcs11.SessionRef.dispose(Session.java:171)
at sun.security.pkcs11.Session.close(Session.java:120)
at sun.security.pkcs11.SessionManager.closeSession(SessionManager.java:232)
at sun.security.pkcs11.SessionManager.killSession(SessionManager.java:174)
at sun.security.pkcs11.Token.killSession(Token.java:311)
at sun.security.pkcs11.P11Digest.engineReset(P11Digest.java:144)
at sun.security.pkcs11.P11Digest.engineDigest(P11Digest.java:194)
at sun.security.pkcs11.P11Digest.engineDigest(P11Digest.java:157)
at java.security.MessageDigest$Delegate.engineDigest(MessageDigest.java:592)
at java.security.MessageDigest.digest(MessageDigest.java:365)
at com.sun.crypto.provider.PBES1Core.deriveCipherKey(PBES1Core.java:279)
at com.sun.crypto.provider.PBES1Core.init(PBES1Core.java:250)
at com.sun.crypto.provider.PBEWithMD5AndDESCipher.engineInit(PBEWithMD5AndDESCipher.java:221)

与此同时,另一个:

Thread-73" #91 prio=5 os_prio=64 tid=0x0000000001733800 nid=0x6b runnable [0xffff80ffb467e000]
java.lang.Thread.State: RUNNABLE
at com.oracle.security.ucrypto.NativeDigest.nativeInit(Native Method)
at com.oracle.security.ucrypto.NativeDigest.engineUpdate(NativeDigest.java:167)
- locked <0x00000003402108d0> (a com.oracle.security.ucrypto.NativeDigest$MD5)
at java.security.MessageDigest$Delegate.engineUpdate(MessageDigest.java:584)
at java.security.MessageDigest.update(MessageDigest.java:335)
at com.sun.crypto.provider.PBES1Core.deriveCipherKey(PBES1Core.java:278)
at com.sun.crypto.provider.PBES1Core.init(PBES1Core.java:250)
at com.sun.crypto.provider.PBEWithMD5AndDESCipher.engineInit(PBEWithMD5AndDESCipher.java:221)
at javax.crypto.Cipher.init(Cipher.java:1393)
at javax.crypto.Cipher.init(Cipher.java:1326)

请问我应如何解决此问题。在Solaris上运行的jasypt是否存在任何已知问题?

我的测试包括创建一个数组,其中包含一些用jasypt加密的简单字符串(其中包含30个项目),然后启动100个线程。每个线程都会解密数组中的项目10次。

在Solaris上的结果:一个线程需要39到79秒才能完成此任务

在Linux上的结果:一个线程需要2到7秒才能完成此任务

在linux计算机上:1个物理处理器,8个内核

在solaris上,我有一个虚拟机,该虚拟机驻留在具有2个物理处理器(每个物理处理器具有4个核心和8个虚拟处理器)的计算机上。

注意:即使在具有256核的solaris sparc上解密数据时,我们也遇到了速度慢的问题。我当时无法在那个环境中进行测试。

public static ArrayList<String> ar = new ArrayList();
public static PooledPBEStringEncryptor encryptor;
static
{
    Provider[] providers = Security.getProviders();
    encryptor = new PooledPBEStringEncryptor();
    encryptor.setPoolSize(4);
    encryptor.setPassword("xxxxxx");

    for (int i=0;i<10;i++){
        ar.add(encryptJasyptValue("false"));
    }
    for (int i=0;i<10;i++){
        ar.add(encryptJasyptValue(""+i));
    }
    for (int i=0;i<10;i++){
        ar.add(encryptJasyptValue("true"));
    }


}


public static long encryptJasypt (String str){
long time = System.currentTimeMillis();
return System.currentTimeMillis()-time;
}

public static long decryptJasypt (String str){
    long time = System.currentTimeMillis();
    encryptor.decrypt(str);
    return System.currentTimeMillis()-time;
}

public static void main(String[] args) throws Exception
{


    int noTreads =100;
    if(args.length>0 && args[0]!=null) {
         noTreads = Integer.parseInt(args[0]);
    }
    for (int i=0;i<noTreads;i++)
    {
       new MyThread().start();
    }


 }
}

class MyThread extends Thread {
public void run() {

    long time=0;
    for (int k=0;k<10;k++) {
        for (int i = 0; i < CryptoUtil.ar.size(); i++) {
            time += CryptoUtil.decryptJasypt(CryptoUtil.ar.get(i));
        }
    }
    System.out.println("took d="+time);
}

}

0 个答案:

没有答案