Erlang Queue and Merle.
Joe Williams - - March 05, 2009Lately 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
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:47Thanks for having this article. Very informative indeed.
Handyman London
Nope, lost me completely! nevermind.
http://www.telephoneansweringservice.org.uk
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:54Hmmm, 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
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:54I really needed to know this thanks! going to start blogging it up
semi formal dresses
This is very interesting, but watching satellite tv online would be a lot simpler.
Posted by Bill on 30 Sep 2010 at 18:41As you can see the chain is alternating anniversary time the functions are run but due to not acceptance pass4sure SY0-201 for assorted appointment one has to grab the new adaptation of the chain anniversary time and use it for the next operation. pass4sure 640-802 I brainstorm there is apparently a cleaner way to do this, pass4sure 350-001 if I appear up with one I like it will apparently get added to mainline merle.
Posted by Ming21 on 11 Feb 2011 at 08:55I did not know that you could pass the Pid variable around like this. As we restructure our system to do called reverse lookup information, this may come in handy. I have to check it out with our supervisor. I may give this a shot. Thanks.
Posted by Mic Jenkins on 04 Mar 2011 at 22:12I like the way this article was written, do you work as a professional on this field? I am just in awe by your works be yourself quotes
Posted by Tanya on 02 Nov 2011 at 04:21
Add comment
Erlang on Twitter
» tichise (Takuya Ichise): RT @AntiBayes: 【言語別業務時の服装】
・Clojure:全裸
・Scheme:全裸
・Gauche:全裸
・Prolog:全裸
・Scala:全裸
・Erlang:全裸
・C++:全裸
» mshiba64 (Masami Shibatani): ということで、ErlangのBit Syntaxに突入。language for distributed and concurrent programだからね。
» despenjahatdos (Jon champion): Eits jangan salah begini2 saya titisan dewa erlang RT @yolapitalokaa: Yg ngepost twit kyknya jg lg galau drtd ... http://t.co/QfCyVSIl
» erlangtriaji (erlang triaji ): Sini sun ahahaha RT @Encays: Udah udah, lo berduaan aja RT @revianh: Kepooo! RT @erlangtriaji: Hadir RT @Encays: Udah, sama erlang aj
» Encays (antarif cahyadi): Menjepit RT @erlangtriaji: Tegang! RT @revianh: Kepooo! RT @erlangtriaji: Hadir RT @Encays: Udah, sama erlang aja RT @revianh
» erlangtriaji (erlang triaji ): Tegang! RT @revianh: Kepooo! RT @erlangtriaji: Hadir RT @Encays: Udah, sama erlang aja RT @revianh: Nanggepnya lama banget
» Encays (antarif cahyadi): Udah udah, lo berduaan aja RT @revianh: Kepooo! RT @erlangtriaji: Hadir RT @Encays: Udah, sama erlang aja RT @revianh: Nanggepnya lama
» revianh (Revian Hermansyah): Kepooo! RT @erlangtriaji: Hadir RT @Encays: Udah, sama erlang aja RT @revianh: Nanggepnya lama banget -_-
» erlangtriaji (erlang triaji ): Hadir RT @Encays: Udah, sama erlang aja RT @revianh: Nanggepnya lama banget -_-
» Encays (antarif cahyadi): Udah, sama erlang aja RT @revianh: Nanggepnya lama banget -_-
Statistics
Number of aggregated posts: 10454
Number of comments: 1392
Most recent article: January 31, 2012
Latest comments
» nobelboy on OpaDo Data Storage: Feel free to add some Qs here or contact me offline, and I will see what I can work into…
» darrensy on The Twisted Matrix: This has been a great idea you have shared. covers for kindle
» jony on Principle Software Engineer at LonoCloud (Full-time): That provides will become a internet marketer of little kinds of expert methods developers developing strategy using Erlang/OTP. There will…