Solr和HttpClient高併發 對比
公司需求 做了相關測試 關於HttpClient解析url 獲取資料 和通過Solr API方式來獲取引數來做相關查詢 速度做相關對比
對比
1)httpClient的相應方法
/**
* Get方式發起請求
*
* @param url
* get請求的URL
* @return
*/
public static String requestByGetMethod(String url) {
// 建立預設的httpClient例項
CloseableHttpClient httpClient = getHttpClient();
if (url.startsWith("https")) {
try {
httpClient = createSSLInsecureClient();
}
catch (GeneralSecurityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
try {
// 用get方法傳送http請求
HttpGet get = new HttpGet(url);
CloseableHttpResponse httpResponse = null;
// 傳送get請求
httpResponse = httpClient.execute(get);
if(httpResponse.getStatusLine().getStatusCode() != 200){
return "wrong";
}
try {
// response實體
HttpEntity entity = httpResponse.getEntity();
if (null != entity) {
return EntityUtils.toString(entity, "UTF-8");
// return entity;
}
}
finally {
httpResponse.close();
}
}
catch (Exception e) {
e.printStackTrace();
}
finally {
try {
closeHttpClient(httpClient);
}
catch (IOException e) {
e.printStackTrace();
}
}
return null;
}
因為測試相對要小一下 高併發10000情況下 HttpClient訪問是247674ms,而且會報出N多錯誤
版本 Solr6.5.0 單機 資料規模大概1800W條資料
通過Solr API查詢 結果是46938ms
HttpClient Solr
247674ms VS46938ms 結果很明顯 大概5倍的差距