« BD-1 2010年モデル | トップページ | 人生にホンキ »

2010年4月 8日 (木)

Ernie : Ruby/Erlang Hybrid BERT-RPC Server

Erlang
Ruby
この辺で紹介したバイナリフォーマットBERT。

当時は単なるRubyでも使用できるバイナリフォーマットとRuby実装のRPCサーバ、という程度にしか認識してなかったんですけど、BERT and BERT-RPC 1.0 Specificationを再調査してたら

BERT (Binary ERlang Term) is a flexible binary data interchange format based on (and compatible with) Erlang's binary serialization format (as used by erlang:term_to_binary/1).
ということで、どうやらErlangでノード間通信するときのシリアライズフォーマットであるExternal Term Format(ETF)を拡張しているみたいです。

Erlangはちょうど勉強中ということもあり俄然、興味が沸いてきたのでもうちょっと調べたら、Ruby実装だと思っていたBERT-RPCサーバErnieはRubyとErlangによる実装だった模様。

Ernieの内部でどうやってRubyとErlangが連携しているかも興味があるし、これは試してみなければ。

まずはErlangのインストール。

次にErnieをRubyGemsでインストール。

$ sudo gem install ernie
Password:
Building native extensions.  This could take a while...
Building native extensions.  This could take a while...
Successfully installed bert-1.1.2
Successfully installed bertrpc-1.3.0
Successfully installed ernie-2.2.0
3 gems installed

BERT本体であるbertや、クライアントのbertrpcも同時にインストールされる。

んで、BERT-RPCサーバ側のハンドラを作る。
最初はIntroducing BERT and BERT-RPCと同じコードにしてみた。

# calc.rb
require 'ernie'
mod(:calc) do fun(:add) do |a, b| a + b end end

Ernieを起動。

