Tho Luong
SILILAB Vietnam
Hanoi, March 1, 2014
Rubichat
Introduction2
Rubichat:
A Realtime Communication Service
Allow website owner to communicate with customer
more easily
Rubichat: customer & operator3
Introduction4
Rubichat:
A Realtime Communication Service
Allow website owner to communicate with customer
more easily
Easy to setup:
Architecture
RabbitMQ
Customer and operatorFacebook userX user
X1 X2 crane crane
tractor tractor
Java, php, spring, hibernate, amqp,
nodejs, zend framework, netty
sensor Apache
?
MySQL, Redis and MongoDB
Issue6
Develop rubiweb project in PHP using Zend
Framework
Some services were implemented in Java (30%)
Should we implement other services in Java or PHP
or both of them?
3 solutions
Solution #17
Reimplement all services in PHP
Some services will be implemented in both Java
and PHP not a big problem
PHP and Zend work well with MySQL, do they
still work well with MongoDB and Redis?
Just some services use MongoDB and Redis
not a big problem
Solution #18
When Java wants to use a service that is
implemented in PHP port this implementation to
Java?
Some services are hard to implement, ex: access
control service
Solution #1: complicated and not easy for
maintainance.
Solution #29
Beauty and maintainability are #1 priority
All services will be implemented in Java
PHP calls Java service implementations remotely
via RabbitMQ
PHP Java
e1
e2
req
resp
OK
Solution #210
Problem: how to receive response properly?
PHP -01
PHP-02Resp-02
Resp-01
Mission impossible
Solution #211
How about using one queue for each PHP request?
PHP-02
PHP-01
PHP-n
e….. …..
At least, one “dirty” queue is produced after each
PHP request lifecycle
No, RabbitMQ must manage a lot of queues.
Solution #312
RPC: PHP invokes Java API remotely
PHPJava
Server
X protocol
Issues:
1. System architecture
2. Protocol selection
3. Technology selections for Java Server
Flappy
System architecture13
Option 1: flappy accesses database directly
PHPJava
Server
X protocol
Flappy
MySQ
L
Mong
oDBRedis
Option 2: flappy serves PHP connections, access
service implentations via RabbitMQ
PHPJava
Server
Flappy
Rab
bit
MQ
MySQ
L
Mong
oDBRedis
Tractor
Tractor
…..
…..
Protocol selection14
Common RPC protocols
XML RPC
JSON RPC
Protobuf (google)
Thrift (facebook)
SOAP
Flappy uses XMPP (RFC 3920,RFC 3921) message
format
Easy to control
Familiar to Rubichat developers
XMPP in JSON format15
Stanza: IQ
Stanza: M
Binary data format16
Data type: 1 byte
RABBIT_TRACTOR_IN,
RABBIT_TRACTOR_OUT, FLAPPY_IN,
FLAPPY_OUT, NA
Length: int: 4 byte
Body
lengthtype body
1 4 length
Technologies selection17
Socket library: Netty, a great library for network
application
Twitter uses Netty to improve search engine
performance. (3x faster)
Interceptor design in Tractor server is influenced by
Netty
Netty advantages18
Asynchronous I/O: decouple threads from Client
Socket Connections
Rich Buffer data structure
Advanced Components for More Rapid
Development
Event Model based on the Interceptor Chain
Pattern
Test result19
Create 100 users, find them and measure time:
Service Query Tractor(ms) Client (ms) ∆ (ms)
Create 100 5196 5665 469
Find 1 187 203 16
Service Query Tractor(ms) Client (ms) ∆ (ms)
Create 100 4414
Find 1 34
(New FlappyClient implementation: use single connection(March 26, 2014))
20
Demo:
1. Flappy Server
2. Tractor
Solution disadvantages21
response
Flappy
PHP
Java Server
request
.phpModel
ToJSON()
.jsonTo
PhpModel()
.jsonTo
JavaModel()
.javaModel
ToJSON()
Write data-mappers
manually
Future work22
Tool for generating data mappers
Optimize PHP FlappyClient and develop clients for
other languages
Thank you!
23
Top Related