wildflyejb通过http冻结对jboss的调用

j13ufse2  于 2021-07-06  发布在  Java
关注(0)|答案(0)|浏览(204)

我正在使用“ejboverhttp”协议对wildfly15.0.1上的ejb远程调用进行负载测试。jmeter java客户端采样器类似于:
公共类loginejbtestsampler扩展了abstractjavasampler客户端{

private static final String ARG_USUARIO = "username";
private static final String ARG_SENHA = "password";
private static final String ARG_FILIAL= "filial";
private static final String USER = "ejbuser";
private static final String PASSWORD = "ejbpassword";

private Context context;

@Override
public void setupTest(JavaSamplerContext context) {
    if (!useCloseLookupEachRequest()) {
        abrirLookup();
    }
}

@Override
public void teardownTest(JavaSamplerContext context) {
    if (!useCloseLookupEachRequest()) {
        fecharLookup();
    }
}

@Override
public SampleResult runTest(JavaSamplerContext context) {

    final LoginRemote service;
    final Usuario usuario;
    final UserContext userContext;

    SampleResult sampleResult = new SampleResult();
    sampleResult.sampleStart();

    try {
        if (useCloseLookupEachRequest()) {
            abrirLookup();
        }

        try {
            service = doRemoteLookup("MyModuleName", LoginRemote.class);
        }catch (Exception e) {
            throw new RuntimeException("Erro ao executar lookup",e);
        }
        String username = context.getParameter(ARG_USUARIO);
        String password = context.getParameter(ARG_SENHA);
        long filial = context.getLongParameter(ARG_FILIAL);

        try {
            usuario = service.validarLoginSenha(username, password);
        }catch (Exception e) {
            throw new RuntimeException("Erro ao executar validarLoginSenha",e);
        }

        if (usuario != null) {

            try {
                userContext = service.criarContexto(usuario.getIdUsuario(),filial, new Date(), Boolean.TRUE);//Freeze here
            }catch (Exception e) {
                throw new RuntimeException("Erro ao executar criarContexto",e);
            }
            sampleResult.sampleEnd();           
            sampleResult.setSuccessful(Boolean.TRUE);
            sampleResult.setResponseCodeOK();
            sampleResult.setResponseMessage("Usuario: " + usuario.getNome()+" - Data Contexto: "+userContext.getSystemDate());

        } else {
            sampleResult.sampleEnd();
            sampleResult.setSuccessful(Boolean.FALSE);
            sampleResult.setResponseMessage("Usuario não retornado ");
        }

        if (useCloseLookupEachRequest()) {
            fecharLookup();
        }

    } catch (Exception e) {

        sampleResult.sampleEnd();
        sampleResult.setSuccessful(Boolean.FALSE);
        sampleResult.setResponseMessage("Exception: " + e );

        try(StringWriter stringWriter = new StringWriter()){
            e.printStackTrace( new PrintWriter( stringWriter ) );
            sampleResult.setResponseData( stringWriter.toString(),"UTF-8" );
            sampleResult.setDataType( org.apache.jmeter.samplers.SampleResult.TEXT );
        }catch (Exception ignore) {}

    }
    return sampleResult;
}

private boolean useCloseLookupEachRequest() {
    return Boolean.getBoolean("teste-close-lookup-each-request");
}

private void abrirLookup() {
    try {
        String host = System.getProperty("default.host");
        String port = System.getProperty("default.port");
        Properties props = new Properties();
        props.put(Context.INITIAL_CONTEXT_FACTORY, "org.wildfly.naming.client.WildFlyInitialContextFactory");
        props.put(Context.PROVIDER_URL, "http://" + host + ":" + port+"/wildfly-services");
        props.put(Context.SECURITY_PRINCIPAL, USER);
        props.put(Context.SECURITY_CREDENTIALS, PASSWORD);

        context = new InitialContext(props);
    }catch (Exception e) {
        throw new RuntimeException(e);
    }
}

private void fecharLookup() {
    try {
        if (context != null) {
            context.close();
        }
    }catch (Exception e) {
        throw new RuntimeException(e);
    }
}
private <T> T doRemoteLookup(String moduleName, Class<T> remoteInterface) {
    try {
        String intefaceName = remoteInterface.getName();
        String ejbName = intefaceName.substring(intefaceName.lastIndexOf('.')+1).replaceAll("Remote", "EJB");

        String jndiName = getRemoteJndiName(new EJBModule("MyApplicationName", moduleName),ejbName,remoteInterface);
        Object bean = context.lookup(jndiName);

        EJBClient.setInvocationTimeout(bean, 10, TimeUnit.SECONDS);

        return (T)bean;
    }catch (Exception e) {
        throw new RuntimeException(e);
    }
}

private String getRemoteJndiName(EJBModule module, String ejbName, Class<?> remoteInterface) {
    String intefaceName = remoteInterface.getName();
    StringBuilder jndiName = new StringBuilder();
    jndiName.append("ejb:");
    jndiName.append(module.getApplicationName());
    jndiName.append("/");
    jndiName.append(module.getModuleName());
    jndiName.append("/");
    jndiName.append(ejbName);
    jndiName.append("!");
    jndiName.append(intefaceName);      
    return jndiName.toString();
}

}
jmeter测试的线程组有100个线程(用户)和100个循环计数
当测试完成了大约9000个示例时,jmeter只有1个活动线程,只有测试冻结,没有服务器异常和客户端异常。
我在测试采样器上设置了一个调用超时,以便验证服务器是否持有请求,但没有抛出timeoutexception。
我用visualvm得到的堆栈跟踪是这样的:

