- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
ASP.Net HttpClient
是一次性的,很多文章都说由于性能原因应该使用单例模式来使用它。但是当我看到 RestClient
时,它无法被处置,并且在 Recommended-Usage 中页面示例每次都会new
RestClient
。我应该为 RestClient
使用单例模式还是应该每次都new
?如果我每次new
都会有性能问题吗?
一些引用:
Do HttpClient and HttpClientHandler have to be disposed
YOU'RE USING HTTPCLIENT WRONG AND IT IS DESTABILIZING YOUR SOFTWARE
最佳答案
should I use singleton pattern for RestClient or should I new iteverytime, if I new it everytime will any performance concern?
推荐使用方式RestSharp
是为每个请求创建一个新实例。
它与 HttpClient
推荐的单例方法不同。原因是under the hood RestSharp
使用HttpWebRequest
用于 HTTP 交互,而不是 HttpClient
。这就是使用模型不同的原因。
If I create it everytime do I get performance issue just like theHttpClient?
不应创建 HttpClient
的新实例的主要原因对于每个请求都不是性能考虑因素。创建和初始化所花费的时间只占后续网络调用所花费时间的一小部分。使用HttpClient
单例实例的主要原因is the following :
HttpClient is intended to be instantiated once and re-used throughoutthe life of an application. Instantiating an HttpClient class forevery request will exhaust the number of sockets available under heavyloads. This will result in SocketException errors.
RestSharp
不使用连接池作为 HttpClient
并且使用后不会留下打开的 socket 。这就是为什么创建 RestClient
的新实例是安全的(并且推荐)。根据请求。
如果您使用 RestClient
的重用实例,您会获得性能提升吗? ?那么,您将节省创建对象及其初始化的时间。然而这个时间非常接近 0
而且,这只是后续网络调用所花费的时间的一小部分。您不会重用其他 .NET 对象,例如 List<T>
出于性能考虑,是吗?您应该对 RestClient
执行相同的操作。它只是以暗示这种使用场景的方式开发的。
关于c# - RestClient 应该是单例还是为每个请求创建新实例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49588205/
单向链表 单向链表比顺序结构的线性表最大的好处就是不用保证存放的位置,它只需要用指针去指向下一个元素就能搞定。 单链表图解 图画的比较粗糙,简单的讲解一下: 上面四个长方形,每个长方
使用TCP,我正在设计一些类似于next的程序。 客户端在许多线程中的接收正在等待一台服务器的发送消息。但是,这是有条件的。 recv正在等待特定的发送消息。 例如 客户 thread 1: recv
我正在编写正则表达式来验证电子邮件。唯一让我困惑的是: 顶级域名可以使用单个字符吗?(例如:lockevn.c) 背景:我知道顶级域名可以是 2 个字符到任意字符(.uk、.us 到 .canon、.
是否可以在单个定义中定义同一 Controller 的多个路由? 例如: 我想要一个单一的定义 /, /about, /privacy-policy 使用类似的东西 _home: pat
我正在使用 objective-c开发针对 11.4 iOS 的单 View 应用程序,以及 Xcode版本是 9.4.1。 创建后有Main.storyboard和LaunchScreen.stor
我一直在尝试在 shell 程序中实现管道结构,如果我执行简单的命令(例如“hello | rev”),它就可以工作 但是当我尝试执行“head -c 1000000/dev/urandom | wc
此表包含主机和接口(interface)列UNIQUE 组合* 编辑:这个表也有一个自动递增的唯一 ID,抱歉我应该在之前提到这个 ** | host.... | interface..... |
我想将具有固定补丁大小的“std filter”应用于单 channel 图像。 也就是说,我希望 out[i,j] 等于 img[i,j] 附近的像素值的标准值。 对于那些熟悉 Matlab 的人,
假设我想进行网络调用并使用 rx.Single,因为我希望只有一个值。 我如何应用replay().autoConnect() 这样的东西,这样当我从多个来源订阅时网络调用就不会发生多次?我应该使用
我将图像从 rgb 转换为 YUV。现在我想单独找到亮度 channel 的平均值。你能告诉我如何实现这一目标吗?此外,有没有办法确定图像由多少个 channel 组成? 最佳答案 你可以这样做: #
在比较Go和Scala的语句结束检测时,我发现Scala的规则更丰富,即: A line ending is treated as a semicolon unless one of the foll
在IEEE 1800-2005或更高版本中,&和&&二进制运算符有什么区别?它们相等吗? 我注意到,当a和b的类型为bit时,这些coverpoint定义的行为相同: cp: coverpoint a
我正在使用Flutter的provider软件包。我要实现的是为一个 View 或页面提供一个简单的提供程序。因此,我在小部件中尝试了以下操作: Widget build(BuildContext c
我正在尝试在 cython 中使用 openmp。我需要在 cython 中做两件事: i) 在我的 cython 代码中使用 #pragma omp single{} 作用域。 ii) 使用#pra
我正在尝试从转义字符字符串中删除单引号和双引号。它对单引号 ' 或双自动 " 不起作用。 请问有人可以帮忙吗? var mysting = escapedStr.replace(/^%22/g, '
我正在尝试在 cython 中使用 openmp。我需要在 cython 中做两件事: i) 在我的 cython 代码中使用 #pragma omp single{} 作用域。 ii) 使用#pra
我正在使用 ANT+ 协议(protocol),将智能手机与 ANT+ USB 加密狗连接,该加密狗通过 SimulANT+ 连接到 PC。 SimulANT+ 正在模拟一个心率传感器,它将数据发送到
有人可以解释/理解单/多线程模式下计算结果的不同吗? 这是一个大约的例子。圆周率的计算: #include #include #include const int itera(100000000
我编写了一个粗略的阴影映射实现,它使用 6 个不同的 View 矩阵渲染场景 6 次以创建立方体贴图。 作为优化,我正在尝试使用几何着色器升级到单 channel 方法,但很难从我的着色器获得任何输出
尝试使用 Single-Spa 构建一些东西并面临添加到应用程序 AngularJS 的问题。 Angular2 和 ReactJs 工作完美,但如果添加 AngularJS 并尝试为此应用程序使用
我是一名优秀的程序员,十分优秀!