[erlang-questions] Need some advice on implementing a Queue Server

Wes James comptekki@REDACTED
Thu Jul 30 21:02:07 CEST 2015


On Thu, Jul 30, 2015 at 12:22 PM, avinash D'silva <evnix.com@REDACTED>
wrote:
>
> Hi,
>
> I am trying to learn Erlang by implementing a small Queueing Server.
>
> What have I done so far?
> I have created a basic websocket server using cowboy.
>
> I am trying to implement a Queue which all processes can access.
>
> I have used lists which can act as queues.
>
> The basic insert function looks like this:
> Queue(Q) ->
>         receive
>                Msg ->
>                     Queue(lists:append(Q,[Msg]))
>         end.
>
> To create a Queue called "Q_1"
>
> >  pg2:create(<<"Q_1">>).
> >  P = spawn(test,Queue,[[1]]). % spawn queue and insert 1.
> >  pg2:join(<<"Q_1">>,P).
> >  P ! 2.
> >  P ! 3. % add some elements to queue.
>
> to retrieve the elements from the named Queue "Q_1":
> 1. I use [Px|_]=pg2:get_members()
> 2. then I would do something like: Px ! POP_ELEMENT
>
>
> Is there a better or more scalable way of doing this?
>
> Will this work when a lot of clients are connected( around 60), having a
insert rate of 100k elements per hour?
>
> Any help is appreciated :)
>

I did a search on yahoo for "erlang queue example" and this was the first
hit:

http://www.erlang.org/doc/man/queue.html

There were several other examples that might help.

-wes
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20150730/c4031987/attachment.htm>


More information about the erlang-questions mailing list