Post on 06-May-2015
description
transcript
USSD Renderer ReduxMobME Engineering Saturdays 002Vishnu Gopal
Agenda
Why Redux?
Implementation
Evented & Synchrony
Redux Internals
Calculator using Redux
Next Steps
Why Redux?
Mobile Network Operator
USSD Device
Mobile Subscriber
USSD App
MobME Server
Why Redux?
Vodafone
Comviva USSD Gateway
98468190XX
USSD Flow
USSD Renderer Redux
Why Redux?Comviva USSD Gateway
USSD Renderer Redux
MS Mobile Subscriber
MS Initiated MS -> USSD Network Initiated USSD -> MS
Request USSD -> MSResponse MS -> USSDNotify USSD -> MS (end)
Why Redux?
Slow, > 5s
Single simple response
Lots of sessions
Stateful
No extra HTTP features.
Fast, < 0.5s
Multiple resources
Minimal sessions
Stateless
Cookies, pipelining, etc.
HTTP USSD
Why Redux?Comviva USSD Gateway
USSD Renderer Redux
Protocol HTTPA USSD Response is converted to a HTTP Request with these
parameters:msisdn, input, shortcode
Why Redux?
http://host:port/ussd-121?msisdn=<msisdn>&input=
“Welcome to 121! Press 1 for Umbrellas and 2 for Raincoats”
http://host:port/ussd-121?msisdn=<msisdn>&input=2
“Thank you for choosing Raincoats. A customer service representative will shortly give you a call.”
Why Redux?
USSDRenderer
Mature, truckload of
featuresPython & YAML
Forking Processes
ProceduralNot TDDed
Why Redux?
USSDRenderer Redux
Baby, subset of features Ruby
Evented
Classes, Modular, Helpers
TDDed
Implementation: Evented
USSD Renderer
Reusable Worker Pool ->
USSD Worker ProcessMS
Worker Exhaustion When Requests are Slow
MS
MS
MS
USSD Worker Process
USSD Worker Process
USSD Worker Process
Implementation: Evented
USSD Renderer
Single Threaded Evented
Worker ->
MS
Can only saturate one core
MS
MS
MS
USSD Worker Process
Less memory, Less CPU
Implementation: Evented
Works the same way CPUs work
Pauses a request and handles another when it is waiting for input and output.
Keyboard input/output
Network requests, like HTTP API calls.
When the request finishes, a callback is fired to let the request know status (error or success)
Implementation: Evented
USSD Renderer
Single Threaded Evented
Worker ->
MS-1 USSD Worker Process
MS-2
Operator Balance
API (slow)
A B
CD
Once C is finished, MS-1 receives a callback on success, errback on failure
Implementation: Evented
a = EM::HTTPRequest.new(“http://google.com/”).get
a.callback { p a.response }
a.errback { p a.response_header.status }
Implementation: Synchrony
a = EM::HTTPRequest.new(“http://google.com/”).get
if a.response_header.status == 500
p “error”
else
p a.response
end
Implementation: Redux
Request
Input
Process
Request Notify
Implementation: Redux
Request
Input
Process
Request
Notify
Node 1Input
Process
Node 2
Implementation: Redux
index {
request {
prompt “Enter your name:”
}
process { |input|
notify “Hello #{input}!”
}
}
Implementation: Reduxindex {
request {
prompt “Enter your name:”
}
process { |input|
session[:name] = input
switch :age
}
}
age {
request {
prompt “Enter your age:”
}
process { |input|
notify “Hello #{input} year old #{session[:name]}”
}
}
Writing a Redux Calculator
Next StepsLots more features!
Menu pagination with prefixes and suffixes
Message interpolation
Redis session store
Lots of helpers for common tasks: redis, mysql, url calls
Play around with the template to create your own USSD app!
Finis.Questions?