[erlang-questions] Guidance to a cache mechanism

Paul Peregud <>
Tue Oct 30 16:14:23 CET 2012


Guarding writes to cache using gen_server is ok. You may leave want to
make ets table public and use {read_concurrency, true}.

Aside from bad performance of timer module, timer:send_interval has
other bad property. If your cache gen_server's message queue is
overloaded, timer:send_interval will add additional messages to it
thus making the problem worse.

You may also want to store datetime() of oldest entry of your ets
table in gen_server's State and check how what seconds' entries should
be trimmed while processing tick message by comparing oldest
datetime() value with current time.

On Tue, Oct 30, 2012 at 1:01 PM, Rapsey <> wrote:
> Do not use timer module. Use erlang:send_after/3
> In my experience the timer module is unreliable and send_after will always
> work.
>
>
> Sergej
>
> On Tue, Oct 30, 2012 at 12:08 PM, Maruthavanan Subbarayan
> <> wrote:
>>
>> Hi,
>>
>> I have to develop a caching queue, which also should should after a expiry
>> time.
>>
>> I may have around 500+ messages which may come in a second. Each message
>> might contain 100-200 bytes.
>>
>> So I have designed the system like below.
>>
>> 1. Queue would be a gen server.
>> 2. All messages which would come on same second would be stored in state
>> of the gen_server like a record {datetime(),[<list of messages>]}
>> 3. When the time differs, I would insert the above record to ets table and
>> update the state of gen_server.
>> 4. There would be a timer running timer:send_interval which would message
>> timeout the gen_server for every second, when this message is received, then
>> gen_server would delete the ets table according to expiry configured.
>>
>> I was looking on some guidance to check if the above is fine and with with
>> stand the performance. I am foreseeing maximum expiry would be around 60
>> minutes.
>>
>> Thanks,
>> Marutha
>>
>> _______________________________________________
>> erlang-questions mailing list
>> 
>> http://erlang.org/mailman/listinfo/erlang-questions
>>
>
>
> _______________________________________________
> erlang-questions mailing list
> 
> http://erlang.org/mailman/listinfo/erlang-questions
>



-- 
Best regards,
Paul Peregud
+48602112091



More information about the erlang-questions mailing list