Занятый Apache Tomcat распаковывает данные - PullRequest
0 голосов
/ 01 ноября 2018

У меня есть приложение, развернутое в tomcat, и я занят большим потоком, не выпуская более 700 подобных событий:

Привет, ребята! я захватил дамп thead, файл находится на ufile.io / 8zz1t , и я использую fastthread.io для чтения. Можете ли вы проверить, если вы видите проблему, я вижу, что у inflater есть поток с CPU потреблять.

S   188063346 ms    0 KB    0 KB    10.162.3.36 172.30.100.163  POST /ChiperService/rest/cs/Descifrar HTTP/1.1
S   280064346 ms    0 KB    0 KB    10.162.3.36 172.30.100.163  POST /ChiperService/rest/cs/Descifrar HTTP/1.1
S   185431144 ms    0 KB    0 KB    10.162.38.201   172.30.100.163  POST /ChiperService/rest/cs/Descifrar HTTP/1.1
S   267094596 ms    0 KB    0 KB    10.162.3.36 172.30.100.163  POST /ChiperService/rest/cs/Descifrar HTTP/1.1
S   261396699 ms    0 KB    0 KB    10.162.3.36 172.30.100.163  POST /ChiperService/rest/cs/Descifrar HTTP/1.1

Какая часть этого кода следует из-за того, что поток занят, я не знаю, должен ли дефлектор или инфлятор быть рядом.

в диспетчере tomcat для приложения ChiperService нет активных сессий.

Пожалуйста, помогите серверу сбоить почти 5 раз в день, потому что thead занят и процессор потребляет много ресурсов.

Это служба отдыха:

Служба отдыха:

package ChiperServicePkg;

import com.sun.jersey.api.core.ResourceConfig;
import java.io.IOException;
import javax.ws.rs.core.Context;
import javax.ws.rs.POST;
import javax.ws.rs.PathParam;
import javax.ws.rs.Path;

import javax.ws.rs.core.Response;
import principal.allus.com.co.SBCCypherModuleMain;
/**
 * REST Web Service
 *
 * @author 1017200731
 */
@Path("/cs")
public class CiphersResource {

@Context ResourceConfig Config;

/**
 * Creates a new instance of CiphersResource
 */
public CiphersResource() {
}

/**
 *
 * @param UUI
 * @return
 * @throws Exception
 */
@POST
@Path("Cifrar")    
public String Cifrar(String UUI) throws Exception 
{
    String Key = (String) Config.getProperty("KeyCipher");
    String dataEncrypted = null;
    try
    {
        dataEncrypted= SBCCypherModuleMain.cifrar(UUI,Key );            
    }
    catch(Exception ex)
    {
        if (ex instanceof IOException){
            throw new IOException(ex);
        }
        else{
            throw ex;
        }            
    }
    return dataEncrypted;
}

/**
 *
 * @param dataEncrypted
 * @return
 * @throws Exception
 */
@POST
@Path("Descifrar")
public Response Descifrar(String dataEncrypted) throws Exception
{
    String Key = (String) Config.getProperty("KeyCipher");
    String dataDecrypted= "";

    try
    {
        dataDecrypted= SBCCypherModuleMain.descifrar(dataEncrypted, Key);
    }
    catch(Exception ex)
    {            
        return Response.status(Response.Status.INTERNAL_SERVER_ERROR)
            .entity(ex.getMessage()).type("text/plain").build();
    }
    return Response.ok(dataDecrypted).build();
}  

/**
 * Sub-resource locator method for {id}
 */
@Path("{id}")
public CipherResource getCipherResource(@PathParam("id") String id) {
    return CipherResource.getInstance(id);
}       

} * * тысяча двадцать-один

Метод Descifrar вызывает jar, предоставленный клиентом, и с помощью декомпилятора я могу извлечь следующий код:

  public static String descifrar(String bytes, String llave)
    throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException, Exception
  {
    byte[] vector = null;
    String retorno = "";

    retorno = SBCCypherModuleCompress.descomprimir(SBCCypherModuleCypher.descifrar(bytes, llave.substring(0, 16)));

    return retorno;
  }

