ap4r on rubykaigi2007 (english only)
DESCRIPTION
Rubykaigi2007 presentationTRANSCRIPT
AP4RKiwamu Kato & Shun’ichi Shinohara
Future Architect, Inc.
1
RubyKaigi 2007
•Introduction
•Demo
•Real world examples
•Technical topics
2
Introduction
3
Self Introduction
4
•Majored in Civil Engineering
•Has Enhanced and maintained messaging middleware in company
Kiwamu Kato
5
•Started Ruby since last year
•Leader of the AP4R team
•http://d.hatena.ne.jp/kiwamu/
6
Kiwamu Kato
shino•Programmer, I love coding !
•The language of the year is C or Haskell
7
•Last year, made a debut to the OSS world
•http://d.hatena.ne.jp/ita-wasa/
8
shino
What is AP4R ?
9
Lightweight
Messaging
10
What is AP4R ?
•Asynchronous Processing for Ruby
•Loose coupling by messaging
11
What can we do w/ AP4R ?
•Quicker response to users
•Load distribution
12
Press release 2006/09/05
13
http://itpro.nikkeibp.co.jp/article/NEWS/20060905/247218/
Key points are ..
14
Lightweight and
Robust
15
When is it useful ?
16
Quicker response to users
17
If NO speedy response is needed,
execute it later
Before
Client Server
19
A B C D ...
Client Server Messaging Server
20
After
A B
Client Server Messaging Server
21
After
A B C D ...
Useful cases
•Logging
•Sending mail
•Creating heavy summary data
•Collaboration with other systems
22
Moreover,load distribution
23
Easy to scale out
Client Server Messaging Server
24
Easy to scale out
Client Server Messaging Servers
25
Only good things ?
26
Sounds easy ?
27
(Maybe) No
28
If message deliveriesare NOT guaranteed,...
29
message lost and
message duplication
it may lead to
30
In other words...
31
•You can’t receive the goods despite payment !
•Double withdrawals !
32
Messages should be delivered in a reliable way,
33
No matter what happens
34
•Database trouble
•Network trouble
•Server down
•Busy and timeout
• ... etc
Lightweight and
Robust35
In Future Architect ...
36
•Developed own messaging library
•Named “RtFA”
We use messaging a lot
37
•Pure Java
• Its own protocol, API (≠ JMS)
•Time-proven on various systems
38
We use messaging a lot
One of illustrative cases
http://japan.internet.com/linuxtoday/20061228/5.html
Mission critical system in transportation business
39
• Over 100 million package data per day
• Load distribution and parallel processing on 8 nodes of Oracle 10g RAC
PJ summary
40
•Approx 100 servers
•Used “RtFA”, an in-house middleware
PJ summary
41
Messaging is important
43
Lightweight
Messaging44
45
http://www.pragmaticprogrammer.com/titles/fr_j2r/
http://www.oreilly.co.jp/books/9784873113203/
From RtFA to AP4R
• Based on implementation/experiences with Java,kept good parts, improved bad parts
• Focus on ease of use(API, configuration)
46
Lightweight and
Robust
47
Demo
48
•Shopping store application
•Order and payment
49
Outline
Shopping store app.
Client Rails
50
.
Payment
Order
Loose couplingClient Rails AP4R Rails × 3
51
Order
Loose couplingClient Rails AP4R Rails × 3
52
Order Payment
Loose couplingClient Rails AP4R Rails × 3
53
Order PaymentSleep 1
•Use mongrel cluster
•Stress by ab
•Monitor queue retaining status
54
Outline
Real world examples
55
Two examples
•Work With Rails
•Our internal project
56
Working With Rails
http://workingwithrails.com/
57
WWR
•is who’s who for Rails developers
• listed 7,000 people from 104 countries
58
59
WWR
•aggregates feeds from user’s blog
•has scaling problem in fetching them slow/stale
60
WWR solution
•Queue Feeds
•Fetch async’ly
"Getting Distributed with Ruby on Rails" slide #44 (from slideshare)
61
WWR solution
•Able to scale
•Flexible to feed types
62
Internal project
63
•Work sheet management app.newly-building in Ruby
Briefing
64
•Labor cost accounting app.existing in Java
Requirements
•Quick and rich UI
•Replicate data between Java and Ruby
65
With AP4R
•Separate loads from UI
• Invoke Java from Ruby async’ly
66
Separate loads from UIClient Server Messaging Server
67
Separate loads from UIClient Server Messaging Server
67
Separate loads from UIClient Server Messaging Server
67
Separate loads from UI
Create summary data, Send mails, etc.
68
Client Server Messaging Server
Async’ly invoke Java
69
Client Server Messaging Server
Async’ly invoke Java
69
Client Server Messaging Server
Async’ly invoke Java
data replication, etc.
69
Client Server Messaging Server
Async’ly invoke Java
data replication, etc.
69
Client Server Messaging Server
Utilize Async! when
• Needless proc. for responce data
• Disjoined transactions are allowable
• External calls (often slow, unstable)
70
Technical topics
71
Two topics here
•API to put messages and process flow
•Stored and Forward
72
API to put messagesand process flow
73
ap4r.async_to({specify next}, {request data} [,{more opts}])
There’s also block stylec.f. RDoc: http://ap4r.rubyforge.org/doc/
74
Class ShopController < ApplicationController
def order # synchronous side ... ap4r.async_to({:action => ‘payment’}, {:id => 1})
redirect_to ... end
def payment # asynchronous side id = params[:id] ... render :text => “true” end
end75
Process flow
76
User Apache Rails AP4R
77
User Apache Rails AP4R
order
message put
78
User Apache Rails AP4R
dispatch79
User Apache Rails AP4R
payment
80
Able to separatesync/async servers
81
User Apache Rails AP4R
82
Architecture
mongrel
reliable-msg
AP4R
XML-RPC
SOAP
HTTP
AP4R DRB
AP4R
HTTP
drubyDRB
MySQL
83
4%10%
20%
66%
DRbreliable-msgmongrelrails
Thanks to
Stored And Forward
85
Stored ?
Forward ?
86
at-least-oncebetween Producer and Channel
87
88
Enterprise Integration Patterns: Designing, Building, and Deploying Messaging Solutions by Gregor Hohpe,Bobby Woolf
Guaranteed Delivery [122]
Typical flowto create async. messages
89
start
end
90
CRUDstart
end
90
CRUD
commit
start
end
90
CRUD
commit
message put / commit
start
end
90
CRUD
commit
message put / commit
start
end
90
data
CRUD
commit
message put / commit
start
end
90
data messages
Ensure (some)
Atomicnessof
updating database andmessage creation
91
•Error occurs,
•Any following messages must NOT be queued
92
On updating database
•Everything succeeded,
•All following messages must be queued
93
On updating database
Relief
☺
94
Lightweight and
Robust95
Ap4r::Client#transaction Class ShopController < ApplicationController def order # synchronous side ap4r.transaction do ... # CRUD on database
ap4r.async_to ... end redirect_to ... end end
96
Process flow changesin queueing sequence
97
ap4r.transaction do ... # CRUD on database
ap4r.async_to(...)
end
Behind ap4r.transaction
98
ap4r.transaction do ... # CRUD on database
ap4r.async_to(...)
end
Behind ap4r.transaction
Insert into SAF table
98
ap4r.transaction do ... # CRUD on database
ap4r.async_to(...)
end
Behind ap4r.transaction
Insert into SAF table
Commit database
98
ap4r.transaction do ... # CRUD on database
ap4r.async_to(...)
end
Behind ap4r.transaction
Insert into SAF table
Commit databaseQueue messages
98
ap4r.transaction do ... # CRUD on database
ap4r.async_to(...)
end
Behind ap4r.transaction
Insert into SAF table
Commit databaseQueue messages
Store
98
ap4r.transaction do ... # CRUD on database
ap4r.async_to(...)
end
Behind ap4r.transaction
Insert into SAF table
Commit databaseQueue messages
Store
Forward
98
Sequence in detailWithout SAF
99
CRUD
commit
message put / commit
start
end
100
data messages
CRUD
commit
message put / commit
start
end
100
data messages
CRUD
commit
message put / commit
start
end
101
data messages
CRUD
commit
message put / commit
start
end
101
data messages
CRUD
commit
message put / commit
start
end
101
data messages☠
CRUD
commit
message put / commit
start
end
101
data messages☠
CRUD
commit
message put / commit
start
end
101
data messages☠
CRUDstart
end
102
data messages
counterchangecommit
message put / commit
CRUD
commit
message put / commit
start
end
103
data messages
counterchange
CRUD
commit
message put / commit
start
end
104
data messages
CRUD
commit
message put / commit
start
end
104
data messages
CRUD
commit
message put / commit
start
end
105
data messages
CRUD
commit
message put / commit
start
end
105
data messages
☠
CRUD
commit
message put / commit
start
end
105
data messages
☠
CRUD
commit
message put / commit
start
end
105
data messages
☠
CRUD
commit
message put / commit
start
end
105
data messages
•Database trouble
•Network trouble
•Server down
•busy and timeout
• ... etc
Better Safe than Sorry
106
Embrace every exceptions☺
☠
107
Sequence in detailWith SAF
108
CRUD
commitmessage put / commit
start
end
109
data messages
SAF create
SAF update
commitmessage put / commit
SAF update
CRUDstart
end
110
data messages
SAF create
commitmessage put / commit
SAF update
CRUDstart
end
110
data messages
SAF create
commitmessage put / commit
SAF update
CRUDstart
end
111
data messages
SAF create
commitmessage put / commit
SAF update
CRUDstart
end
111
data messages
SAF create
commitmessage put / commit
SAF update
CRUDstart
end
111
data messages
SAF create
commitmessage put / commit
SAF update
CRUDstart
end
111
data messages
SAF create
☺
commitmessage put / commit
SAF update
CRUDstart
end
111
data messages
SAF create
☺
commitmessage put / commit
SAF update
CRUDstart
end
111
data messages
SAF create
☺
commitmessage put / commit
SAF update
CRUDstart
end
112
data messages
SAF create
commitmessage put / commit
SAF update
CRUDstart
end
112
data messages
SAF create
message put / commitcommit
SAF update
CRUDstart
end
113
data messages
SAF create
message put / commitcommit
SAF update
CRUDstart
end
113
data messages
SAF create
message put / commitcommit
SAF update
CRUDstart
end
113
data messages
SAF create
messages
message put / commitcommit
SAF update
CRUDstart
end
113
data messages
SAF create
☺messages
message put / commitcommit
SAF update
CRUDstart
end
113
data messages
SAF create
☺messages
Recoverable
message put / commitcommit
SAF update
CRUDstart
end
113
data messages
SAF create
☺messages
message put / commitcommit
SAF update
CRUDstart
end
113
data messages
SAF create
☺messages
commitmessage put / commit
SAF update
CRUDstart
end
114
data messages
SAF create
commitmessage put / commit
SAF update
CRUDstart
end
114
data messages
SAF create
message put / commitcommit
SAF update
CRUDstart
end
115
data messages
SAF create
message put / commitcommit
SAF update
CRUDstart
end
115
data messages
SAF create
messages
message put / commitcommit
SAF update
CRUDstart
end
115
data messages
SAF create
☺messages
message put / commitcommit
SAF update
CRUDstart
end
115
data messages
SAF create
☺messages
Duplicated
message put / commitcommit
SAF update
CRUDstart
end
115
data messages
SAF create
☺messages
message put / commitcommit
SAF update
CRUDstart
end
115
data messages
SAF create
☺messages
Ensure (some)
Atomicnessof data and messages
116
at-least-oncebetween Producer and Channel
117
Summary
118
•Messaging with simple API, simple configuration.
•Seamless collaboration with Rails
119
•Automatic invocation of async proc.
•Guaranteed delivery by SAF
120
Lightweight and
Robust
121
Future Plans
122
Smooth operation ver.0.3.x
☑ Daemonize
☑ URL-rewrite filter
□ DLQ / SAF recovery
□ Protocols: Stomp, HTTP
123
Monitoring ver.0.4.x
□ Coordinate with Cacti, Nagios, etc.
□ Many AP4R processes
□ Interactive management tool
124
Step to large scale ver.0.5.x
□ Dynamic configuration
□ Automatic recovery
□ Long running
125
Others
□ Security
□ Application testing support
□ Blocking queues
126
Your patches are welcome! Thank you.
127
AP4R@RubyForge
•wiki: http://ap4r.rubyforge.org/wiki/wiki.pl?HomePage
• source: svn co svn://rubyforge.org/var/svn/ap4r
128
• Future Architect logo belong to Future Architect, Inc. Japan. All rights reserved.
• Rails logo are trademarks of David Heinemeier Hansson. All rights reserved.
• The Ruby logo is copyright c 2006, Yukihiro Matsumoto. It is released under the terms of the Creative Commons Attribution-ShareAlike 2.5 License.