Erlang Queue and Merle.

Joe Williams - - March 05, 2009

Lately I have been playing around with the idea of adding a process pool to merle or at least a layer that allows you to use a process pool. I also happened across Erlang’s queue implementation. It has all the basic functions you expect from a queue and two API’s. So I created a branch of merle to play around with this idea. There are two main differences from the mainline merle, the first is the pid is always passed to the functions doing the work rather than using ?SERVER, for instance.

stats() ->
gen_server2:call(?SERVER, {stats}).

versus

stats(Pid) ->
gen_server2:call(Pid, {stats}).

This allows more than one gen_server process to be started, the down side being you have to pass this Pid variable around. The other change is a new module called queue_merle, this is a sort of the process pool later that interfaces with merle. Obviously this is a very rough cut but seems to do the trick. The start function starts five merle processes and adds them to the queue, rotate rotates the queue taking all the head of the queue and inserting it into the bottom. I have impletemeted getkey and set as well. They accept a queue, key and/or value. The downside to this implementation is similar to that of using merle without defining ?SERVER, you have to know what, in this case, queue you are using and you need to make sure it is the most current otherwise you will end up getting more calls to one process than another. Here is an example of usage.

1> Queue = queue_merle:start().
{[<0.39.0>,<0.38.0>,<0.37.0>,<0.36.0>],[<0.33.0>]}
2> {Queue1, Result1} = queue_merle:set(Queue, a, “asdf”).
{{[<0.33.0>,<0.39.0>,<0.38.0>],[<0.36.0>,<0.37.0>]},ok}
3> {Queue2, Result2} = queue_merle:set(Queue1, b, “1234″).
{{[<0.36.0>,<0.33.0>,<0.39.0>,<0.38.0>],[<0.37.0>]},ok}
4> {Queue3, Result3} = queue_merle:getkey(Queue2, a).
{{[<0.37.0>,<0.36.0>,<0.33.0>],[<0.38.0>,<0.39.0>]},”asdf”}
5> {Queue4, Result4} = queue_merle:getkey(Queue3, b).
{{[<0.38.0>,<0.37.0>,<0.36.0>,<0.33.0>],[<0.39.0>]},”1234″}

As you can see the queue is rotating each time the functions are run but due to not allowing for multiple assignment one has to grab the new version of the queue each time and use it for the next operation. I imagine there is probably a cleaner way to do this, if I come up with one I like it will probably get added to mainline merle. Fun stuff.



Categories: Blogs  Joe Williams  

Comments

anonymous avatar

Thanks a lot. I see I the information provided is going to help me a lot. God bless.

Now I need some help. When I first tried to run the command:

Queue=queue_merle:start(). and what I get is “:{bad_return_value,{error,econnrefused}}”.

I try to trace the connect/2 and connect/0 functions and then try to run:
queue_merle:connect(). I get the same error as above

then finally
queue_merle:connect(“localhost”,1235). I get the same error as above even if I repeat connect/2 by various values of DEFAULT_PORT.

I cant just get on. Initially I thought it was a ports problem or probably an issue with the ip address ; but I verified and made sure that the Ip address points to localhost as in :
-define(DEFAULT_HOST,{127,0,0,1}) in the merle.erl module.

Any assistance will be highly appreciated. Please email me your response to the above address.

Posted by Abiud on 27 Mar 2009 at 08:47



 
anonymous avatar

Thanks for having this article. Very informative indeed.
Handyman London

Posted by Handyman London on 29 Oct 2009 at 21:40



 
anonymous avatar

Nope, lost me completely! nevermind.
http://www.telephoneansweringservice.org.uk

Posted by Jonathan on 19 Feb 2010 at 15:51



 
anonymous avatar

I thought it was a ports problem or probably an issue with the ip address ; but I verified and made sure that the Ip address points to localhost as in :

Posted by Paul the Handyman on 22 Feb 2010 at 06:54



 
anonymous avatar

Hmmm, interesting, when I read I always try to find the best thing out of the text for me - how can I use it, how can I implement something from the text. I dont know yet how to use this info, but will bookmark it and will use it some day!
Promoting Renewable Fuel and Energy

Posted by David on 26 Feb 2010 at 17:22



 
anonymous avatar

Türkiye’nin en büyük anne -bebek & aile yaşam platformu e-bebek ve Anadolu Ulaşım’ın işbirliğinde 1 Eylül 2009 tarihinde başlatılan, “çağrı merkezinden bilet alanlara çocuk koltuğu sağlanması”na yönelik uygulamaya olan ilgi artarak devam ediyor.

1 Haziran 2010 tarihinde yürürlüğe giren, ülkemizde oto koltuğu kullanımını zorunlu hale getiren yasa ile birlikte, seyahatlerde çocuk oto koltuğuna yönelik taleplerde ciddi artış yaşandığına dikkati çeken çocuk oto koltuğu Genel Müdürü Halil Erdoğmuş, ilerleyen dönemde bu talebin daha da artacağını öngördüklerinin altını çiziyor.

Posted by cocuk on 23 Jun 2010 at 21:54



 


Add comment

Name:

Email:

URL:

Smileys

Remember my personal information

Notify me of follow-up comments?