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倍的差距