Download presentation
Presentation is loading. Please wait.
Published bySuzan Hines Modified over 9 years ago
1
Real-time Web Application with Node.js CENTRE FOR NETWORK RESEARCH COMPUTER ENGINEERING, PRINCE OF SONGKLA UNIVERSITY 1 Aj. Suthon, Nong Gun, Nong Pop
2
Case Study: Registrar ● Too many queries ● Too busy to write ● Slow response ● Improve by o Carefully design workflow o Find better technologies 2
3
One Possible solution ● Node.js - high performance o 8000+ concurrent connection per CPU core ● Socket.io o real-time update to Web Client o 2000+ concurrent connection per CPU core ● Redis o For caching o For publish/subscribe (PUB/SUB) ● Angular.js (to implement SPA) ● REST (to work with others like PHP) 3
4
CACHING 4 Read data Course data struct type STRING Struct type HASH Enroll data
5
PUBLISHING 5 3. REST API 4. Save data ACID 5. Update Enroll data 1. request for Sub 2. Sub 6. Pub 7. Socket IO update Enroll
6
Activity 1: Setup Git Node.js Easy PHP (VC distribution might be needed) npm (installed by Node.js) bower (run command >> npm install -g bower) 6
7
Activity 2: Prepare Database MySQL Database: registrar Source SQL file: others/registrar.sql Tables: course (id, code, title) section (course_id, title, amount) enroll (section_id, student, action_date) 7
8
Activity 3: Play with Redis To run Redis server. >> redis-server To run Redis CLI. >> redis-cli cli >> set x 10 cli >> get x Structure Type - STRING - LIST - SET - HASH - ZSET 8 SET GET HMSET HGETALL HINCRBY
9
Activity 4: Caching Source code: init.js To run >> node init.js To stop: Ctrl+C Redis key: ● course:$course_code to keep course JSON ● enroll:$course_code to keep enroll_amount of all sections in the same course 9
10
Activity 5: SPA & Socket.io Node server source: server.js To run Node server >> node server.js Web client source: public/index.html, public/js/app.js ● Part 1: Search ● Part 2: Plan (involve Socket.io) 10
11
Activity 6: SUB/PUB & Socket.io Node server source: server.js ● Every Socket.io connection has it own relationship with Redis SUB/PUB channel. ● When web client register for a course, node.js subscribe for Redis SUB/PUB channel accordingly. ● Once a message in subscribed channel is published, node.js emit socket.io message to web client 11
12
Activity 7: REST with PHP PHP Server source: php/index.php Web client source: public/index.html, public/js/app.js Some modifications are required - Apache configuration (related to document root) - PHP configuration (related to PHP redis extensions) ● Part 1: Login ● Part 2: Enroll (Increase enroll amount and publish update message to Redis SUB/PUB channel) 12
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.