"Thread Group 1-75" - Thread t@111
   java.lang.Thread.State: WAITING
    at java.lang.Object.wait(Native Method)
    - waiting on <42e4c2ef> (a java.lang.Object)
    at java.lang.Object.wait(Unknown Source)
    at org.wildfly.httpclient.common.WildflyClientInputStream.read(WildflyClientInputStream.java:148)
    at java.io.FilterInputStream.read(Unknown Source)
    at org.jboss.marshalling.SimpleDataInput.read(SimpleDataInput.java:117)
    at org.jboss.marshalling.UTFUtils.readUTFBytes(UTFUtils.java:151)
    at org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:288)
    at org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:220)
    at org.jboss.marshalling.river.RiverUnmarshaller.readFields(RiverUnmarshaller.java:1853)
    at org.jboss.marshalling.river.RiverUnmarshaller.doInitSerializable(RiverUnmarshaller.java:1767)
    at org.jboss.marshalling.river.RiverUnmarshaller.doReadNewObject(RiverUnmarshaller.java:1395)
    at org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:272)
    at org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:205)
    at org.jboss.marshalling.AbstractObjectInput.readObject(AbstractObjectInput.java:41)
    at org.wildfly.httpclient.ejb.HttpEJBReceiver$1.getResult(HttpEJBReceiver.java:198)
    at org.jboss.ejb.client.EJBClientInvocationContext.getResult(EJBClientInvocationContext.java:592)
    at org.jboss.ejb.client.EJBClientInvocationContext.getResult(EJBClientInvocationContext.java:528)
    at org.jboss.ejb.protocol.remote.RemotingEJBClientInterceptor.handleInvocationResult(RemotingEJBClientInterceptor.java:56)
    at org.jboss.ejb.client.EJBClientInvocationContext.getResult(EJBClientInvocationContext.java:594)
    at org.jboss.ejb.client.EJBClientInvocationContext.getResult(EJBClientInvocationContext.java:528)
    at org.jboss.ejb.client.TransactionPostDiscoveryInterceptor.handleInvocationResult(TransactionPostDiscoveryInterceptor.java:133)
    at org.jboss.ejb.client.EJBClientInvocationContext.getResult(EJBClientInvocationContext.java:594)
    at org.jboss.ejb.client.EJBClientInvocationContext.getResult(EJBClientInvocationContext.java:528)
    at org.jboss.ejb.client.DiscoveryEJBClientInterceptor.handleInvocationResult(DiscoveryEJBClientInterceptor.java:115)
    at org.jboss.ejb.client.EJBClientInvocationContext.getResult(EJBClientInvocationContext.java:594)
    at org.jboss.ejb.client.EJBClientInvocationContext.getResult(EJBClientInvocationContext.java:528)
    at org.jboss.ejb.client.NamingEJBClientInterceptor.handleInvocationResult(NamingEJBClientInterceptor.java:79)
    at org.jboss.ejb.client.EJBClientInvocationContext.getResult(EJBClientInvocationContext.java:594)
    at org.jboss.ejb.client.EJBClientInvocationContext.getResult(EJBClientInvocationContext.java:528)
    at org.jboss.ejb.client.TransactionInterceptor.handleInvocationResult(TransactionInterceptor.java:172)
    at org.jboss.ejb.client.EJBClientInvocationContext.getResult(EJBClientInvocationContext.java:594)
    at org.jboss.ejb.client.EJBClientInvocationContext.getResult(EJBClientInvocationContext.java:528)
    at org.jboss.ejb.client.EJBClientInvocationContext.awaitResponse(EJBClientInvocationContext.java:938)
    at org.jboss.ejb.client.EJBInvocationHandler.invoke(EJBInvocationHandler.java:177)
    at org.jboss.ejb.client.EJBInvocationHandler.invoke(EJBInvocationHandler.java:112)
    at com.sun.proxy.$Proxy22.criarContexto(Unknown Source)
    at my.company.test.login.LoginEJBTestSampler.runTest(LoginEJBTestSampler.java:89)
    at org.apache.jmeter.protocol.java.sampler.JavaSampler.sample(JavaSampler.java:197)
    at org.apache.jmeter.threads.JMeterThread.doSampling(JMeterThread.java:630)
    at org.apache.jmeter.threads.JMeterThread.executeSamplePackage(JMeterThread.java:558)
    at org.apache.jmeter.threads.JMeterThread.processSampler(JMeterThread.java:489)
    at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:256)
    at java.lang.Thread.run(Unknown Source)

   Locked ownable synchronizers:
    - None

我想问一下,是否有人知道发生了什么,或者我能做些什么来解决这个问题。我想可能是个窃听器,但在网上唯一能找到的就是https://access.redhat.com/solutions/4904801 ,但没有red hat客户帐户。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题