7. Problems of traditional way
«There's no such thing as problems,
Mr. Green, only situations...»
Avi, «Revolver»
7
8. Problems of traditional way - Architecture
Internet/Intranet
Application Server
Cluster
Database Cluster
8
9. Problems of traditional way - Architecture
Internet/Intranet
Application Server
Cluster
Database Cluster
Another application
Server Cluster
9
10. Problems of traditional way - Architecture
Internet/Intranet
Application Server
Cluster
Database Cluster
First another
application Server
Cluster
…
Second another
application Server
Cluster
10
11. Problems of traditional way - Architecture
Internet/Intranet
Application Server
Cluster
Database Cluster
First another
application Server
Cluster
…
Second another
application Server
Cluster
11
12. Problems of traditional way - Architecture
Internet/Intranet
Application Server
Cluster
Database Cluster
First another
application Server
Cluster
…
Second another
application Server
Cluster
12
13. Problems of traditional way - Architecture
Internet/Intranet
Application Server
Cluster
Database Cluster
First another
application Server
Cluster
…
Second another
application Server
Cluster
13
14. Problems of traditional way - Architecture
Internet/Intranet
Application Server
Cluster
Database Cluster
First another
application Server
Cluster
…
Second another
application Server
Cluster
14
15. Problems of traditional way - Architecture
«Actually, the cause of computer revolution
is not that calculator has become faster and
got a lot of memory, got possibility to show
us advanced graphics, and so on; but that
cause is that computer can connect to
another computer. So, computer is not, as
usually described, the result of calculator
evolution – it`s the result of telephone
evolution!»
Andrey Verbitsky,
«SoftwarePeople 2009»
15
19. 19
So, every act of interaction between systems contain such phases as:…
Interaction core concepts
20. 20
So, every act of interaction between systems contain such phases as:
Packing message
Interaction core concepts
21. 21
So, every act of interaction between systems contain such phases as:
Packing message
Transporting message
Interaction core concepts
22. 22
So, every act of interaction between systems contain such phases as:
Packing message
Transporting message
Unpacking message
Interaction core concepts
23. 23
So, every act of interaction between systems contain such phases as:
Packing message
Transporting message
Unpacking message
… and main question is: where is the bottleneck?..
Interaction core concepts
24. Where is the bottleneck?..
Internet/Intranet
Application Server
Cluster
Database Cluster
First another
application Server
Cluster
…
Second another
application Server
Cluster
24
35. Front-end – client interaction type:
WebSockets vs AJAX
35
WebSockets AJAX (HTTP-REST)
Bi-directional:
Server <-> Client
Uni-directional:
Client -> Server -> Client
Full-duplex At a given time, either client is talking
to server or server is talking to client.
Single TCP Connection:
the HTTP connection is upgraded using
standard HTTP Upgrade mechanism and
client and server communicate over
that same TCP connection
new TCP connection is initiated for a
HTTP request and terminated after the
response is received
Lean protocol… Chatty protocol…
36. Front-end – client interaction type:
WebSockets vs AJAX
36
AJAX (HTTP-REST) Request:
POST /websocket-vs-rest-payload/webresources/rest HTTP/1.1rn
Host: localhost:8080rn
Connection: keep-alivern
Content-Length: 11rn
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_1) AppleWebKit/537.36 (KHTML, like
Gecko) Chrome/32.0.1700.107 Safari/537.36rn
Origin: chrome-extension://hgmloofddffdnphfgcellkdfbfbjeloorn
Content-Type: text/plain rn
Accept: */*rn
Accept-Encoding: gzip,deflate,sdchrn
Accept-Language: en-US,en;q=0.8rn
rn
38. Front-end – client interaction type:
WebSockets vs AJAX
38
So, These are 663 characters exchanged for a trivial “Hello World” echo.
For WebSocket, after the initial HTTP handshake, the data is minimally framed with 2
bytes.
https://github.com/javaee-samples/javaee7-
samples/tree/master/websocket/websocket-vs-rest-payload
42. Where is the bottleneck?..
Internet/Intranet
Application Server
Cluster
Database Cluster
First another
application Server
Cluster
…
Second another
application Server
Cluster
42
61. Problems of traditional way –
RESTful/MsgPack web-services
1. Messages Size
@POST
@Produces({“application/x-msgpack; qs=1”, “application/json; qs=0.75”})
public Order getOrder() {
// …
}
61
72. Problems of traditional way - JMS
@Stateless
@JMSDestinationDefinitions({@JMSDestinationDefinition(
name = "java:global/jms/myQueue",
interfaceName = "javax.jms.Queue")})
public class MessageSender {
@Inject
JMSContext context;
@Resource(mappedName="java:global/jms/myQueue")
Destination myQueue;
public void sendMessage(String message) {
context.createProducer().send(myQueue, message);
}
}
73
73. Problems of traditional way - JMS
1. Java only!
2. Messages Size
3. Lots of code (except JMS 2.0 in JEE7)
4. Lost messages
74
74. Problems of traditional way - JMS
1. Java only!
2. Messages Size
3. Lots of code (except JMS 2.0 in JEE7)
4. Lost messages
5. Duplicates
75
75. Modern alternatives
http://queues.io (~26 solutions)
Local BlockingQueue (“seda” in Apache Camel, JdbcChannelMessageStore in
Spring Integration)
ZooKeeper
JCache (Hazelcast)
In-memory NoSQL DB (Redis, DertyDB,…)
AMQP (ActiveMQ, RabbitMQ)
ZeroMQ
Amazon SQS
Apache Kafka (ZooKeeper inside!)
76
76. Modern alternatives – Local BlockingQueue
BlockingQueue queue = new ArrayBlockingQueue(1024);
Producer producer = new Producer(queue);
Consumer consumer = new Consumer(queue);
new Thread(producer).start();
new Thread(consumer).start();
Thread.sleep(4000);
77
85. Where is the bottleneck?..
Internet/Intranet
Application Server
Cluster
Database Cluster
First another
application Server
Cluster
…
Second another
application Server
Cluster
86