0
아래에 작성한 테스트 코드를 살펴보십시오. 순수 자바 사용 Authenticator를 설정하고 URI 호출을 만들어 일부 XML 데이터를 가져 와서 객체로 변환합니다.클라이언트 용 Netty HTTP Authetication
hotpotato (netty) 대 순수 java (파이프 라인 없음)의 성능을 테스트하기 위해 아래 코드를 작성했습니다.
문제는 hotpotato 또는 netty로 요청을 인증하는 방법을 알아낼 수 없다는 것입니다. 코드를 수용 할 수 있습니다. 단지 성능 차이를 테스트하고 싶습니다 (예 : 5 초 내에 요청 수를 확인하십시오.).
public static void main(String[] args) throws Exception {
Authenticator.setDefault(new MyAuthenticator("DummyUser", "DummyPassword"));
int timeToTestFor = 5000; //5 seconds;
int count = 0;
System.out.println("Start time");
long starttime = System.currentTimeMillis();
do {
URL url = new URL(
"http://example.com/rest/GetData.ashx?what=pizza&where=new%20york&visitorId=12345&sessionId=123456");
SearchResultsDocument doc = SearchResultsDocument.Factory.parse(url);
count++;
} while (System.currentTimeMillis() - starttime < timeToTestFor);
System.out.println("DONE Total count=" + count);
System.out.println("Netty/Hotpotatoe Start time");
count = 0;
starttime = System.currentTimeMillis();
do {
// Create & initialise the client
HttpClient client = new DefaultHttpClient();
client.init();
// Setup the request
HttpRequest request = new DefaultHttpRequest(HttpVersion.HTTP_1_0,
HttpMethod.GET, "/rest/GetData.ashx?what=pizza&where=new%20york&visitorId=12345&sessionId=123456");
// Execute the request, turning the result into a String
HttpRequestFuture future = client.execute("example.com", 80, request,
new BodyAsStringProcessor());
future.awaitUninterruptibly();
// Print some details about the request
System.out.println("A >> " + future);
// If response was >= 200 and <= 299, print the body
if (future.isSuccessfulResponse()) {
System.out.println("B >> "+future.getProcessedResult());
}
// Cleanup
client.terminate();
count++;
} while (System.currentTimeMillis() - starttime < timeToTestFor);
System.out.println("DONE Total count=" + count);
}
감사합니다. 파이프 라인을 사용한 예가 많이 감사하지만 파이프 라이닝을 사용하지 않고이를 수행 할 수 있습니까? – Ali
오, 당신은'awaitUninterruptibly()'을 사용합니다. 이것은 예가 파이프 라인을 사용하지 않는다는 것을 의미합니다. – Ali
파이프 라인이 원인으로 사용됩니다. HttpClientCodec가있는 파이프 라인을 의미하는 경우. 이 예제는 매우 복잡하고 실행을 멈추지 않습니다. 기본 인증은 HttpRequest의 한 헤더 일뿐입니다. (http://en.wikipedia.org/wiki/Basic_access_authentication) –