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:54
Add comment
Erlang on Twitter
» wgren (Lars Westergren): Our company has invited Erlang veteran Tony Rogvall to hold a presentation about Erlang, should be interesting.
» frescosecco (frescosecco): It’s not you. It’s the Erlang debugging strangeness.
» wjlroe (Will Roe): #erlang #otp in action on my #kindle, yeah! http://twitpic.com/2my7vh
» jianzwang (Jianzhi Wang): erlang/mnesia/CAP/Two-phase commit都是需要安静下来仔细琢磨的东西,一旦决定使用,将会面临极大的风险
» fprogblogs (ФП-Блоги): dmzlj пишет: необъяснимое про erlang http://bit.ly/bWR1bK
» fprogblogs (ФП-Блоги): Dmitrii ‘Mamut’ Dimandt пишет: Flymake и Erlang http://bit.ly/cbaWMs
» sbtourist (Sergio Bossa): @dnene +1 for Clojure and/or Erlang :)
» delegatevoid (Timothy Parez): @TheColonial I’ll keep an eye on it… ever never seen anything about erlang before… only mentions from you
» pjimmy (Jimmy P): @TheColonial lol I thought you were just mad at your erlang install..
» TheColonial (OJ): @delegatevoid It’s me, trying to get a regular podcast up for erlang related stuff. Been on the backburner though.
Statistics
Number of aggregated posts: 10084
Number of comments: 564
Most recent article: September 07, 2010
Latest comments
» Simon cadbury on CouchDB Load Balancing and Replication using HAProxy.: Very nice Site number one topic Thanks you.. [url=“http://www.designscopia.com/products/outdoor-media/mobile-ads.asp”]mobile ads design [/url] | [url=“http://www.designscopia.com/products/print-material/stickers.asp”]stickers design [/url]
» dress on Reading Serialized PHP Objects from Erlang: canon lens mugs Nikon Mugs Canon Coffee Lens Mug Nikon Coffee Lens Mug anon coffee mug,canon lens mug,canon mug,canon coffee…
» dress on Fun with processes (Updated): canon lens mugs Nikon Mugs Canon Coffee Lens Mug Nikon Coffee Lens Mug anon coffee mug,canon lens mug,canon mug,canon coffee…