$ ernie -p 9999 -n 10 -h calc.rb
(略)/1.8/optparse.rb:1450:in `complete': invalid option: -n (OptionParser::InvalidOption)
  :

動かねえじゃん!!
つか、-nオプションがマズいみたいだ。

パラメタなしで起動すると…

$ ernie
A config file must be specified: ernie -c /path/to/config.yml

-cオプションでコンフィグファイルが必要みたい。

どうも初期BERTとは仕様が違うみたいなので、GitHubの最新の仕様を参照。って、サンプルも載ってんじゃん。最初から見ろよ、おれ。

というわけでハンドラを作り直し。

require 'rubygems'
require 'ernie'
module Ext def add(a, b) a + b end end
Ernie.expose(:ext, Ext)

普通のRubyモジュールの書き方なので、こっちの方がイイね。

このRubyハンドラをcalc.rbとして保存し、次にコンフィグファイルを作成。

[{module, ext},
 {type, external},
 {command, "ruby calc.rb"},
 {count, 2}].

calc.cfgとして保存。
最後がピリオド(.)で終わってるし、Erlangのリスト形式なんだと思う。
これで(たぶん)externalなハンドラ(つまりRubyのハンドラ)をextというモジュール名で、Ernieに教えてあげてるんだと思う。countはworkerの数らしい。

コンフィグファイルを使ってErnieを起動。
コンフィグファイル内で"ruby calc.rb"としているので、コンフィグファイルがあるディレクトリで下記を実行する。

$ ernie -d -p 9999 -c calc.cfg
erl -boot start_sasl -detached +Bc +K true -smp enable -pz (略)/ernie-2.2.0/bin/../ebin \
 -ernie_server_app port 9999 -ernie_server_app config '"calc.cfg"' -ernie_server_app log_level 2 -run ernie_server_app boot

うまく立ち上がった!!

$ ps x | grep ruby
 3501   ??  Ss     0:00.18 ernie handler 2.2.0 (ruby) - calc.rb - [1] waiting
 3502   ??  Ss     0:00.18 ernie handler 2.2.0 (ruby) - calc.rb - [0] waiting
 3579 s000  R+     0:00.00 grep ruby

確かにRubyプロセスが2つ待機しているようだ。

実際にErnieと通信してみる。
もちろんRubyによるクライアント実装bertrpcを使う。
スクリプトを書くほどでもないので、irbを使ってインタプリタ実行。

$ irb
>> require 'bertrpc'
=> true
>> svc = BERTRPC::Service.new('localhost',9999)
=> #<BERTRPC::Service:0x1011369b8 @port=9999, @host="localhost", @timeout=nil>
>> svc.call.ext.add(1,2)
=> 3
>> 

おお!!
call request(同期処理)がちゃんと実行されてる!!
localhostなのでありがたみがないけど。

BERTが流れる通信路の暗号化はどうすんの?とか、非同期処理(cast request)はどうすんの?とか、興味はつきないけど、ひとまず超お手軽にRPCが実現できることは分かった。

|

« BD-1 2010年モデル | トップページ | 人生にホンキ »

Erlang」カテゴリの記事

Ruby」カテゴリの記事

コメント

Buildings are not very cheap and not everybody is able to buy it. However, mortgage loans was created to aid different people in such kind of hard situations.

投稿: LyndaWall | 2012年4月 3日 (火) 22:18

A lot of students don’t know the right way to perform their philosophy essays paper. Thus, at present moment they could come along your amazing article & create the most perfect term papers ever.

投稿: social issues essays paper | 2012年10月31日 (水) 12:40

I have got different ideas , which are related with back links, nonetheless, I do not get the real way to realize them! Maybe, I will utilize the forum posting service linksexperts.com. Probable, that will help!

投稿: buy link | 2012年10月31日 (水) 13:45

Generally, high school students buy custom essays online prime-writing.com from the first custom papers writing service they see in the web. That supposes to be not correct because they may find a scam company. Therefore, it's worth to watch out with such issues.

投稿: custom term papers online | 2012年11月 5日 (月) 15:27

Thanks a lot for the superb release about this good post. I couldn’t get this kind of thesis abstract online and was going to order the dissertation "topthesis.com". Thus, I get all the information now.

投稿: dissertation | 2012年11月21日 (水) 20:09

Earlier I was exceptionally uncertain about rendering research essay writing companies as I did not think they can write a superior paper.

投稿: essay writing service | 2012年11月21日 (水) 20:25

If you have problems with producing of college papers, online writing services that propose people to buy custom papers will help you out. But, buy essays online on the net when you are certain that the agency isn't dealing in copied papers.

投稿: custom political essays | 2012年11月21日 (水) 20:45

Visit this website in order to receive a splendid look-in to purchase professional English research paper and make a change in your student’s life owing to our best academic writing services.

投稿: writing service | 2012年11月21日 (水) 21:09

I used to be frustrated just because of ranking of my website. It used to be really low. Fortunately I have found the best forum proifle service , which aided me a lot. I utilize search engine optimization constantly at this time!

投稿: social bookmarking service | 2012年11月23日 (金) 16:11

Want to get information how to write a research paper in order to have academic success? That will not be a problem if you are helped be trustworthy custom essay papers firm. Nonetheless, there are a few of expert corporations in the web. Hence, you should search tightly.

投稿: academic writing help | 2012年12月16日 (日) 11:47

Thank you, it's very brilliant description it might be very polite for students. For example last year when I had a difficult of time at the end of semester with a everlasting flow of academic assignments and job, I had a amazing idea to buy it somewhere and than use plagiarism check (plagiarismsearch.com). I was so exhausted that I did not care for what can begin when my academic work was written by another person. To my awesome surprise, research paper was worthy the price I paid for it. I was so pleased with the quality and now everytime i use this service.

投稿: check for plagiarism | 2012年12月30日 (日) 22:47

At present, a lot of buyers are seeking for software Services, but only here you will be given the best custom software services, merely visit this Web site "worldsystems.com".

投稿: up here | 2012年12月31日 (月) 22:52

Ukraine software development is created specially for individual customer in order to meet precise demands of their business.

投稿: Web developers China company | 2013年1月 3日 (木) 19:20

At present, many students are searching for superior quality authentically written essay papers. GoGetEssays rewiew will aid pupils to come across the most trustworthy essay paper writing service from which they may purchase excellent dissertations done from the very beginning.

投稿: SuperbEssay.com rewiew | 2013年1月 3日 (木) 19:46

It's not very good not to know if your text is original. I'm generally focuced on high results. Thence, I use online plagiarism checker to be sure that my content is the best.

投稿: plagiarism detection | 2013年1月 9日 (水) 15:43

Problems don't make an influence on you? Therefore, you're ready to compose the america essay. Or probably, you need to begin from not complicated book reports to to make an emphasize on your technique!

投稿: business essay paper | 2013年1月 9日 (水) 15:57

Check out our home page in order to buy essays and receive original writing services.

投稿: writing services | 2013年1月11日 (金) 11:53

Your fantastic stuff close to this good post should be open for all people, because they demand thesis service and professional dissertation writing service or just thesis abstract.

投稿: thesis writing service | 2013年4月 9日 (火) 01:46

Did not try to contact any custom buy term papers "premiumqualityessays.com" services? Hence, you didn't realize what premium quality means! I opine that you need to try it!

投稿: buy an essay | 2013年4月10日 (水) 12:15

Bothered about where to buy resume paper? Check out Prime Resume agency to obtain help with resume writing. Buy resumes from professional resume writers or read resume formats if you wish to learn what winning CV writing looks like.

投稿: Check this link | 2013年7月23日 (火) 00:01

To receive the best art essay can be not a dream anymore. Essays writing organizations furnish high school students with good quality essays. Hence, that is great opportunity for you to show your skills.

投稿: miscellaneous essay | 2013年7月24日 (水) 11:29

Click this link and you will find dependable software outsourcing services that will help you to reach your goals.

投稿: Click here | 2013年7月28日 (日) 18:56

So if you are a student who is seeking for writing help use this link. Purchase essays for college from the respectable agency and you will never feel sorry.

投稿: Internet site | 2013年7月31日 (水) 00:47

Press up here if you are looking for professional writing services. Buy custom essay, save your time and take care of your own business while well-versed writers will cope with your writing task.

投稿: essay papers | 2013年11月21日 (木) 00:28

School assignments won’tbe complicated cause nowadays actively learning people can get any type of papers for college at custom writing service. Buy paper services and enable talented wordsmiths to produce the first-rate paper project for you.

投稿: look here | 2013年11月21日 (木) 00:54

Our professional resume writers will provide resume writinghelp to job seekers who do not have time to write a resume. Consider ResumesExpert company and look through CV templates. Now you know where to buy resume paper, so do not mull over buy resumes and build up your career.

投稿: Click here | 2013年12月 4日 (水) 21:25

Are you hunting for resume services? Still have no clue how to write a resume? Check out Resumes Leader agency resumesleader.com. Here you may see resume formats or order resume from expert resume writers.

投稿: ResumesLeader page | 2013年12月 4日 (水) 21:26

Provided that you don’t have a clue where to buy resume paper and are in need of CV writing services, check out Prime Resume agency "prime-resume.com". You can look over resume writing samples as well as buy CV from best resume writers.

投稿: this Web site | 2013年12月 8日 (日) 19:16

Need to get CV writing help? Have no idea where to buy resume paper? Consider Marvelous Resume company where you can find resume templates. Our resume writers will reassure you that buying resume can bring job seekers career success!

投稿: site | 2013年12月 8日 (日) 19:22

A lot of juniors are concerned which service to choose for buying resume, but they merely need to get in touch with PERFECT RESUME company and receive professional resume writing. And also in case juniors have no clue where to look through resume formats or they need to order resume composed by expert resume writers they can opt for this trustable company.

投稿: samples of resume writing | 2013年12月12日 (木) 00:20

Don’t know which organization to select to get help from? Look over Custom-Writing testimonials, and come to a wise choice.

投稿: this site | 2013年12月12日 (木) 00:20

Would you like to get professional resume service, that suit the field of research you desire?. You can trust our resume writers, as you rely on yourself. Thanks because that’s the useful information

投稿: exclusiveresume.com | 2013年12月17日 (火) 10:45

Online writing departments with many years of experience in producing of all types of CVs will be the best supporters for those people who want experts to write a resume (resumesexpert.com).

投稿: over here | 2014年3月14日 (金) 14:44

コメントを書く



(ウェブ上には掲載しません)




トラックバック

この記事のトラックバックURL:
http://app.cocolog-nifty.com/t/trackback/16742/48033787

この記事へのトラックバック一覧です: Ernie : Ruby/Erlang Hybrid BERT-RPC Server :

« BD-1 2010年モデル | トップページ | 人生にホンキ »