[erlang-questions] using flush() for batches from mailbox

AD straightflush@REDACTED
Tue Oct 16 04:43:24 CEST 2012


But thats a different mailbox no?  not sure how another_server is going to
be able to access the mailbox of the calling server unless the messages get
persisted somehow

On Mon, Oct 15, 2012 at 7:54 PM, Yogish Baliga <baliga@REDACTED> wrote:

> You can do the batching of messages in handle_cast. When number of
> messages in a batch exceed some number, do the processing in another
> process or gen_server?
>
> handle_cast(Msg, State) when length(State) > 10 ->
>    gen_server:call(another_server, State),
>    {noreply, []);
> handle_cast(Msg, State) ->
>    {noreply, [Msg|State]}.
>
>
>
> On Mon, Oct 15, 2012 at 3:04 PM, AD <straightflush@REDACTED> wrote:
>
>> Why would callers timeout (if using cast), is b/c the flush would prevent
>> the gen_server from sending a reply ?
>>
>>
>> On Mon, Oct 15, 2012 at 3:36 PM, Gleb Peregud <gleber.p@REDACTED> wrote:
>>
>>> On Mon, Oct 15, 2012 at 7:31 PM, AD <straightflush@REDACTED> wrote:
>>> > Hello,
>>> >
>>> >  I have a use case where I would like to flush() the Mailbox in a
>>> loop.  I
>>> > have a process that takes about 500ms to execute, and i would like the
>>> > process to operate on batches of messages from the Mailbox rather than
>>> 1 at
>>> > a time.  Since the sender can push messages to the mailbox at tens of
>>> > messages/sec and I would like to preserve order, the most efficient way
>>> > right now I think of is to take messages off the mailbox in batches.
>>> >
>>> > If there is a process sending to a gen_server:cast at , say, 10
>>> messages/sec
>>> > , can i use flush to consume all 10 messages from teh mailbox at once?
>>> > Something like
>>> >
>>> > flush() ->
>>> >         receive
>>> >                 _ -> flush()
>>> >         after
>>> >                 0 -> ok
>>> >         end.
>>>
>>> Of course you can. The code is correct as well. There are two problems
>>> here:
>>> 1) It will consume gen_server:calls, hence callers will timeout
>>> 2) It will consume sys messages, hence e.g. sys:get_status/1 won't work
>>>
>>> Cheers,
>>> Gleb Peregud
>>>
>>
>>
>> _______________________________________________
>> erlang-questions mailing list
>> erlang-questions@REDACTED
>> http://erlang.org/mailman/listinfo/erlang-questions
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20121015/5d3280c2/attachment.htm>


More information about the erlang-questions mailing list