erlang gen_server具有大状态 [英] erlang gen_server with a large state

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

问题描述

我有一个trie(用元组和列表实现),有几千个条目,我想支持并发读取。数据的内存占用量在10-20 MB的范围内。



维护状态和给客户端并发访问的建议方法是什么?



这是我尝试过的:



1)创建一个gen_server,以trie为状态。这样做很好,但很明显,所有的电话都是序列化的。



2)修改(1)为每个调用生成一个新的进程,该进程采用状态,请求和出发。每个新进程遍历了trie,并将结果称为 gen_server:reply / 2 。这个解决方案似乎没有起作用,因为内存和CPU使用率爆炸式增长我假设发生这种情况是因为状态被复制到每次调用的生成过程中。

解决方案

mochiigb是mochiweb,一种用例基本上它将需要您的数据结构并将其编译成一个模块,因此数据是共享的(模块常量的零拷贝)。只有在数据结构不经常变化的情况下才起作用,但这听起来像是你所拥有的。




I have a trie (implemented with tuples and lists) with several thousand entries and I would like to support concurrent reads. The memory footprint of the data is in the 10-20 MB range. The trie is built once and read only after that.

What is the recommended way to maintain the state and give clients concurrent access?

Here is what I have tried:

1) Created a gen_server with the trie as the state. This worked fine but, obviously, all calls were serialized.

2) Modified (1) to spawn a new process for each call which takes the state, the request, and From. Each new process traversed the trie and called gen_server:reply/2 with the result. This solution didn't seem to work because memory and CPU usage exploded . I assume this happened because the state was copied to the spawned process for every call.

解决方案

mochiglobal from mochiweb is designed for exactly this kind of use case. Basically it will take your data structure and compile it into a module, so the data is shared (zero copy for module constants). Only works well on data structures that don't change often, but it sounds like that's what you have.

这篇关于erlang gen_server具有大状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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