Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/performance/5.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
Performance 如何最大限度地减少创建WCF客户端的开销?_Performance_Wcf - Fatal编程技术网

Performance 如何最大限度地减少创建WCF客户端的开销?

Performance 如何最大限度地减少创建WCF客户端的开销?,performance,wcf,Performance,Wcf,我目前拥有以下代码: public static ICmsDataServiceWcf Data { get { if (HttpContext.Current != null && HttpContext.Current.Session != null && HttpContext.Current.Session["DataSevice"] == null) {

我目前拥有以下代码:

    public static ICmsDataServiceWcf Data
    {
        get
        {
            if (HttpContext.Current != null && HttpContext.Current.Session != null && HttpContext.Current.Session["DataSevice"] == null)
            {
                HttpContext.Current.Session.Add("DataService", GetDataService());
            }

            if (HttpContext.Current != null && HttpContext.Current.Session != null && HttpContext.Current.Session["DataSevice"] != null)
            {
                return (ICmsDataServiceWcf)HttpContext.Current.Session["DataService"];
            }
            return GetDataService();
        }
    }
这样做的目的是最小化创建/销毁WCF客户端所涉及的开销。它似乎工作得很好。但我遇到的一个问题是,相当多的请求来自后台任务。这些显然没有上下文,因此只能返回GetDataService()行

我想做的是创建一个WCF客户端的静态实例并返回它。但是,这种方法让我担心的一件事是,许多任务将通过单个实例发出大量请求。这会成为一个傻瓜吗?如果是这样的话,那么创建一个由10个WCF客户端组成的池来分散负载是否是一个更好的主意

谢谢


Joe

不建议使用静态代理,因为来自一个错误请求的代理状态将杀死其他模块。看看下面的问题,你正在优化一些已经很快的东西,可能会引入难以发现的bug。除非您的性能度量显示客户端创建是一个问题:否则不要这样做。为每个线程创建一个新的客户端实例,然后在工作完成后关闭该实例。