Linux:需要设计预取器将文件从NAS缓存到系统内存中
我正在为以下场景设计一个服务器:
- 一系列单个图像存储在NAS上,假设其中有100个,
- 客户端通过TCP套接字连接到服务器并请求image39,
- 服务器从NAS读取image39并通过套接字发送回客户端
- 客户端很可能还会请求该系列中的其他图像,因此:
- 我想启动一个线程来迭代图像,读取它们,并执行
cat image39 > > /dev/null
强制缓存到服务器 - 线程上的内存中将按如下方式获取图像:image38、image40、image37、image41 等。
- 如果客户端现在请求 image77,则已获取的图像将被忽略
- ,我想重置获取线程获取:image76、image78 等。
这必须扩展到许多系列和客户端。大概是1000个并发量级 预取。我知道如果线程太多,可能会导致性能下降。分叉一个新进程会更好吗?有没有比线程或进程更有效的方法?
谢谢!!!
I am designing a server for the following scenario:
- a series of single images are stored on a NAS, lets say 100 of them
- a client connects to the server over TCP socket and requests image39
- server reads image39 from NAS and sends back to client over socket
- it is likely that the client will also request other images from the series, so:
- I would like to launch a thread that iterates through the images, reads them, and does a
cat image39 > /dev/null
to force cache into memory on server - thread will fetch images as follows: image38, image40, image37, image41, etc.
- already fetched images are ignored
- if client now requests image77, I want to reset the fetch thread to fetch: image76, image78, etc.
This has to scale to many series and clients. Probably on the order of 1000 concurrent
prefetches. I understand that threads can cause performance hit if there are too many. Would it be better to fork a new process instead? Is there a more efficient way than threads or processes ?
Thanks!!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是过早的优化。尝试在不使用“强制”缓存的技巧的情况下实现您的系统,并看看它是如何工作的。我敢打赌,一切都会好起来的——如果你的技巧与系统上的其他东西不能很好地配合,你就不必担心令人讨厌的意外。
This is premature optimization. Try implementing your system without tricks to "force" the cache, and see how it works. I bet it'll be fine--and you won't then need to worry about nasty surprises if it turns out your tricks don't play nice with other things on the system.