将自适应或优化内存策略纳入库中是否可行?
我有一个执行 I/O 的库。有几个外部旋钮用于调整内部使用的内存缓冲区的大小。当我运行一些测试时,我发现缓冲区的大小会显着影响性能。
但最佳大小似乎取决于很多因素 - PC 上的可用内存、正在处理的文件的大小(从非常小到巨大)、文件数量、输出流相对于输入流,我不确定还有什么。
在库中构建自适应记忆策略有意义吗?还是直接下注,让图书馆的用户弄清楚该使用什么更好?
有人做过这样的事情吗?这有多难?有效吗?
给定不同的缓冲区大小,我认为该库可以跟踪各种操作所需的时间,然后可以做出一些关于最佳大小的决定。我可以想象让库在初始 I/O 轮次中轮换各种缓冲区大小......然后它最终会根据结果在未来轮次中进行计算并调整缓冲区大小。但是,多久重新检查一次?多久调整一次?
I have a library that does I/O. There are a couple of external knobs for tuning the sizes of the memory buffers used internally. When I ran some tests I found that the sizes of the buffers can affect performance significantly.
But the optimum size seems to depend on a bunch of things - the available memory on the PC, the the size of the files being processed (varies from very small to huge), the number of files, the speed of the output stream relative to the input stream, and I'm not sure what else.
Does it make sense to build an adaptive memory strategy into the library? or is it better to just punt on that, and let the users of the library figure out what to use?
Has anyone done something like this - and how hard is it? Did it work?
Given different buffer sizes, I suppose the library could track the time it takes for various operations, and then it could make some decisions about which size was optimal. I could imagine having the library rotate through various buffer sizes in the initial I/O rounds... and then it eventually would do the calculations and adjust the buffer size in future rounds depending on the outcomes. But then, how often to re-check? How often to adjust?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
适应性方法有时被称为“自主的”,使用人类自主神经系统的类比:你不会有意识地控制你的心率和呼吸,你的自主神经系统会这样做。
您可以在此处阅读其中的一些内容,以及这里(对插头表示歉意,但我想表明这个概念正在被认真对待,并且体现在真正的产品。)
我使用试图做到这一点的产品的经验是,它们确实有效,但可能让我不高兴:那是因为他们倾向于采取“父亲最了解”的方法。你对你的应用程序或环境做了一些(你相信的)小改变,然后一些意想不到的事情发生了。你不知道为什么,也不知道这是否好。所以我的自治规则是:
现在,有时底层的数学相当复杂 - 考虑到一些自主系统正在发展,因此做出预测性变化(此类请求的数量不断增长,让我们提供更多资源X)所以数学模型并不平凡。因此,简单的解释并不总是可用。然而,对观看者的某种程度的反馈可以让人放心。
The adaptive approach is sometimes referred to as "autonomic", using the analogy of a Human's autonomic nervous system: you don't conciously control your heart rate and respiration, your autonomic nervous system does that.
You can read about some of this here, and here (apologies for the plugs, but I wanted to show that the concept is being taken seriously, and is manifesting in real products.)
My experience of using products that try to do this is that they do acually work, but can make me unhappy: that's because there is a tendency for them to take a "Father knows best" approach. You make some (you believe) small change to your app, or the environment and something unexecpected happens. You don't know why, and you don't know if it's good. So my rule for autonomy is:
Now sometimes the underlying math is quite complex - consider that some autonomic systems are trending and hence making predictive changes (number of requests of this type growing, let's provision more of resource X) so the mathematical models are non-trivial. Hence simple explanations are not always available. However some level of feedback to the watching humans can be reassuring.