2016-11-11 2 views
0

일반적인 HTTP 샘플러와 JSR223 샘플러가 혼합 된 테스트 계획이 있습니다. JSR223 나는 간단한 GET/POST 요청을 위해 protobuf 프로토콜과 HTTP 샘플러를 통해 요청을 실행하는 데 사용한다.HTTPSampler에서 HTTPClient를 가져 와서 Beanshell에서 사용하기

SSL 프로토콜을 통한 테스트 중에 JSR223 샘플러가 제공하는 많은 양의 SSL 핸드 셰이크 때문에 Nginx에 막대한 부하가 있음을 발견했습니다.

CloseableHttpClient client = vars.getObject("client"); 

:

CloseableHttpClient client = HttpClients.createDefault(); 

내가 모든 JSR223 샘플러의 초기 단계와 그것의 reusage에이 클라이언트 생성 한 인스턴스로 고정 : 문제는 내가 모든 요청에 ​​새로운 HttpClient를 만든 것이 었습니다 이제 모든 스레드가 두 개의 HTTPClient (하나는 HTTPSampler를 사용하고 하나는 JSR223을 사용함)를 사용하고 있습니다. 그리고 HTTPSampler에서 HTTPClient를 JSR223에서 더 사용하여 이중 핸드 셰이크를 피하는 방법이 있습니다.

HTTPSampler가 테스트 중에 서로간에 savedClient를 전송하는 것처럼 보입니다.

답변

1

"불행히도"좋은 방법이 없으므로 올바른 방법입니다.

이론적으로 Java Reflection API을 사용하여 동일한 HTTPClient 인스턴스에 액세스 할 수 있지만 언제든지 Reflection을 사용하여 JMeter 제한을 해결할 때마다 새끼 고양이가 죽는 것을 기억하십시오.

import org.apache.http.HttpEntity; 
import org.apache.http.HttpResponse; 
import org.apache.http.client.HttpClient; 
import org.apache.http.client.methods.HttpGet; 
import org.apache.http.util.EntityUtils; 
import org.apache.jmeter.protocol.http.sampler.HTTPHC4Impl; 

import org.apache.jmeter.samplers.SampleResult; 

import java.lang.reflect.Field; 
import java.lang.reflect.Method; 


Field samplerImpl = sampler.getClass().getDeclaredField("impl"); 
samplerImpl.setAccessible(true); 
HTTPHC4Impl impl = ((HTTPHC4Impl) samplerImpl.get(sampler)); 
Method method = HTTPHC4Impl.class.getDeclaredMethod("setupClient", URL.class, SampleResult.class); 
method.setAccessible(true); 
URL url = new URL("http://example.com"); 
HttpClient client = (HttpClient) method.invoke(impl, url, new SampleResult()); 
HttpGet get = new HttpGet(); 
get.setURI(url.toURI()); 
HttpResponse response = client.execute(get); 
HttpEntity entity = response.getEntity(); 
log.info("******************* Response *************************"); 
log.info(EntityUtils.toString(entity)); 

데모 :

JMeter get HTTPCLient

그리고 난 당신이 스크립트를 통해 높은 부하를 수행하는 경우 그루비 언어로 전환하는 것이 좋습니다는, 일부 조사와 벤치 마크 Beanshell vs JSR223 vs Java JMeter Scripting: The Performance-Off You've Been Waiting For!을 확인하십시오.

관련 문제