Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/278.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 客户端的响应时间比tomcat中的QTime长得多_C#_Solr - Fatal编程技术网

C# 客户端的响应时间比tomcat中的QTime长得多

C# 客户端的响应时间比tomcat中的QTime长得多,c#,solr,C#,Solr,我有一个solr网站,有大约500个文档(模式中定义了30个文件),还有一个c#client在同一台机器上,它将向solr网站发送http get请求。 这些日志由我的客户记录: 您可以看到,solr的查询时间非常长,而且非常相似(在1000毫秒到1050毫秒之间)。同时,tomcat中相应的日志: 2013-1-16 23:54:49 org.apache.solr.core.SolrCore execute Info: [suit1] webapp=/vanclsearchV2 path=/

我有一个solr网站,有大约500个文档(模式中定义了30个文件),还有一个c#client在同一台机器上,它将向solr网站发送http get请求。 这些日志由我的客户记录:

您可以看到,solr的查询时间非常长,而且非常相似(在1000毫秒到1050毫秒之间)。同时,tomcat中相应的日志:

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
每一个奇怪的,所有的时间都是零!谁能解释一下这种情况,以及如何解决这个问题

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;

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


另外,您可能需要考虑使用客户端从Cype访问SOLR。它为查询Solr提供了更丰富的界面,并将查询结果映射到POCO对象。

QTime是Solr进行搜索的时间。剩下的时间是通过生成响应来完成的,包括从磁盘获取字段的存储内容并将其生成JSON格式

我将研究以下几件事:

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

能否显示您使用c#客户端连接到Solr的代码?我很想知道你是如何根据上面显示的日志计算Solr时间的。回答得好。此外,如果服务器没有足够的内存用于Solr和文件系统缓存,那么在获取文档以准备响应时,很可能会出现相当多的磁盘IO和抖动。
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;