1.25稳定性bug修改同步到1.26
This commit is contained in:
parent
d40594bce1
commit
08ddb35bc3
@ -1,5 +1,6 @@
|
|||||||
package com.sunyard.sge.database;
|
package com.sunyard.sge.database;
|
||||||
|
|
||||||
|
import com.sun.jna.Pointer;
|
||||||
import com.sun.jna.ptr.IntByReference;
|
import com.sun.jna.ptr.IntByReference;
|
||||||
import com.sun.jna.ptr.PointerByReference;
|
import com.sun.jna.ptr.PointerByReference;
|
||||||
import com.sunyard.SydApiException;
|
import com.sunyard.SydApiException;
|
||||||
@ -29,7 +30,9 @@ public class SydApiBaseFunction implements SydApi {
|
|||||||
private boolean isShortLinkMode = false;
|
private boolean isShortLinkMode = false;
|
||||||
|
|
||||||
// c 加速句柄,短链接。
|
// c 加速句柄,短链接。
|
||||||
private PointerByReference phHandle = null;
|
private Pointer[] phHandle = new Pointer[1];
|
||||||
|
|
||||||
|
private Pointer pointer = null;
|
||||||
|
|
||||||
private ILogFactory iLogFactory = new LogbackFactory();
|
private ILogFactory iLogFactory = new LogbackFactory();
|
||||||
private ILogger log = iLogFactory.getLogger(SydApiBaseFunction.class);
|
private ILogger log = iLogFactory.getLogger(SydApiBaseFunction.class);
|
||||||
@ -64,7 +67,7 @@ public class SydApiBaseFunction implements SydApi {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SydApi SYD_Short_Connect_Ex(String[] pcIpList, int[] iPortList, int iConnectTimeOut, int allDealTimeOut) {
|
public SydApi SYD_Short_Connect_Ex(String[] pcIpList, int[] iPortList, int iConnectTimeOut, int allDealTimeOut) {
|
||||||
|
// long s = System.currentTimeMillis();
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("SYD_Connect_Ex方法接收参数:pcIpList:{},iPortList:{},iConnectTimeOut:{},iDealTimeOut:{}", Arrays.toString(pcIpList), Arrays.toString(iPortList), iConnectTimeOut, allDealTimeOut);
|
log.debug("SYD_Connect_Ex方法接收参数:pcIpList:{},iPortList:{},iConnectTimeOut:{},iDealTimeOut:{}", Arrays.toString(pcIpList), Arrays.toString(iPortList), iConnectTimeOut, allDealTimeOut);
|
||||||
}
|
}
|
||||||
@ -72,8 +75,9 @@ public class SydApiBaseFunction implements SydApi {
|
|||||||
if (pcIpList.length != iPortList.length) {
|
if (pcIpList.length != iPortList.length) {
|
||||||
throw new IllegalArgumentException("ip与端口数量不一致");
|
throw new IllegalArgumentException("ip与端口数量不一致");
|
||||||
}
|
}
|
||||||
SydApi4j[] apis = new SydApi4j[pcIpList.length];
|
|
||||||
int iDealTimeOut = allDealTimeOut / pcIpList.length;
|
int iDealTimeOut = allDealTimeOut / pcIpList.length;
|
||||||
|
SydApi4j[] apis = new SydApi4j[pcIpList.length];
|
||||||
|
|
||||||
boolean connected = false;
|
boolean connected = false;
|
||||||
for (int i = 0; i < pcIpList.length; i++) {
|
for (int i = 0; i < pcIpList.length; i++) {
|
||||||
|
|
||||||
@ -97,7 +101,7 @@ public class SydApiBaseFunction implements SydApi {
|
|||||||
|
|
||||||
// c 加速链接
|
// c 加速链接
|
||||||
if ( Env.isLinux() ) {
|
if ( Env.isLinux() ) {
|
||||||
PointerByReference phHandle = new PointerByReference();
|
Pointer[] phHandle = new Pointer[1];
|
||||||
int connectResult = SydLibrary.INSTANCE.SYD_Connect_Ex(
|
int connectResult = SydLibrary.INSTANCE.SYD_Connect_Ex(
|
||||||
pcIpList,
|
pcIpList,
|
||||||
iPortList,
|
iPortList,
|
||||||
@ -108,17 +112,21 @@ public class SydApiBaseFunction implements SydApi {
|
|||||||
phHandle);
|
phHandle);
|
||||||
|
|
||||||
if ( 0 != connectResult ){
|
if ( 0 != connectResult ){
|
||||||
|
// 释放已建立的链接
|
||||||
|
this.SYD_Disconnect();
|
||||||
throw new SydApiException("连接错误", -1);
|
throw new SydApiException("连接错误", -1);
|
||||||
}
|
}
|
||||||
this.phHandle = phHandle;
|
this.phHandle = phHandle;
|
||||||
|
this.pointer = phHandle[0];
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SYD_Disconnect() {
|
public void SYD_Disconnect() {
|
||||||
if ( null != phHandle && Env.isLinux()) {
|
if ( null != phHandle && Env.isLinux()) {
|
||||||
SydLibrary.INSTANCE.SYD_DisConnect_Ex(phHandle.getValue());
|
SydLibrary.INSTANCE.SYD_DisConnect_Ex(this.pointer);
|
||||||
phHandle = null;
|
this.phHandle = null;
|
||||||
|
this.pointer = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (null == hsms) {
|
if (null == hsms) {
|
||||||
@ -941,7 +949,7 @@ public class SydApiBaseFunction implements SydApi {
|
|||||||
IntByReference encDataLen = new IntByReference(encData.length);
|
IntByReference encDataLen = new IntByReference(encData.length);
|
||||||
|
|
||||||
int i = SydLibrary.INSTANCE.SYD_SM4_Encrypt_Mac_ShortData(
|
int i = SydLibrary.INSTANCE.SYD_SM4_Encrypt_Mac_ShortData(
|
||||||
phHandle.getValue(),
|
this.pointer,
|
||||||
iEncKeyIndex,
|
iEncKeyIndex,
|
||||||
iMacKeyIndex,
|
iMacKeyIndex,
|
||||||
pcData,
|
pcData,
|
||||||
@ -987,7 +995,7 @@ public class SydApiBaseFunction implements SydApi {
|
|||||||
log.debug("SYD_SM4_EncryptAndMac_ShortData:k1={} k2={}", iEncKeyIndex, iMacKeyIndex);
|
log.debug("SYD_SM4_EncryptAndMac_ShortData:k1={} k2={}", iEncKeyIndex, iMacKeyIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( null != phHandle ) {
|
if ( null != pointer ) {
|
||||||
|
|
||||||
return SYD_SM4_EncryptAndMac_ShortData_c(iEncKeyIndex, iMacKeyIndex, pcData);
|
return SYD_SM4_EncryptAndMac_ShortData_c(iEncKeyIndex, iMacKeyIndex, pcData);
|
||||||
|
|
||||||
@ -1009,7 +1017,7 @@ public class SydApiBaseFunction implements SydApi {
|
|||||||
|
|
||||||
|
|
||||||
int i = SydLibrary.INSTANCE.SYD_SM4_Decrypt_Mac_ShortData(
|
int i = SydLibrary.INSTANCE.SYD_SM4_Decrypt_Mac_ShortData(
|
||||||
phHandle.getValue(),
|
pointer,
|
||||||
iEncKeyIndex,
|
iEncKeyIndex,
|
||||||
iMacKeyIndex,
|
iMacKeyIndex,
|
||||||
pcData,
|
pcData,
|
||||||
@ -1048,7 +1056,7 @@ public class SydApiBaseFunction implements SydApi {
|
|||||||
log.debug("SYD_SM4_CheckMacAndDecrypt_ShortData:k1={} k2={}", iEncKeyIndex, iMacKeyIndex);
|
log.debug("SYD_SM4_CheckMacAndDecrypt_ShortData:k1={} k2={}", iEncKeyIndex, iMacKeyIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
if( null != phHandle ) {
|
if( null != pointer ) {
|
||||||
return SYD_SM4_CheckMacAndDecrypt_ShortData_c(iEncKeyIndex, iMacKeyIndex, pcData, mac);
|
return SYD_SM4_CheckMacAndDecrypt_ShortData_c(iEncKeyIndex, iMacKeyIndex, pcData, mac);
|
||||||
} else {
|
} else {
|
||||||
boolean ret = SYD_SM4Mac_ShortData(iMacKeyIndex, pcData, 1040, mac);
|
boolean ret = SYD_SM4Mac_ShortData(iMacKeyIndex, pcData, 1040, mac);
|
||||||
@ -1217,4 +1225,9 @@ public class SydApiBaseFunction implements SydApi {
|
|||||||
}
|
}
|
||||||
return ia;
|
return ia;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void finalize() throws Throwable {
|
||||||
|
this.SYD_Disconnect_Ex();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -51,7 +51,7 @@ public class SydApiBuilder {
|
|||||||
HsmLinkInfo[] linkInfo = HsmLinkInfo.mutiHsmLinkInfo(pcIpList, iPortList, iConnectTimeOut, iDealTimeOut);
|
HsmLinkInfo[] linkInfo = HsmLinkInfo.mutiHsmLinkInfo(pcIpList, iPortList, iConnectTimeOut, iDealTimeOut);
|
||||||
this.pool = new SydApiPool(config, linkInfo);
|
this.pool = new SydApiPool(config, linkInfo);
|
||||||
longLinkWorks = new CommWorker();
|
longLinkWorks = new CommWorker();
|
||||||
warmUp( pcIpList, iPortList, iConnectTimeOut, iDealTimeOut );
|
// warmUp( pcIpList, iPortList, iConnectTimeOut, iDealTimeOut );
|
||||||
}
|
}
|
||||||
|
|
||||||
public CommWorker getLongLinkWorks() {
|
public CommWorker getLongLinkWorks() {
|
||||||
|
|||||||
@ -166,11 +166,12 @@ public class SydApiLongLinkWrap implements SydApi {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DataAndMac SYD_SM4_EncryptAndMac_ShortData(int iEncKeyIndex, int iMacKeyIndex, byte[] pcData) {
|
public DataAndMac SYD_SM4_EncryptAndMac_ShortData(int iEncKeyIndex, int iMacKeyIndex, byte[] pcData) {
|
||||||
if (Env.isLinux()) {
|
// if (Env.isLinux()) {
|
||||||
return SYD_SM4_EncryptAndMac_ShortData_c(iEncKeyIndex, iMacKeyIndex, pcData);
|
// return SYD_SM4_EncryptAndMac_ShortData_c(iEncKeyIndex, iMacKeyIndex, pcData);
|
||||||
} else {
|
// } else {
|
||||||
return SYD_SM4_EncryptAndMac_ShortData_java(iEncKeyIndex, iMacKeyIndex, pcData);
|
// return SYD_SM4_EncryptAndMac_ShortData_java(iEncKeyIndex, iMacKeyIndex, pcData);
|
||||||
}
|
// }
|
||||||
|
return SYD_SM4_EncryptAndMac_ShortData_java(iEncKeyIndex, iMacKeyIndex, pcData);
|
||||||
}
|
}
|
||||||
|
|
||||||
DataAndMac SYD_SM4_EncryptAndMac_ShortData_c(int iEncKeyIndex, int iMacKeyIndex, byte[] pcData) {
|
DataAndMac SYD_SM4_EncryptAndMac_ShortData_c(int iEncKeyIndex, int iMacKeyIndex, byte[] pcData) {
|
||||||
@ -221,11 +222,12 @@ public class SydApiLongLinkWrap implements SydApi {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DataAndMacCheck SYD_SM4_CheckMacAndDecrypt_ShortData(int iEncKeyIndex, int iMacKeyIndex, byte[] pcData, byte[] macs) {
|
public DataAndMacCheck SYD_SM4_CheckMacAndDecrypt_ShortData(int iEncKeyIndex, int iMacKeyIndex, byte[] pcData, byte[] macs) {
|
||||||
if (Env.isLinux()) {
|
// if (Env.isLinux()) {
|
||||||
return SYD_SM4_CheckMacAndDecrypt_ShortData_c(iEncKeyIndex, iMacKeyIndex, pcData, macs);
|
// return SYD_SM4_CheckMacAndDecrypt_ShortData_c(iEncKeyIndex, iMacKeyIndex, pcData, macs);
|
||||||
} else {
|
// } else {
|
||||||
return SYD_SM4_CheckMacAndDecrypt_ShortData_java(iEncKeyIndex, iMacKeyIndex, pcData, macs);
|
// return SYD_SM4_CheckMacAndDecrypt_ShortData_java(iEncKeyIndex, iMacKeyIndex, pcData, macs);
|
||||||
}
|
// }
|
||||||
|
return SYD_SM4_CheckMacAndDecrypt_ShortData_java(iEncKeyIndex, iMacKeyIndex, pcData, macs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -290,11 +292,12 @@ public class SydApiLongLinkWrap implements SydApi {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<DataAndMac> SYD_SM4_EncryptAndMac_BatchData(int[] iEncKeyIndex, int[] iMacKeyIndex, List<byte[]> pcData) {
|
public List<DataAndMac> SYD_SM4_EncryptAndMac_BatchData(int[] iEncKeyIndex, int[] iMacKeyIndex, List<byte[]> pcData) {
|
||||||
if (Env.isLinux()) {
|
// if (Env.isLinux()) {
|
||||||
return SYD_SM4_EncryptAndMac_BatchData_c(iEncKeyIndex, iMacKeyIndex, pcData);
|
// return SYD_SM4_EncryptAndMac_BatchData_c(iEncKeyIndex, iMacKeyIndex, pcData);
|
||||||
} else {
|
// } else {
|
||||||
return SYD_SM4_EncryptAndMac_BatchData_java(iEncKeyIndex, iMacKeyIndex, pcData);
|
// return SYD_SM4_EncryptAndMac_BatchData_java(iEncKeyIndex, iMacKeyIndex, pcData);
|
||||||
}
|
// }
|
||||||
|
return SYD_SM4_EncryptAndMac_BatchData_java(iEncKeyIndex, iMacKeyIndex, pcData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -405,11 +408,12 @@ public class SydApiLongLinkWrap implements SydApi {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<DataAndMacCheck> SYD_SM4_CheckMacAndDecrypt_BatchData(int[] iEncKeyIndex, int[] iMacKeyIndex, List<DataAndMac> pcData) {
|
public List<DataAndMacCheck> SYD_SM4_CheckMacAndDecrypt_BatchData(int[] iEncKeyIndex, int[] iMacKeyIndex, List<DataAndMac> pcData) {
|
||||||
if (Env.isLinux()) {
|
// if (Env.isLinux()) {
|
||||||
return SYD_SM4_CheckMacAndDecrypt_BatchData_c(iEncKeyIndex, iMacKeyIndex, pcData);
|
// return SYD_SM4_CheckMacAndDecrypt_BatchData_c(iEncKeyIndex, iMacKeyIndex, pcData);
|
||||||
} else {
|
// } else {
|
||||||
return SYD_SM4_CheckMacAndDecrypt_BatchData_java(iEncKeyIndex, iMacKeyIndex, pcData);
|
// return SYD_SM4_CheckMacAndDecrypt_BatchData_java(iEncKeyIndex, iMacKeyIndex, pcData);
|
||||||
}
|
// }
|
||||||
|
return SYD_SM4_CheckMacAndDecrypt_BatchData_java(iEncKeyIndex, iMacKeyIndex, pcData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -8,7 +8,7 @@ import com.sun.jna.ptr.PointerByReference;
|
|||||||
*/
|
*/
|
||||||
public class ConnectHandlerManager {
|
public class ConnectHandlerManager {
|
||||||
|
|
||||||
private static PointerByReference phHandle = new PointerByReference();
|
private static Pointer[] phHandle = new Pointer[1];
|
||||||
private static Boolean inited = false;
|
private static Boolean inited = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -45,6 +45,6 @@ public class ConnectHandlerManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static Pointer getHandler(){
|
public static Pointer getHandler(){
|
||||||
return phHandle.getValue();
|
return phHandle[0];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -21,7 +21,7 @@ public interface SydLibrary extends Library {
|
|||||||
int iConnectTimeOut,
|
int iConnectTimeOut,
|
||||||
int iDealTimeOut,
|
int iDealTimeOut,
|
||||||
int iThreadCount,
|
int iThreadCount,
|
||||||
PointerByReference phHandle);
|
Pointer[] phHandle);
|
||||||
|
|
||||||
// 1.3 断开与设备的连接
|
// 1.3 断开与设备的连接
|
||||||
int SYD_DisConnect_Ex(Pointer phHandle);
|
int SYD_DisConnect_Ex(Pointer phHandle);
|
||||||
|
|||||||
@ -36,10 +36,12 @@ public class FuncTest {
|
|||||||
public SydApi connect() {
|
public SydApi connect() {
|
||||||
if (isShortLink) {
|
if (isShortLink) {
|
||||||
|
|
||||||
|
System.out.println("short");
|
||||||
SydApi api = new SydApi4Database();
|
SydApi api = new SydApi4Database();
|
||||||
api.SYD_Short_Connect_Ex(config.getIps(), config.getPorts(), connectTimeout, dealTimeout);
|
api.SYD_Short_Connect_Ex(config.getIps(), config.getPorts(), connectTimeout, dealTimeout);
|
||||||
return api;
|
return api;
|
||||||
} else {
|
} else {
|
||||||
|
System.out.println("long");
|
||||||
SydApiBuilder builder = new SydApiBuilder(
|
SydApiBuilder builder = new SydApiBuilder(
|
||||||
config.getIps(),
|
config.getIps(),
|
||||||
config.getPorts(),
|
config.getPorts(),
|
||||||
@ -2185,6 +2187,7 @@ public class FuncTest {
|
|||||||
}
|
}
|
||||||
} catch (SydApiException e){
|
} catch (SydApiException e){
|
||||||
printException("输入正确入参,校验失败", e);
|
printException("输入正确入参,校验失败", e);
|
||||||
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
printEnd();
|
printEnd();
|
||||||
|
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
210
src/test/java/test/TestOpenClose.java
Normal file
210
src/test/java/test/TestOpenClose.java
Normal file
@ -0,0 +1,210 @@
|
|||||||
|
package test;
|
||||||
|
|
||||||
|
import com.sun.jna.Pointer;
|
||||||
|
import com.sunyard.sge.database.DataAndMac;
|
||||||
|
import com.sunyard.sge.database.SydApi;
|
||||||
|
import com.sunyard.sge.database.SydApi4Database;
|
||||||
|
import com.sunyard.sge.plus.SydLibrary;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.concurrent.ExecutorService;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
public class TestOpenClose {
|
||||||
|
|
||||||
|
private static Config config ;
|
||||||
|
|
||||||
|
|
||||||
|
public static void sm4ShortMacEnde1(int numberOfThreads, int totalRequest, int plainLen) throws InterruptedException {
|
||||||
|
byte[] data = new byte[plainLen];
|
||||||
|
int keyEnc = 0;
|
||||||
|
int keyMac = 0;
|
||||||
|
|
||||||
|
Set<SydApi> syncSet = Collections.synchronizedSet(new HashSet<>());
|
||||||
|
|
||||||
|
ThreadLocal<SydApi> Api = new ThreadLocal<SydApi>() {
|
||||||
|
@Override
|
||||||
|
protected SydApi initialValue() {
|
||||||
|
SydApi api = new SydApi4Database();
|
||||||
|
try {
|
||||||
|
api.SYD_Short_Connect_Ex(config.getIps(), config.getPorts(), 2000, 2000);
|
||||||
|
System.out.println("create link " + Thread.currentThread().getName());
|
||||||
|
syncSet.add( api );
|
||||||
|
System.out.println("建立链接 " + syncSet.size());
|
||||||
|
}catch (Exception e) {
|
||||||
|
System.out.println("error link " + Thread.currentThread().getName());
|
||||||
|
// e.printStackTrace();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
return api;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
try {
|
||||||
|
System.out.println("准备密文数据");
|
||||||
|
SydApi apiTest = Api.get();
|
||||||
|
final DataAndMac ret = apiTest.SYD_SM4_EncryptAndMac_ShortData(keyEnc, keyMac, data);
|
||||||
|
apiTest.SYD_Disconnect_Ex();
|
||||||
|
System.out.println("密文数据准备完成");
|
||||||
|
|
||||||
|
ExecutorService poolEnc = Executors.newFixedThreadPool(numberOfThreads);
|
||||||
|
long start = System.currentTimeMillis();
|
||||||
|
for (int i = 0; i < totalRequest; i++) {
|
||||||
|
poolEnc.submit(() -> {
|
||||||
|
SydApi api = Api.get();
|
||||||
|
if ( null == api ) {
|
||||||
|
System.out.println("api is null");
|
||||||
|
}
|
||||||
|
api.SYD_SM4_EncryptAndMac_ShortData(keyEnc, keyMac, data);
|
||||||
|
|
||||||
|
// System.out.println("encrypt " + Thread.currentThread().getName());
|
||||||
|
|
||||||
|
|
||||||
|
// System.out.println("Thread=" + Thread.currentThread().getName());
|
||||||
|
// SydApi4Database adb = (SydApi4Database) api;
|
||||||
|
// System.out.println("handler=" + adb.getHandler());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
poolEnc.shutdown();
|
||||||
|
poolEnc.awaitTermination(Long.MAX_VALUE, TimeUnit.SECONDS);
|
||||||
|
System.out.println("释放链接 " + syncSet.size());
|
||||||
|
syncSet.forEach(SydApi::SYD_Disconnect_Ex);
|
||||||
|
syncSet.clear();
|
||||||
|
// System.out.println("sleep");
|
||||||
|
// Thread.sleep(10 * 1000);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
long end = System.currentTimeMillis();
|
||||||
|
long duration = end - start;
|
||||||
|
double tps = totalRequest * 1000.0 / duration;
|
||||||
|
double throughput = totalRequest * 1000.0 / duration * plainLen / 1024 / 1024;
|
||||||
|
|
||||||
|
System.out.println("并发数: " + numberOfThreads);
|
||||||
|
System.out.println("加密共花费 " + String.format("%.2f", duration / 1000.0) + " 秒");
|
||||||
|
System.out.println("TPS: " + String.format("%.2f", tps));
|
||||||
|
System.out.println("吞吐量: " + String.format("%.2f", throughput) + " MB/S");
|
||||||
|
double avgLatency = numberOfThreads * duration * 1.0 / totalRequest;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
ExecutorService poolDec = Executors.newFixedThreadPool(numberOfThreads);
|
||||||
|
start = System.currentTimeMillis();
|
||||||
|
for (int i = 0; i < totalRequest; i++) {
|
||||||
|
poolDec.submit(() -> {
|
||||||
|
SydApi api = Api.get();
|
||||||
|
api.SYD_SM4_CheckMacAndDecrypt_ShortData(keyEnc, keyMac, ret.getData(), ret.getMac());
|
||||||
|
// System.out.println("decrypt " + Thread.currentThread().getName());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
poolDec.shutdown();
|
||||||
|
poolDec.awaitTermination(Long.MAX_VALUE, TimeUnit.SECONDS);
|
||||||
|
System.out.println("释放链接 " + syncSet.size());
|
||||||
|
syncSet.forEach(SydApi::SYD_Disconnect_Ex);
|
||||||
|
syncSet.clear();
|
||||||
|
// System.out.println("sleep");
|
||||||
|
// Thread.sleep(10 * 1000);
|
||||||
|
|
||||||
|
|
||||||
|
end = System.currentTimeMillis();
|
||||||
|
duration = end - start;
|
||||||
|
tps = totalRequest * 1000.0 / duration;
|
||||||
|
throughput = totalRequest * 1000.0 / duration * plainLen / 1024 / 1024;
|
||||||
|
|
||||||
|
System.out.println("并发数: " + numberOfThreads);
|
||||||
|
System.out.println("解密共花费 " + String.format("%.2f", duration / 1000.0) + " 秒");
|
||||||
|
System.out.println("TPS: " + String.format("%.2f", tps));
|
||||||
|
System.out.println("吞吐量: " + String.format("%.2f", throughput) + " MB/S");
|
||||||
|
avgLatency = numberOfThreads * duration * 1.0 / totalRequest;
|
||||||
|
} catch (Exception e) {
|
||||||
|
System.out.println("密文数据准备异常");
|
||||||
|
e.printStackTrace();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static void case1(){
|
||||||
|
System.out.println("case1 start");
|
||||||
|
// PointerByReference phHandle = new PointerByReference();
|
||||||
|
|
||||||
|
Pointer[] phHandle = new Pointer[1];
|
||||||
|
int connectResult = SydLibrary.INSTANCE.SYD_Connect_Ex(
|
||||||
|
config.getIps(),
|
||||||
|
config.getPorts(),
|
||||||
|
config.getIps().length,
|
||||||
|
1000,
|
||||||
|
2000,
|
||||||
|
0,
|
||||||
|
phHandle);
|
||||||
|
|
||||||
|
if ( 0 != connectResult ){
|
||||||
|
System.out.println("link error" + connectResult);
|
||||||
|
} else {
|
||||||
|
System.out.println("SYD_Disconnect this.phHandle=" + Pointer.nativeValue(phHandle[0]));
|
||||||
|
System.out.println("link");
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println("SYD_Disconnect this.phHandle=" + Pointer.nativeValue(phHandle[0]));
|
||||||
|
int disResult = SydLibrary.INSTANCE.SYD_DisConnect_Ex(phHandle[0]);
|
||||||
|
if ( 0 != disResult ){
|
||||||
|
System.out.println("disResult error" + disResult);
|
||||||
|
} else {
|
||||||
|
System.out.println("disResult");
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println("case1 end");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void case2(){
|
||||||
|
System.out.println("case2 start");
|
||||||
|
SydApi4Database api = new SydApi4Database();
|
||||||
|
api.SYD_Short_Connect_Ex(config.getIps(), config.getPorts(), 2000, 2000);
|
||||||
|
api.SYD_Disconnect_Ex();
|
||||||
|
System.out.println("case2 end");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static void case3(String[] args) throws InterruptedException {
|
||||||
|
int threads = 40;
|
||||||
|
|
||||||
|
try {
|
||||||
|
threads = Integer.valueOf(args[0]);
|
||||||
|
}catch ( Exception e ) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println("threads=" + threads);
|
||||||
|
|
||||||
|
|
||||||
|
System.out.println("case3 start");
|
||||||
|
while (true) {
|
||||||
|
sm4ShortMacEnde1(threads, 100000, 1024);
|
||||||
|
}
|
||||||
|
|
||||||
|
// System.out.println("case3 end");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static void main(String[] args) throws InterruptedException {
|
||||||
|
|
||||||
|
// 载入配置文件
|
||||||
|
config = Config.loadConfig();
|
||||||
|
System.out.println("config=" + Arrays.toString(config.getIps()));
|
||||||
|
|
||||||
|
|
||||||
|
// case1();
|
||||||
|
|
||||||
|
|
||||||
|
// case2();
|
||||||
|
|
||||||
|
|
||||||
|
case3(args);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user