一个生产者的同步+具有共享内存的多消费者模型
我想在 Unix 中实现一个具有共享内存的单生产者、多消费者模型
生产者:将数据帧(~char[1024])放入内存段
消费者:将数据memcpy到自己的私有内存中并进行一些处理
一些相关信息:
- 消费者错过一些数据帧是可以的
- 消费者是独立的,例如。如果一个消费者只获取数据 1,2,4,另一个消费者获取 2,3,5 也没关系
- 大约 10 个消费者将同时运行
- 生产者生成数据的速度比消费者处理数据的速度
- 快 慢/僵尸消费者不应该减慢整个系统
- 消费者如果看到与
我设置共享内存内容相同的数据,将跳过memcpy,并使用pthread读写锁,但它似乎比使用tcp模型慢
我的问题:哪种同步最适合对于这种模型?
I want to implement a one-producer, multiple-consumer model with shared memory in Unix
Producer: put the data frame(~char[1024]) in a memory segment
Consumers: memcpy the data into its own private memory and do some processing
Some relevant info:
- It is okay for consumer to miss some data frame
- Consumers are independent, eg. It's okay if one consumer only gets data 1,2,4, and another gets 2,3,5
- About 10 consumers will be running at the same time
- Producer can generate data faster than consumers can process
- Slow/zombie consumer should not slow down the whole system
- Consumer will skip the memcpy if it sees the same data
I have setup the shared memory stuff, and use the pthread read-write lock, but it seems slower than using a tcp model
My question: what synchronization is best suited for this kind of model?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您确定问题出在所使用的同步模型中吗?
我在想别的事情:也许制作人“保留令牌”的时间太长了。例如,生产者应该在私有内存中生成 1024 字节,并保留共享内存以用于写入新数据?
确保关键部分尽可能小。
Are you sure the problem is in the synchronization model used?
I am thinking about something else: Maybe the producer "keep the token" too long. For instance, the produced should produce the 1024 bytes in a private memory and keep the shared memory just for writing down the new data?
Be sure the critical section is as small as possible.