Real time web


Published on

Simple Introduction to Real-time systems and specially using Node.js in that - at #CATscope13 SAT 27/4/2013

Published in: Technology
  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Real time web

  1. REAL-TIME WEB Medhat Dawoud @Med7atDawoud
  2. What is Real-time web • The meaning is that: users can see the contents as fast as the author publish it (like chat applications) • A lot of technologies are used to implement the Real-time systems. • Today I’m interested in a technology that do that for us in an easy, reliable, and fantastic way
  3. To create Real-time system on web we need .. • Very fast web server. • Very very fast I/O operations (Non-blocking). • System that depend on event-driven(event-loops). • Flexible tool to handle all of this in a simple way.
  4. Some technologies for Real-time systems Python [ twisted ] Ruby [ EventMachine ] Perl [ AnyEvent ] If you deal with one of them, this presentation will be really understood at once.
  5. Finally , The Magic Technology Appears • 2009 - this guy “Ryan Dahl” releases something that support the highly-performance concurrent applications. • It’s called Node.js
  6. What is Node.js ? • In simple words Node.js is ‘server-side JavaScript’. • In not-so-simple words Node.js is a high-performance network applications framework, well optimized for high concurrent environments. • It’s Open Source. It runs well on Linux systems, can also run on Windows systems. • uses an asynchronous event-driven model.
  7. What is Node.js ? • Built and run on V8 JavaScript engine. • In ‘Node.js’ , ‘.js’ doesn’t mean that its solely written JavaScript. It is 40% JS and 60% C++. • is now the most followed project on Github, exceeding Ruby on Rails .. woooooo • From the official site: ‘Node's goal is to provide an easy way to build scalable network programs’ - (from!)
  8. Google V8 engine • V8 is an open source JavaScript engine developed by Google. It’s written in C++ and is used in Google Chrome Browser. • Faster than SpiderMonkey (used in firefox) over 4 times ( when V8 was invented )  - from an expert on stakoverflow -
  9. Theory 1 : Event-loops Event-loops are the core of event-driven programming, almost all the UI programs use event-loops to track the user event, for example: Clicks, Ajax Requests etc. Client Event loop (main thread) C++ Threadpool (worker threads) Clients send HTTP requests to Node.js server An Event-loop is woken up by OS, passes request and response objects to the thread-pool Long-running jobs run on worker threads Response is sent back to main thread via callback Event loop returns result to client
  10. Theory 2 : Non-blocking I/O • Traditional I/O var result = db.query(“select x from table_Y”); doSomethingWith(result); //wait for result! doSomethingWithOutResult(); //execution is blocked! • Non-traditional, Non-blocking I/O db.query(“select x from table_Y”,function (result){ doSomethingWith(result); //wait for result! }); doSomethingWithOutResult(); //executes without any delay!
  11. Natural & Features of Node.js ( some confusing ) • Apply it in the coolest, sexiest, most popular language on the planet. • Node.js uses an event-driven, non-blocking I/O model, which makes it lightweight. • The big support of V8 from Google is a great power.
  12. Why JavaScript was suitable for that ? • JavaScript Callbacks feature that solve the problem of event-loops. • The great NPM (Node Package Manager). • Node.js JavaScript quite different : there is no DOM implementation provided by Node.js, • i.e. you can not do this: var element = document.getElementById(“elementId”); • Everything inside Node.js runs in a single-thread. Natural & Features of Node.js ( some confusing )
  13. What can we do with Node.js • You can create an HTTP server and print ‘hello world’ on the browser in just 4 lines of JavaScript. • You can create a DNS server. • You can create a Web Chat Application like GTalk in the browser. • Node.js can also be used for creating online games, collaboration tools or anything which sends updates to the user in Real-time.
  14. Example: Creating Http server
  15. When to use Node.js ? • streaming based Real-time services, online games, web chat applications,..etc. • If you need high level concurrency and not worried about CPU-cycles. • If you are good at JavaScript code. • You will develop the front-end and back-end in the same language, what a triumph 
  16. Some Benchmarks (proof of power) Taken from: php-benchmark/wiki/Tests A benchmark between Apache+PHP and node.js, shows the response time for 1000 concurrent connections making 10,000 requests each, for 5 tests.
  17. Some Benchmarks (proof of power) Taken from: The benchmark shows the response time in milli-secs for 4 evented servers.
  18. Who is using Node.js Complete list can be found at:,-Applications,-and-Companies-Using-Node
  19. Some Modules you will love them • Express– to make things simpler e.g. syntax, DB connections. • Jade – HTML template system • Socket.IO– to create real-time apps • CoffeeScript – for easier JavaScript development Find out more about some widely used Node.js modules at:
  20. The last thing to say (How to start ?!) • Try to explore the rest of Node.js your self. • I recommend a free book to start called • ( O’raily Book : Up and Running With Node.js) • Tutorial sites: • • • • The series of articles in arabic isA on (
  21. Medhat Dawoud Twitter: @Med7atdawoud Thanks