WebClient 构建开销 [英] WebClient construction overhead

查看:30
本文介绍了WebClient 构建开销的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个客户端,它发出有限数量的并发 Web 请求.为此,我使用 WebClient.我目前有一个 WebClient-s 池,我创建了一次并使用空闲的那个.

I have a client which makes a limited number of concurrent web requests. I use WebClient for this purpose. I currently have a pool of WebClient-s which I create once and use whichever one is idle.

尽管这种方法变得有点麻烦,我想知道拥有一组预先构建的 WebClient 实例是否有任何好处,或者动态创建它们是否不会太麻烦?

This approach is becoming a little cumbersome though, and I'm wondering if there is any benefit to having a collection of pre-constructed WebClient instances, or if creating them on the fly wouldn't be too much trouble?

推荐答案

你到底为什么要拥有一个 WebClient 池?它们是微小的、廉价的物体.您是否通过测量确定这是必要的和有益的?我猜不是?

Why on earth would you have a pool of WebClients in the first place? They are tiny, cheap objects. Did you determine by measuring that this is needed and beneficial? I assume not?

对象实例化几乎总是便宜的.HTTP 连接也不昂贵.WebClient 池是过早的优化.没有必要 - 随意创建任意数量.

Object instantiation is almost always cheap. HTTP connections are not expensive, either. A WebClient pool is premature optimization. There is no need for it - feel free to create as many as you want.

这篇关于WebClient 构建开销的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