ETS新的压缩特性
November 28th, 2010
即将发布的R14B01要支持ets的压缩,更大程度的提高内存的利用率。
在github上可以看到这个分支,有兴趣的同学可以下载下来看看。
压缩的时候只压缩value, key是不压缩的。 value特别简单类型的eterm也是不压缩的,因为zip压缩需要一定长度的内容,而且压缩本身也要加入一点的overload.
以下是sverker (author)的提交log.
ETS ‘compressed’ option.
The compressed format is using a slighty modified variant of the extern format
(term_to_binary). To not worsen key lookup’s too much, the top tuple itself
and the key element are not compressed. Table objects with only immediate
non-key elements will therefor not gain anything (but actually consume one
extra word for “alloc_size”).
我们来试验下吧:
# erl +ec Erlang R14B01 (erts-5.8.2) [source][/source][/source] [64-bit] [smp:48:48] [rq:48] [async-threads:0] [hipe] [kernel-poll:false] Eshell V5.8.2 (abort with ^G) 1> ets:all(). [8207,4110,13,file_io_servers,inet_hosts_file_byaddr, inet_hosts_file_byname,inet_hosts_byaddr,inet_hosts_byname, inet_cache,inet_db,global_pid_ids,global_pid_names, global_names_ext,global_names,global_locks,ac_tab] 2> ets:info(8207). [{compressed,true}, {memory,92}, {owner,<0.26.0>}, {heir,none}, {name,shell_records}, {size,0}, {node,nonode@nohost}, {named_table,false}, {type,ordered_set}, {keypos,1}, {protection,public}] 3> ets:new(xx, [public, compressed]). 16400 4> ets:info(16400). [{compressed,true}, {memory,302}, {owner,<0.32.0>}, {heir,none}, {name,xx}, {size,0}, {node,nonode@nohost}, {named_table,false}, {type,set}, {keypos,1}, {protection,public}]
祝大家玩的开心。
Post Footer automatically generated by wp-posturl plugin for wordpress.
—压缩前——
[{compressed,false},
{memory,2795863},
{owner,},
{heir,none},
{name,ets_scene_poses},
{size,275615},
{node,’xge2@192.168.1.108′},
{named_table,true},
{type,set},
{keypos,1},
{protection,protected}]
———-压缩后———–
[{compressed,true},
{memory,3071478},
{owner,},
{heir,none},
{name,ets_scene_poses},
{size,275615},
{node,’xge2@192.168.1.108′},
{named_table,true},
{type,set},
{keypos,1},
{protection,protected}]
———–
本地xp 的开发机,压缩后反而内存长了,为什么呢?
Yu Feng Reply:
January 6th, 2011 at 7:50 pm
1. 压缩的对象他挑的,不一定所有的类型都可压缩的。
2. 可压缩的对象的内容是不是有压缩率。
3. 压缩要管理成本。
博主回复真快,看来只能在有string 类型的table 里面试验了。