H2Oではバージョン1.5より、mrubyを用い、Rackのインターフェイスに則った形でハンドラを書けるようになっています。
この機能を提供している目的は、正規表現による書き換え等を用いる複雑な設定ファイルではなくプログラミング言語を用いることで、ウェブサーバの設定をより簡潔に拡張しやすくするためです(Apacheのmod_rubyやmod_perlのようにウェブアプリケーションをウェブサーバ内で実行可能にすることではありません)。
とは言っても、現実のウェブサーバの設定においては、外部のデータベース等に問い合わせた結果に基づいたルーティングが必要になることがあります。
H2Oのようなイベントドリブンなウェブサーバ上で動作する、同期モデルを採用するRackインターフェイスを用いて記述されるハンドラ内において、データベースへの問い合わせをどのように実現すれば良いか。問い合わせが同期的だと、その間ウェブサーバの処理が止まってしまうので、Rubyで問い合わせ関数が呼ばれたタイミングで、ウェブサーバ側に処理を戻したいわけです。
そんなこんなで
そのとおりです。mrubyの構造上、Cライブラリ呼出のタイミングで非同期化するの難しそう>「mrubyのコード中でredisへのアクセスが発生した際にh2oがそのスレッドを開放できず、イベントループの恩恵が得られてない」 https://t.co/suTAf8PatM
— Kazuho Oku (@kazuho) November 10, 2015
とツイートしたところ、@kazuho むむむ、どういう改善をすれば「恩恵を得られる」ようになりますかね。改善する意志はあります。
— Yukihiro Matsumoto (@yukihiro_matz) November 10, 2015
@yukihiro_matz @kazuho CからFiberいじれるようにするとかそういう話ですかね。
— MATSUMOTO, Ryosuke (@matsumotory) November 10, 2015
@matsumotory @kazuho yieldとresumeはできますが。後はなにが必要ですか? 作るのはC関数に再入できない問題がありますが、resume同様returnでしか呼べない制限をつければ可能ですね
— Yukihiro Matsumoto (@yukihiro_matz) November 10, 2015
という流れになりました。その後、考えたところ、
@matsumotory @yukihiro_matz rack handlerをfiber内から呼ぶようにすれば、ひょっとしてmrubyに手を入れずに対応できるんじゃないかと考えています
— Kazuho Oku (@kazuho) November 10, 2015
という気がしてきたので、まずはPoCを書いてみることにしました。■Fiberを使って、同期コールを非同期化するPoC
ざっと、以下のような感じになります。Rack ハンドラ自体を Fiber 内に置き、その入出力と、非同期化したい関数(ここでは
DB#query
)が呼ばれたタイミングで Fiber.yield
を呼ぶことで、メインループ(これは実際には C で書くことになる)へ制御を戻しています。# DB class that calls yield class DB def query return Fiber.yield ["db#query"] end end # the application, written as an ordinary Rack handler app = lambda {|env| p "received request to #{env["PATH_INFO"]}" [200, {}, ["hello " + DB.new.query]] } # fiber that runs the app runner = Fiber.new { req = Fiber.yield while 1 resp = app.call(req) req = Fiber.yield ["response", resp] end } runner.resume # the app to be written in C msg = {"PATH_INFO"=> "/abc"} # set request obj while 1 status = runner.resume(msg) if status[0] == "response" resp = status[1] break elsif status[0] == "db#query" # is a database query, return the result msg = "" else raise "unexpected status:#{status[0]}" end end p "response:" + resp[2].join("")
やろうと思えばできることはわかりました。しかし、この手法には制限が2点あります。
- fiber 内からしか呼べない - それでいいのか?
- fiber 内で、Cコードを経由して呼ばれた ruby コードから Fiber.yield できない
■プロトコルバインディングの実装手法
さて、これで行けそうだということは分かったのですが、可能であることと、それが良いアプローチであることが等価であるとは限りません。そもそも、プロトコルバインディングはどのように書かれるべきなのでしょうか。2種類に大別してプロコンを書きたいと思います。
- Cライブラリのラッパーを書く
- Cライブラリが、非同期モデルをサポートしている必要がある
- イベントループ (libuv, libev, ...) 毎に対応が必要
- プロトコルを実装しなくて良い
- rubyでバインディングを書く
- プロトコルを実装する必要がある
- rubyで書ける!
- 各バックエンド (libuv, libev, ngx_mruby, h2o, ...) が同じ ruby API (TCPSocketのサブセットで良いと思う) を提供すれば、イベントループ毎の対応が不要
- Cより遅いかも…
個人的には、rubyでバインディングを書くアプローチが好みです。速度が遅いかも…という点については、Perl IO を用いた HTTP 実装を推進してきた立場から言うと、スクリプト言語のI/Oレイヤの負荷はネットワーク通信を行うプログラムにおいては多くの場合問題にならないと考えます。問題になるとすれば、通信データのパーサですが、ここのみをネイティブコード化するという手法で十分に対応できることは、Plack や Furl に慣れた Perl プログラマであれば納得できる話かと思いますし、(m)ruby においても同等かと思います。
■まとめ
長くなりましたが、H2O (あるいはイベントドリブンなプログラム一般)から、同期的に書かれたネットワーククライアントを呼び出す mruby スクリプトを起動する方法については、
- 同期的に記述されたアプリケーションを Fiber を使ったラッパーで非同期化する
- ホストプログラムは、Fiber を通じて、TCPSocket と互換性のある同期ソケット API を提供する
- プロトコルバインディングは、Rubyで(もしくは、Ruby の TCPSocket と C で書かれたプロトコルパーサを組み合わせて)提供する
ReplyDeleteشركة نقل اثاث بالخبر
شركة نقل اثاث بالقطيف
شركة نقل اثاث بالدمام
شركة نقل عفش بالقطيف
شركة نقل عفش بالاحساء
شركة غسيل مسابح بالدمام
شركة نقل عفش بالطائف
شركات نقل عفش بالدمام
شركة تنظيف خزانات بالمدينة المنورة
شركة نقل عفش بالجبيل
شركة غسيل كنب بالدمام
شركة نقل اثاث بالمدينة المنورة
شركة نقل اثاث بالمدينة المنورة
شركة نظافه بالقطيف
شركة نظافه عامه بالخبر
شركة نقل اثاث بالدمام
This blog is a great source of information which is very useful for me.
ReplyDeleteICC T20 World Cup 2016 Live Streaming
Starsports india vs Australia live streaming
IPL Schedule 2016
March 2016 Calendar Template
ReplyDeletenice article.......
ReplyDeleteHappy Holi Images 2016
Happy Holi Wallpaper 2016
Happy Holi Photos 2016
Happy Holi Pictures 2016
Happy Holi SMS 2016
Happy Holi Quotes 2016
Happy Holi SMS in Hindi
Happy Holi SMS in English
Happy Holi Wishes 2016
Happy Holi Greetings 2016
Happy Holi Date 2016
Happy Holi Whatsaap Status
Happy Holi Facebook Status
Happy Holi Facebook Cover
happy holi 2016 wishes
Happy Holi Recipes
india vs srilanka
ReplyDeleteindia vs srilanka live
india vs srilanka worldcup
live
t20worldcup live
icc t20worldcup 2016
icc t20worldcup 2016 live
icc t20worldcup highlights
worldcup live
20-20 World Cup 2016 Schedule
Happy Holi SMS in English
Happy Holi Wishes 2016
Happy Holi Greetings 2016
Happy Holi Date 2016
Happy Holi Whatsaap Status
Happy Holi Facebook Status
Happy Holi Facebook Cover
http://blog.kazuhooku.com/2015/11/mruby.html
ReplyDeleteicc t20 world cup
ReplyDeleteicc t20 world cup 2016
icc t20 world cup 2016 live
icc t20 world cup 2016 live streaming
icc t20 world cup live
t20 world 2016
t20 world cup
t20 world cup 2016 live
t20 world cup 2016 live streaming
t20 world cup live
icc t20 world cup
icc t20 world cup 2016
icc t20 world cup 2016 live
icc t20 world cup 2016 live streaming
icc t20 world cup live
t20 world 2016
t20 world cup
t20 world cup 2016 live
t20 world cup 2016 live streaming
t20 world cup live
IPL t20
IPL t20 2016
IPL t20 2016 live
IPL t20 2016 Streaming
IPL t20 2016 live Streaming
IPL t20 2016 Streaming
IPL t20 live Streaming
IPL live Streaming
IPL live
IPL t20 live
mobiles phone
hindilyrics
PnrStatus
Happy Mothers Day 2016
ReplyDeleteHappy Mothers Day 2016
Happy Fathers Day 2016
www.Mahresult.nic.in
SSC 2016
CBSE Result
Apple Live Event
Easter Bunny Coloring Pages
IPL Schedule 2016
happy birthday cakes
ReplyDeleteHi i was browsing your blog and i found it really interesting! i too have a website.Kindly check it out here
ReplyDeleteRajhans Residency Noida Extension
Rajhans Residency Noida
Rajhans Residency
Nice Article , I also have some topics visit them..............
ReplyDeleteHappy Friendship Day
Happy Friendship Day Quotes
Friendship Day Quotes
Friendship Day Images
Friendship Day Messages
Friendship Day SMS
Best Whatsapp Status
15th August Whatsapp Status
Friendship Day Whatsapp Status
Friendship Whatsapp Status
Happy Friendship Day Whatsapp Status
Happy Independence Day Whatsapp Status
Love Status for Whatsapp
Nice Whatsapp Status
Happy Birthday Whatsapp Status
Funny Whatsapp Status
Cool Whatsapp Status
Good Morning Whatsapp Status
Good Night Whatsapp Status
Best Whatsapp DP
Whatsapp Profile Picture
Parents Day Whatsapp Status
Happy Parents Day
Raksha Bandhan Whatsapp Status
Happy Raksha Bandhan Status
Rakhi Whatsapp Status
Nice Article , I also have some topics visit them..............
ReplyDeletecouples halloween costumes ideas
funny halloween costumes ideas
halloween costumes Ideas for women
couples halloween costume ideas
cute halloween costumes
family halloween costumes
halloween ideas
good halloween costumes
halloween pumpkin
Happy Navratri 2016
Happy Navratri Images
Happy Navratri
Happy Navratri Wishes
Whatsapp Status
Independence Day Whatsapp Status
Best Whatsapp Status
15 August Whatsapp Status
Friendship Day Whatsapp Status
Good Morning Whatsapp Status
Cool Whatsapp Status
Friends Whatsapp Status
Funny Whatsapp Status
Good Evening Whatsapp Status
Good Night Whatsapp Status
Happy Birthday Whatsapp Status
Happy Friendship Day Whatsapp Status
Happy Independence Day Whatsapp Status
Happy Parents Day Whatsapp Status
Love Whatsapp Status
Love Status For Whatsapp
Nice Whatsapp Status
Rakhi Whatsapp Status
Raksha Bandhan Whatsapp Status
Best Whatsapp Profile Pictures
Best Whatsapp DP
Nice Article , I also have some topics visit them..............
ReplyDeleteIndia’s Independence Day
Independence Day India
15 August Images
15 August speech
15 August Songs
15 August Quotes
15 August Whatsapp Status
15 August Facebook Status
15 August Shayari
15 August Photos
15 August Messages
15 August SMS
15 August Wishes
15 August Pictures
15 August Wallpaper
Happy Independence Day
Happy Independence Day 2016
Happy Independence Day Images
Happy Independence Day Wishes
Happy Independence Day Messages
Happy Independence Day Quotes
Happy Independence Day Songs
Happy Independence Day Bhashan
Happy Independence Day Parade
RIO Olympics 2016 Schedule
RIO 2016 Tickets
RIO Olympics 2016 Medal Tally
RIO Olympics 2016
Olympics 2016
La Tomatina
Tomatina Festival
Tomato Festival Spain
Tomatina Festival
La Tomatina 2016
Halloween Costumes
Halloween Costumes Idea
Happy Halloween Costumes
Happy Halloween 2016 ideas
Happy Halloween Ideas
halloween store
halloween express
halloween decoration Ideas
sexy halloween costumes ideas
Nice Article , I also have some topics visit them..............
ReplyDeleteHappy Raksha Bandhan
Happy Raksha Bandhan Images
Happy Raksha Bandhan Wishes
Rakhi Images
Raksha Bandhan
Raksha Bandhan 2016
Raksha Bandhan Greetings
Raksha Bandhan Images
Raksha Bandhan Messages
Raksha Bandhan Photos
Raksha Bandhan Pics
Raksha Bandhan Pictures
Raksha Bandhan SMS
Raksha Bandhan Status
Raksha Bandhan Wallpaper
Raksha Bandhan Wishes
Janmashtami Images
Happy Janmashtami
Krishna Janmashtami
Krishna Janmashtami 2016
Krishna Janmashtami Celebration
Krishna Janmashtami Facebook Status
Krishna Janmashtami Images
Krishna Janmashtami Messages
Krishna Janmashtami Photos
Krishna Janmashtami Pics
Krishna Janmashtami Pictures
Krishna Janmashtami Quotes
Krishna Janmashtami SMS
Krishna Janmashtami Wallpaper
Krishna Janmashtami Whatsapp Status
Krishna Janmashtami Wishes
Hi i was browsing your blog and i found it really interesting! i too have a website.Kindly check it out here
ReplyDeletefriendship quotes
friendship day
friendship day images
happy friendship day
happy friendship day images
friendship day quotes
images of friendship day
when is friendship day
friendship day messages
friend ship day
happy friendship day quotes
national friendship day
friendship day pics
friendship day wallpaper
friendship day photos
friendship day sms
happy friends day
friend ship day images
friendship day wishes
happy friendship quotes
friendship day pictures
Whatsapp Status
Friends Whatsapp Status
Friendship Day Whatsapp Status
Funny Whatsapp Status
Cool Whatsapp Status
Good Morning Whatsapp Status
Love Status For Whatsapp
Nice Whatsapp Status
Rakhi Whatsapp Status
Raksha Bandhan Whatsapp Status
Best Whatsapp DP
Best Whatsapp Profile Pictures
Hi i was browsing your blog and i found it really interesting! i too have a website.Kindly check it out here
ReplyDeleteGalaxy Blue Sapphire Plaza
Galaxy Blue Sapphire Noida Extension
Galaxy Blue Sapphire
Galaxy Blue Sapphire Plaza Noida
coach factory outlet
ReplyDeletenike air max
timberland outlet
adidas yeezy
louis vuitton outlet
kate spade outlet
toms shoes outlet
celine
air jordan retro
true religion outlet
mont blanc pens
coach outlet store online
coach outlet
adidas originals
louis vuitton handbags
oakley vault
jordan 11s
louis vuitton outlet
michael kors outlet clearance
coach outlet
christian louboutin flats
oakley vault
tory burch flats
michael kors handbags
ray ban sunglasses
michael kors handbags
lebron james shoes 2015
christian louboutin shoes
louis vuitton
ray ban sunglasses
jordan shoes
polo ralph lauren
coach outlet store online
cheap jordans
adidas shoes
rolex submariner
asics shoes
toms outlet
coach outlet store online clearances
louis vuitton outlet
20168.2wengdongdong
ReplyDeleteIn your blog I was happy to see your article, better than last time, and have made great progress, I am very pleased. I am looking forward to your article will become better and better.
hotmail login | red ball | 192.168.1.1
Nice Post, I also have my blog. Click on below Links to check.
ReplyDeleteHappy Navratri
Happy Navratri 2017
Happy Navratri 2017 Images
Happy Navratri 2017 Wishes
Happy Navratri 2017 Wallpaper
Happy Navratri 2017 Status
Happy Navratri 2017 Whatsapp Status
Happy Navratri 2017 Quotes
Happy Navratri 2017 SMS
Happy Navratri 2017 Messages
Happy Navratri 2017 Pictures
Happy Navratri 2017 Desktop Background Images
Happy Navratri 2017 Facebook Images
Happy Navratri 2017 Photos
Goddess Durga Images
Goddess Durga Wallpaper
Happy Navratri 2017 Songs
Happy Navratri Images
Happy Navratri Wishes
Happy Navratri Wallpaper
Happy Navratri Status
Happy Navratri Whatsapp Status
Happy Navratri Quotes
Happy Navratri SMS
Happy Navratri Messages
Happy Navratri Pictures
Happy Navratri Desktop Background Images
Happy Navratri Facebook Images
Happy Navratri Photos
Goddess Durga Images
Goddess Durga Wallpaper
Happy Navratri Songs
Very very awesome Article!!!
ReplyDeleteFind out about upcoming easter 2017>>>
Easter USA 2017
Easter Origin
Easter Day 2017
Easter 2017 Canada
Easter Holidays
Easter Monday 2017 Canada
Easter Weekend 2017 Canada
Holidays In Canada
Easter Island
Easter Island Heads
Easter Island History And Mistory
Where Is Easter Island
Easter Egg Hunt
Easter Egg Hunt Game
History Of Easter
History Of Easter Bunny
The Meaning Of Easter
Easter Egg images clip Art Pictures Of Easter Eggs Easter Egg Images Free Download
Happy Easter Images
Easter Images 2017
Happy Easter Images 2017
Easter Story
Easter Story
Meaning Of Easter
How To Celebrate Easter Around The World
Easter Celebration
Easter Facts
Facts About Easter Bunny
Easter Facts Religious
Facts About Easter Eggs
Easter Facts History
Easter Dinner Side Dishes
Very very awesome Article!!!
ReplyDeleteFind out about upcoming easter 2017>>>
Easter USA 2017
Easter Origin
Easter Day 2017
Easter 2017 Canada
Easter Holidays
Easter Monday 2017 Canada
Easter Weekend 2017 Canada
Holidays In Canada
Easter Island
Easter Island Heads
Easter Island History And Mistory
Where Is Easter Island
Easter Egg Hunt
Easter Egg Hunt Game
History Of Easter
History Of Easter Bunny
The Meaning Of Easter
Easter Egg images clip Art Pictures Of Easter Eggs Easter Egg Images Free Download
Happy Easter Images
Easter Images 2017
Happy Easter Images 2017
Easter Story
Easter Story
Meaning Of Easter
How To Celebrate Easter Around The World
Easter Celebration
Easter Facts
Facts About Easter Bunny
Easter Facts Religious
Facts About Easter Eggs
Easter Facts History
Easter Dinner Side Dishes
href="http://www.ssc10thresults2017.in/" target="_blank">ap ssc results 2017
ReplyDeletehttp://www.ssc10thresults2017.in/
ReplyDeleteNike Free Runn Shoes
ReplyDeleteNike Air Force 1 Shoes
Nike Air Zoom Shoes
Nike Rose Run Shoes
Nike Air Max 90 Shoes
Palladium Boots
Asics Gel Shoes
Salomon Speedcross 3 CS
Adidas Yeezy Boots 350
Adidas Springblade Shoes
Baja tahan karat/korosiAgen Besi Hollow
ReplyDeleteAgen Stainless steel
Harga besi cnp baja
Toko besi beton master steel ms
Supplier besi cnp baja
Supplier besi cnp baja
undangan pernikahan cute
People are crazy about Startup but some bullshit Startup ideas also running these days.
ReplyDeleteCoach Outlet ED Hardy Outlet Coach Outlet Store Online Kate Spade Outlet Cheap Jordans Coach Purses Coach Outlet Kate Spade Outlet Toms Outlet Louis Vuitton
ReplyDeleteشركة نقل عفش بالدمام الشرق الاوسط متحصصه فى نقل عفش واثاث بالدمام ونقل العفش بالخبر كما انها توفر شركة نقل عفش بالجبيل والخبر وشركة نقل عفش بالقطيف والاحساء وجميع خدمات نقل العفش والاثاث بالمنطقة الشرقية بارخص اسعار نقل عفش بالدمام وتقدم ايضا شركة تخزين عفش بالدمام والخبر
ReplyDeleteنقل عفش بالدمام
شركة نقل اثاث بالدمام
شركة نقل اثاث بالخبر
شركة نقل اثاث بالجبيل
شركة نقل عفش بالخبر
ReplyDeleteشركة نقل عفش بالقطيف
شركة نقل اثاث بالاحساء
شركة نقل عفش الجبيل
شركة نقل عفش بالدمام
شركة نقل اثاث بجدة
ReplyDeleteشركة نقل عفش بالرياض
شركة نقل عفش بالمدينة المنورة
شركة نقل عفش بالدمام
شركة نقل عفش بالدمام
ray ban sunglasses
ReplyDeletejordan shoes
true religion outlet
jordan shoes
tory burch outlet
mulberry handbags
michael kors outlet
polo ralph lauren
coach outlet online
coach outlet
chanyuan2018.02.05
If You Want Watch IPL Live Stream Then Visit www.crickspo.com, it also provide IPL Live ScoreCheck IPL Updates, IPL News, Ball By Ball Score, Men of the atch, men of the series, who won the toss today etc.
ReplyDeleteI was looking for some solution on google and then I cam across your website and got addicted. Such a nice way of website management, colours, way of writing and layout is attractive.
ReplyDeleteipl final score
ipl live stream 2018
ipl live score 2018
ipl 2018 Schedule match
watch ipl online live
ipl live score
free ipl score
ipl live stream
ipl final 2018
ipl live streaming
Hi its was really good that you have shown interest in the things I am also interested. I'd surely come back on your website for such kind of niche stuff. Hats off to you for the efforts you and your team is doing.
ReplyDeleteipl live score
free ipl score
ipl live stream
ipl final 2018
ipl live streaming
ipl final score
ipl live stream 2018
ipl live score 2018
ipl 2018 Schedule match
watch ipl online live
ReplyDeleteI was looking for some solution on google and then I cam across your website and got addicted. Such a nice way of website management, colours, way of writing and layout is attractive.
ipl live score
ipl score live
free ipl score
ipl final live streaming
ipl final 2018
ipl live streaming
ipl final score
ipl live stream 2018
ipl live score 2018
ipl Schedule 2018
watch ipl online live
ipl live score card
ipl final
ipl live stream
live ipl score
extra cover.net
today ipl live score
Thank you for sharing! Glad to see the information.
ReplyDeleteinstagram viewer
Great content, looking forward to implement all these tips!
ReplyDelete32 inches weave hair
30 inches weave hair
24 inches weave hair
20 inches weave hair
16 inches weave hair
14 inches weave hair
12 inches weave hair
ReplyDeleteThank you, the article is very petrifying, hopefully it can be useful for everyone.
Obat Tukak Lambung Paling Ampuh
Tips Paling Jitu Untuk Mengatasi Penyakit Demam Berdarah Dengue
Obat Penghancur Batu Ginjal Paling Ampuh
Tips Paling Ampuh Untuk Pengobatan Meningitis
Obat Herbal Untuk Penyakit Kolera
Cara Menghilangkan Rasa Mual
Obat Herbal Untuk Tulang Keropos
There has been an ascent in the quantity of individuals searching for approaches to address their monetary needs without the assistance of these money related establishments and new openings for work.quick car title loans chicago
ReplyDeleteThank you for joining us. his article is very helpful
ReplyDelete4 Tanaman Herbal Untuk Hernia
Cara Mengobati Penyakit Lupus
Pengobatan Untuk Rorombeheun
Khasiat dan Manfaat Obat Herbal Sarang Semut
son of manjeet singh box office collection
ReplyDeleteson of manjeet singh collection
qismat box office collection
saamy square box office collection
student of the year 2
Best Refrigerators at Lowest Price in India 2018-2019 Refrigerator are used in our daily life routine...
Mumbai Call girls
ReplyDeleteMumbai Call girls
Mumbai Call girls
Mumbai Call girls
Mumbai Call girls
Mumbai Call girls
Mumbai Call girls
Webroot.com/safe is a protection software solution that communicates with the cloud avoiding the hassle to manage the signature updates to deploy. for office setup visit office.com/setup
ReplyDelete16 inch clip in hair extensions
ReplyDelete18 inch clip in hair extensions
20 inch clip in hair extensions
22 inch clip in hair extensions
24 inch clip in hair extensions
26 inch clip in hair extensions
مثلما يلزم المراعاة بحفظ المدخرات المصنوعة من الزجاج، أو الشاشات ، أو الكريستال ، على نحو أمن جدًا ، واتباع أساليب التغليف الجيد ، لهذه المدخرات.شركة نقل عفش
ReplyDelete