【问题标题】:Response time in client was much longer than QTime in tomcat客户端的响应时间比 tomcat 中的 QTime 长得多
【发布时间】:2013-01-17 21:25:07
【问题描述】:

我有一个 solr 网站,其中包含大约 500 个文档(架构中定义了 30 个文件),以及一个 c# 客户端在同一台机器上,它将向该 solr 网站发送 http get 请求。 这些日志是由我的 c# 客户端记录的:

01-16 23:54:49,301 [107] INFO LogHelper - requst time too long: 1054, solr time: 1003
01-16 23:54:49,847 [63] INFO LogHelper - requst time too long: 1068, solr time: 1021
01-16 23:57:17,813 [108] INFO LogHelper - requst time too long: 1051, solr time: 1027
01-16 23:57:18,313 [111] INFO LogHelper - requst time too long: 1031, solr time: 1007
and so on…

您可以看到,来自 solr 的查询时间非常长,而且每个都相似(在 1000 毫秒到 1050 毫秒之间)。同时在tomcat中对应的log:

2013-1-16 23:54:49 org.apache.solr.core.SolrCore execute
Info: [suit1] webapp=/vanclsearchV2 path=/select/ params={fl=id,typeid,createtime,vprice,sprice,price,totalassesscount,totalsalescount,productcode,productname,stylecode,tag,vpricesku,spricesku,pricesku,userrate,assesscount,lstphotos,mainphotos,salesflag,isduanma,detailsalescount,productplusstyleinfo&sort=createtime+desc&start=0&q=*:*&wt=json&fq=ancestorsid:(28976+OR+28978)&fq=typeid:(1)&rows=30} hits=43 status=0 QTime=0 
2013-1-16 23:54:49 org.apache.solr.core.SolrCore execute
Info: [suit1] webapp=/vanclsearchV2 path=/select/ params={fl=id,typeid,createtime,vprice,sprice,price,totalassesscount,totalsalescount,productcode,productname,stylecode,tag,vpricesku,spricesku,pricesku,userrate,assesscount,lstphotos,mainphotos,salesflag,isduanma,detailsalescount,productplusstyleinfo&sort=createtime+desc&start=0&q=*:*&wt=json&fq=ancestorsid:(28976+OR+28978)&fq=typeid:(1)&rows=30} hits=43 status=0 QTime=0
2013-1-16 23:57:17 org.apache.solr.core.SolrCore execute
Info: [suit1] webapp=/vanclsearchV2 path=/select/ params={fl=id,typeid,createtime,vprice,sprice,price,totalassesscount,totalsalescount,productcode,productname,stylecode,tag,vpricesku,spricesku,pricesku,userrate,assesscount,lstphotos,mainphotos,salesflag,isduanma,detailsalescount,productplusstyleinfo&sort=createtime+desc&start=0&q=*:*&wt=json&fq=ancestorsid:(27547+OR+27614)&rows=30} hits=9 status=0 QTime=0 
2013-1-16 23:57:18 org.apache.solr.core.SolrCore execute
Info: [suit1] webapp=/vanclsearchV2 path=/select/ params={fl=id,typeid,createtime,vprice,sprice,price,totalassesscount,totalsalescount,productcode,productname,stylecode,tag,vpricesku,spricesku,pricesku,userrate,assesscount,lstphotos,mainphotos,salesflag,isduanma,detailsalescount,productplusstyleinfo&sort=createtime+desc&start=0&q=*:*&wt=json&fq=ancestorsid:(27547+OR+27614)&rows=30} hits=9 status=0 QTime=0

每一个怪,所有的QTime都为零!谁能解释一下这种情况,以及如何解决这个问题?

string QUERY_TEMPLATE = ConfigurationManager.AppSettings["solr-select-url"] + "/select/?fl={0}&q={1}{2}&start={3}&rows={4}&sort={5}&wt=json";

WebRequest request = HttpWebRequest.Create(string.Format(QUERY_TEMPLATE,
                                                requestInfo.BrowserType==BrowserTypeEnum.Style?STYLE_FIELDS:COLOR_FIELDS,
                                                string.IsNullOrWhiteSpace(requestInfo.KeyWord) ? "*:*" : requestInfo.KeyWord,
                                                filterQuery,
                                                (requestInfo.Page - 1) * requestInfo.RowsCount,
                                                requestInfo.RowsCount,
                                                sortFiled)
                                            );
request.Method="GET";

string resultString=null;

Stopwatch solrWatch = new Stopwatch();
solrWatch.Start();
using (WebResponse response = request.GetResponse())
{
    using (Stream stream = response.GetResponseStream())
    {
        using (StreamReader reader = new StreamReader(stream))
        {
            resultString = reader.ReadToEnd();
        }
    }
}
solrWatch.Stop();
solrTime = solrWatch.ElapsedMilliseconds;

【问题讨论】:

  • 您能否展示您用于通过您的 c# 客户端连接到 Solr 的代码?我很想知道您是如何从上面显示的日志中计算 Solr 时间的。

标签: c# solr


【解决方案1】:

QTime 是 Solr 进行搜索的时间。其余时间用于生成响应,包括从磁盘获取存储的字段内容并将它们生成为 JSON 格式。

我会研究以下几件事:

  • 使用 SolrNet 库来访问 Solr,而不是自己进行查询和解析响应
  • 检查您是否正在发送调试信息并将其关闭;只需查看返回的 JSON 并在 solrconfig.xml 中进行配置
  • 检查您是否真的需要所有这些字段作为响应
  • 检查任何特定字段是否真的很大,以及您是否受到磁盘而不是 CPU 的瓶颈;如果是这样,您可以(在 Solr 4 中)将该字段声明为压缩存储 - 这可以加快从磁盘获取该字段的速度

【讨论】:

  • 好答案。此外,如果服务器没有大量内存可用于 Solr 和文件系统缓存,则在获取文档以准备响应时,可能会发生相当多的磁盘 IO 和抖动。
【解决方案2】:

感谢您添加用于访问 Solr 服务器的代码。从您的 tomcat 日志可以看出,对 Solr 的请求发生得非常快。 (Solr 正在缓存查询,因此 QTime 为 0,如您所述)。您的 1000+ 毫秒时间不是 Solr 服务器响应您的时间。这段时间用于将 Solr 响应传输回您的客户端(在这种情况下很简单,因为它位于同一台服务器上)并读取响应流。

此外,您可能需要考虑使用 SolrNet 客户端从 C# 访问 Solr。它为查询 Solr 提供了更丰富的接口,并将查询结果映射到 POCO 对象。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-09-07
    • 2018-06-20
    • 1970-01-01
    • 2019-05-27
    • 2015-02-25
    • 2012-09-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多