Your SlideShare is downloading. ×
Event loop
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Introducing the official SlideShare app

Stunning, full-screen experience for iPhone and Android

Text the download link to your phone

Standard text messaging rates apply

Event loop

548
views

Published on

A presentation to show the workings of the event loop and how vert.x uses this pattern.

A presentation to show the workings of the event loop and how vert.x uses this pattern.

Published in: Technology

0 Comments
3 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
548
On Slideshare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
15
Comments
0
Likes
3
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Event Loop + Vert.x
  • 2. Chief Developer @ Senacor Technologies AG! http://www.senacor.com! jochen.mader@senacor.com! Twitter: @codepitbull Jochen Mader
  • 3. CPU ABC 42 1 2 3 4 5 6 7 8 9 0
  • 4. CPU
  • 5. CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU
  • 6. volatile CyclicBarrier AtomicBoolean synchronized ReentrantLock AtomicInteger AtomicCafe Thread ThreadPoolExecutor Runnable Callable
  • 7. wooble http://www.wooble.wtf wooble http://www.wooble.wtf wooble http://www.wooble.wtf wooble http://www.wooble.wtf
  • 8. wooble http://www.wooble.wtf wooble http://www.wooble.wtf wooble http://www.wooble.wtf wooble http://www.wooble.wtf wooble http://www.wooble.wtf wooble http://www.wooble.wtf wooble http://www.wooble.wtf wooble http://www.wooble.wtf wooble http://www.wooble.wtf wooble http://www.wooble.wtf wooble http://www.wooble.wtf wooble http://www.wooble.wtf wooble http://www.wooble.wtf wooble http://www.wooble.wtf wooble http://www.wooble.wtf wooble http://www.wooble.wtf wooble http://www.wooble.wtf wooble http://www.wooble.wtf wooble http://www.wooble.wtf wooble http://www.wooble.wtf wooble http://www.wooble.wtf wooble http://www.wooble.wtf wooble http://www.wooble.wtf wooble http://www.wooble.wtf wooble http://www.wooble.wtf wooble http://www.wooble.wtf
  • 9. C10K ZZZZZZZZZz ZZZZZZZZZz ZZZZZZZZZz
  • 10. Single Thread 1 Thread w/ lock 2 Threads w/ lock 1 Thread w/ CAS 2 Threads w/ CAS Volatile 0 12500 25000 37500 50000 Contention https://github.com/codepitbull/lockperformance
  • 11. I/O Acces type cycles L1- Cache 3 L2-Cache 14 RAM 250 Disk 41000000 Network 240000000 http://blog.mixu.net/2011/02/01/understanding-the-node-js-event-loop/
  • 12. contentionI/O
  • 13. Channel A Channel B Channel C Channel D Selector Event Handler 1 Event Handler 2 Event Handler 3 Event Handler 4 Event Handler 5 REACTOR DO NOT BLOCK! JAVA NIO
  • 14. Selector selector = Selector.open();
 
 channel.configureBlocking(false);
 
 SelectionKey key = channel.register(selector, SelectionKey.OP_READ);
 
 while(true) {
 int readyChannels = selector.select();
 
 if(readyChannels == 0) continue;
 
 Set<SelectionKey> selectedKeys = selector.selectedKeys();
 
 Iterator<SelectionKey> keyIterator = selectedKeys.iterator();
 
 while(keyIterator.hasNext()) {
 
 SelectionKey key = keyIterator.next();
 
 if(key.isAcceptable()) {
 // a connection was accepted by a ServerSocketChannel.
 } else if (key.isConnectable()) {
 // a connection was established with a remote server.
 } else if (key.isReadable()) {
 // a channel is ready for reading
 } else if (key.isWritable()) {
 // a channel is ready for writing
 }
 
 keyIterator.remove();
 }
 }
  • 15. I NEEEEDS ! NICE API!!!!
  • 16. Channel A Channel B Channel C Channel D Selector Event Handler 1 Event Handler 2 Event Handler 3 Event Handler 4 Event Handler 5 12.10.2012
  • 17. Noch ! hübscher?
  • 18. Quasar
  • 19. 生 ॐ СВОБОДА
  • 20. Micro Services (Martin Fowler) http://martinfowler.com/articles/microservices.html
  • 21. class MustacheRendererVerticle extends Verticle {
 
 DefaultMustacheFactory mf = new DefaultMustacheFactory( "de/codepitbull/javaland/mustache");
 
 @Override
 def start() {
 vertx.eventBus.registerHandler("template.render", { message ->
 Mustache mustache = mf.compile(message.body());
 StringWriter sw = new StringWriter();
 mustache.execute(sw, new Example()).flush();
 message.reply(sw.getBuffer().toString());
 });
 }
 
 }
  • 22. Verticle Module 1 0..n 0..n 1 System vert.x module1 verticle 1 verticle 2 module2 verticle 3 verticle 4
  • 23. import org.vertx.groovy.platform.Verticle
 
 class DemoVerticle extends Verticle {
 @Override
 Object start() {
 container.deployModule("io.vertx~mod-web-server~2.0.0-final", container.config)
 }
 } io.vertx~mod-web-server~2.0.0-final
  • 24. official community 生 ॐ СВОБОДА
  • 25. Verticle Verticle Verticle Verticle Verticle Verticle Verticle Verticle
  • 26. Verticle Verticle Verticle Verticle Verticle Verticle Verticle Verticle Verticle Verticle Verticle Verticle Verticle Verticle Verticle Verticle Multicast
  • 27. mod 2mod 1 CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU vertx -ha mod ? mod ? mod ? mod ? mod ? mod ? mod ? mod ?
  • 28. mod 2mod 1 CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU vertx -ha mod ? mod ? mod ? mod ? mod ? mod ? mod ? mod ?
  • 29. mod 2mod 1 CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU vertx -ha mod ? mod ? mod ? mod ? mod ? mod ? mod ? mod ? CPU CPU CPU CPU CPU CPU CPU CPU
  • 30. mod 2mod 1 CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU vertx -ha mod ? mod ? mod ? mod ? mod ? mod ? mod ? mod ? CPU CPU CPU CPU CPU CPU CPU CPU mod 2mod 1
  • 31. DEMO
  • 32. Leseliste/Quellen http://www.cs.wustl.edu/~schmidt/PDF/reactor-siemens.pdf http://tutorials.jenkov.com/java-nio/selectors.html https://www.ibm.com/developerworks/java/library/j-jtp02225/ http://blog.tsunanet.net/2010/11/how-long-does-it-take-to-make-context.html http://blog.mixu.net/2011/02/01/understanding-the-node-js-event-loop/ http://lmax-exchange.github.io/disruptor/ https://github.com/codepitbull/lockperformance