Erlang and Redis: read performance

◇◆丶佛笑我妖孽 提交于 2019-12-06 12:01:05

9 out of 10 times, slowness like this is a result of badly written drivers more than it is a result of the system. In this case, the ability to pipeline requests to Redis is going to be important. A client like redo can do pipelining and is maybe faster.

Also, beware measuring one process/thread only. If you want fast concurrent access, it is often balanced out against fast sequential access.

Switching to redis-erl decreased read time of 1M keys to 16 seconds. Not fast, but acceptable.

Here is new code:

-module(redis_bench2).
-export([run/0]).

-define(COUNT, 200000).

run() ->
    io:format("Start~n"),
    redis:connect([{ip, "host"}, {port, 6379}, {db, 0}, {pass, "pass"}]),
    read_from_redis().

read_from_redis(<<"0">>) ->
    ok;
read_from_redis(Cursor) ->
    [{ok, Cursor1}|_] = redis:q(["ZSCAN", "if:push:sset:test", Cursor, "COUNT", ?COUNT]),
    io:format("Batch~n"),
    read_from_redis(Cursor1).

read_from_redis() ->
    [{ok, Cursor}|_] = redis:q(["ZSCAN", "if:push:sset:test", 0, "COUNT", ?COUNT]),
    read_from_redis(Cursor).
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!