루비가 얼랭에 빠진 날

1,076 views

Published on

2008.5 제5회 루비세미나 발표

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,076
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
2
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

루비가 얼랭에 빠진 날

  1. 1. 루비 가 얼랭 에 빠진 날 http ://thinkr.egloos.com [email_address] 제 6 회 루비세미나 (2008.6.28)
  2. 2. Concurrency -oriented Programming
  3. 3. How Erlang programs work? <ul><li>많은 프로세스들로 구성 </li></ul><ul><ul><li>운영체제 독립적인 경량 (light-weight) 프로세스 </li></ul></ul><ul><ul><li>유일한 식별자 (Pid) </li></ul></ul><ul><ul><li>많은 프로세스를 동시 처리 (100,000 개 이상 ) </li></ul></ul><ul><li>프로세스들 간에 서로 메시지를 주고 받음 </li></ul><ul><ul><li>비동기적 메시지 전달 메커니즘 </li></ul></ul><ul><li>프로세스는 서로 연결 (link) 될 수 있음 </li></ul><ul><ul><li>연결된 프로세스가 죽으면 다른 프로세스가 통보받음 </li></ul></ul><ul><ul><li>수퍼바이저 / 워커 모델 구성 </li></ul></ul>
  4. 4. A Stateless Server Process -module(demo2). -compile(export_all). run() -> Pid = spawn(fun echo/0), Pid ! {self(), hello, 42}, receive {Pid, reply, 42} -> Pid ! stop end. echo() -> receive {From, hello, Val} -> From ! {self(), reply, Val}, echo(); % loop! stop -> io:format(&quot;Done!~n&quot;, []), ok end. P1 P2 {P1, hello, 42} {P2, reply, 42} Client Server stop
  5. 5. Benefits of COP <ul><li>성능 (Performance) </li></ul><ul><ul><li>분산 병렬 처리 </li></ul></ul><ul><ul><li>Multi-core Support </li></ul></ul><ul><li>가용성 (Reliability) </li></ul><ul><ul><li>무정지 (fault-tolerent) </li></ul></ul><ul><ul><li>Hot code swapping </li></ul></ul><ul><li>확장성 (Scalability) </li></ul>
  6. 6. generic_server OTP gen_server 비헤비어
  7. 7. Apache vs. Yaws * http://www.sics.se /~joe/apachevsyaws.html
  8. 8. RE presentational S tate T ransfer
  9. 9. RESTful URL ( Rails ) <ul><li>GET /posts index </li></ul><ul><li>GET /posts/1 show </li></ul><ul><li>GET /posts/new new </li></ul><ul><li>GET /posts/1/edit edit </li></ul><ul><li>POST /posts create </li></ul><ul><li>PUT /posts/1 update </li></ul><ul><li>DELETE /posts/1 destroy </li></ul>
  10. 10. respond_to :wow! # POST /posts # POST /posts.xml def create @post = Post.new(params[:post]) respond_to do |format| if @post.save flash[:notice] = 'Post was successfully created.' format.html { redirect_to(@post) } format.xml { render :xml => @post, :status => :created, :location => @post } else format.html { render :action => &quot;new&quot; } format.xml { render :xml => @post.errors, :status => :unprocessable_entity } end end end
  11. 11. GoogleTrends “ ruby on rails ” 1.0 1.2 2.0 resource 도입 from MVC to REST
  12. 12. The RADAR Architecture * RESTful Application, Dumb-Ass Recipient ( http://pragdave.pragprog.com/pragdave/2007/03/the_radar_archi.html )
  13. 13. Time to Relax…
  14. 14. CouchDB <ul><li>문서 (document) 기반 데이터베이스 서버 . </li></ul><ul><ul><li>Aaccessible via a RESTful JSON API </li></ul></ul><ul><ul><li>Views (incremental map/reduce) </li></ul></ul><ul><ul><li>Schema-Free </li></ul></ul><ul><ul><li>Distributed, robust architecture </li></ul></ul><ul><ul><li>Written in Erlang </li></ul></ul><ul><ul><li>Apache Incubating (alpha 0.8 release) </li></ul></ul>
  15. 15. SQL vs. CouchDB * http ://www.zefhemel.com/archives/2008/03/11/sittin-on-the-couchdb Static queries of dynamic schemas Dynamic queries of static schemas Must know only document name Must know schema to read/write a complete object Denormalized. Docs usually self contained. Data often duplicated. Normalized. Objects spread across tables. Duplication reduced. Collection of named documents with varying structure Uniform tables of data Dynamic, implicit schema Predefined, explicit schema CouchDB SQL
  16. 16. Document = JSON Object { &quot;_id&quot;:&quot;discussion_tables&quot;, &quot;_rev&quot;:&quot;D1C946B7&quot;, &quot;Subject&quot;:&quot;I like Planktion&quot;, &quot;Author&quot;:&quot;Rusty&quot;, &quot;PostedDate&quot;:&quot;2006-08-15T17:30:12-04:00&quot;, &quot;Tags&quot;:[&quot;plankton&quot;, &quot;baseball&quot;, &quot;decisions&quot;], &quot;Body&quot;:&quot;I decided today that I don't like baseball. I like plankton.&quot; }
  17. 17. Some CouchDB REST APIs <ul><li>Dababase API </li></ul><ul><ul><li>GET /_all_dbs 모든 DB </li></ul></ul><ul><ul><li>PUT /database/ 새 DB 생성 </li></ul></ul><ul><ul><li>DELETE /database/ </li></ul></ul><ul><li>Document API </li></ul><ul><ul><li>GET /database/doc_id </li></ul></ul><ul><ul><li>POST /database/ 또는 PUT /database/doc_id </li></ul></ul><ul><ul><li>PUT /database/doc_id (with ‘_rev’ property) </li></ul></ul><ul><ul><li>DELETE /database/dic_id?rev=xxx </li></ul></ul><ul><li>View API </li></ul><ul><ul><li>GET /database/_view/view_name/func_name </li></ul></ul>
  18. 18. Accessing CouchDB with Ruby <ul><li>범용 </li></ul><ul><ul><li>ActiveResource </li></ul></ul><ul><ul><li>REST Client </li></ul></ul><ul><li>CouchDB 전용 </li></ul><ul><ul><li>CouchObject </li></ul></ul><ul><ul><li>Ruby-CouchDB </li></ul></ul><ul><ul><li>ActiveCouch </li></ul></ul><ul><ul><li>Couchrest </li></ul></ul>
  19. 19. DEMO
  20. 20. Admin Interface
  21. 21. Ruby View
  22. 22. Extending ARes class CouchResource < ActiveResource::Base class << self def element_path(id, prefix_options = {}, query_options = nil) &quot;#{prefix(prefix_options)}#{collection_name}/#{id}#{query_string(query_options)}&quot; def collection_path(prefix_options = {}, query_options = nil) &quot;#{prefix(prefix_options)}#{collection_name}#{query_string(query_options)}&quot; def instantiate_collection(collection, prefix_options = {}) collection = collection.fetch(&quot;rows&quot;) if collection.kind_of? Hash def instantiate_record(record, prefix_options = {}) record = record.fetch(&quot;value&quot;) if record.has_key? &quot;value“ def find_view(view_name, func_name) find(:all, :from => &quot;/#{element_name}/_view/#{view_name}/#{func_name}&quot;) end
  23. 23. Mywiki Resource class Mywiki < CouchResource self.site = &quot;http://localhost:5984&quot; self.format = :json self.collection_name = 'mywiki' # used as a database name self.primary_key = '_id' end
  24. 24. Console Result
  25. 25. Finish!!

×