Класс SBCCypherModuleCompress имеет следующий вид:

 public class SBCCypherModuleCompress
{
  public static String comprimir(byte[] data)
    throws IOException, Exception
  {
BASE64Encoder b64e = new BASE64Encoder();

    byte[] output = null;
    String salida = "";

    Deflater deflater = new Deflater();
    deflater.setInput(data);
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream(data.length);
    deflater.finish();

    byte[] buffer = new byte['?'];
    while (!deflater.finished())
    {
      int count = deflater.deflate(buffer);
      outputStream.write(buffer, 0, count);
    }
    outputStream.close();
    output = outputStream.toByteArray();

    salida = b64e.encode(output);

    return salida;
  }

  public static String descomprimir(String data)
    throws DataFormatException, IOException, Exception
  {
    BASE64Encoder b64e = new BASE64Encoder();
    BASE64Decoder b64d = new BASE64Decoder();

    byte[] output = null;
    String salida = "";
    byte[] datad = null;

    datad = b64d.decodeBuffer(data);

    Inflater inflater = new Inflater();

    inflater.setInput(datad);

    ByteArrayOutputStream outputStream = new ByteArrayOutputStream(datad.length);

    byte[] buffer = new byte['?'];
    while (!inflater.finished())
    {
      int count = inflater.inflate(buffer);
      outputStream.write(buffer, 0, count);
    }
    outputStream.close();

    output = outputStream.toByteArray();

    salida = b64e.encode(output);

    return new String(output);
  }
}

Класс SBCCypherModuleCypher имеет следующий вид:

public class SBCCypherModuleCypher
{
  public static String cifrar(String vector, String llaveSimetrica)
    throws NoSuchAlgorithmException, InvalidKeyException, NoSuchPaddingException, IllegalBlockSizeException, BadPaddingException, Exception
  {
    BASE64Encoder b64e = new BASE64Encoder();
    BASE64Decoder b64d = new BASE64Decoder();

    byte[] datad = null;
    String salida = "";

    datad = b64d.decodeBuffer(vector);

    SecretKeySpec key = new SecretKeySpec(llaveSimetrica.getBytes(), "AES");

    byte[] campoCifrado = null;

    Cipher cipher = Cipher.getInstance("AES");
    cipher.init(1, key);
    campoCifrado = cipher.doFinal(datad);

    salida = b64e.encode(campoCifrado);

    return salida;
  }

  public static String descifrar(String vector, String llaveSimetrica)
    throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException, Exception
  {
    BASE64Encoder b64e = new BASE64Encoder();
    BASE64Decoder b64d = new BASE64Decoder();

    byte[] datad = null;
    String salida = "";

    datad = b64d.decodeBuffer(vector);

    SecretKeySpec key = new SecretKeySpec(llaveSimetrica.getBytes(), "AES");

    Cipher cipher = Cipher.getInstance("AES");

    cipher.init(2, key);

    byte[] datosDecifrados = cipher.doFinal(datad);

    salida = b64e.encode(datosDecifrados);

    return salida;
  }
}

1 Ответ

0 голосов
/ 13 ноября 2018

Все ваши темы находятся в inflater.inflate(buffer) в SBCCypherModuleCompress.java, строка 92.

Но почему вы написали new byte['?']? Это в следующем коде:

byte[] buffer = new byte['?'];
while (!deflater.finished())
{
  int count = deflater.deflate(buffer);
  outputStream.write(buffer, 0, count);
}

, а также в следующем коде:

byte[] buffer = new byte['?'];
while (!inflater.finished())
{
  int count = inflater.inflate(buffer);
  outputStream.write(buffer, 0, count);
}

new byte['?'] не имеет смысла.

new byte[2048] или, возможно, new byte[8192] будет лучше, чем new byte['?'].

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...