SlideShare ist ein Scribd-Unternehmen logo
1 von 26
Downloaden Sie, um offline zu lesen
Zing Me Web Chat Architect




              By Chau Nguyen Nhat Thanh
                ZingMe Technical Manager
                     Web Technical - VNG
Agenda

●
    About Zing Me
●
    Zing Me platform strategy
●
    Zing Me web chat architect
    ●
        Problem with real time message in HTTP
    ●
        Connection server
    ●
        Message server
    ●
        Online server
●
    Some statistic information
                                                 2
About Zing Me
SNS Platform
Updated stats
●   45M registered accounts
●   2.2M daily active users
●   7M monthly active users
●   > 500 servers (2 K cores)
    ●   70 DB servers, >60 Memcached servers
    ●   ~ 150 Web servers
    ●   40 servers for Hadoop farm
    ●   Others (storage, ...)
Zing Me Technology
●   Load balancing: HA proxy, LVS
●   Web server: Nginx, Lighttpd
●   Web caching: Squid, Varnish
●   Caching: Redis, Memcached, Membase
●   CDN: in progress
●   Programming language: PHP, C++,Java, Python,
    Bash script, Erlang
●   Searching: Solr, Lucene
●   DB: MySQL , Cassandra, HBase
●   Log system: Scriber + Hadoop
Zing Me platform strategy
●   Open platform
    ●   Open Social API
    ●   Open Auth
    ●   Zing Connect
    ●   http://open.me.zing.vn/
●   Open service
    ●   Cloud Memcache
    ●   Cloud Key Value Storage
    ●   Virtualization for Hosting Service
Zing Me platform strategy
●   Focus on communication tools:
    ●   Email: Zing mail
    ●   Private message
    ●   IM : ZingMe Web Chat
    ●   Notification: Zing Notification System
Zing Me Web Chat
     Architect
Frontend UI
Problem with realtime message
●   Realtime message in HTTP
    ●   Browser actively connect to web server
    ●   How can web server push the new message to the
        browser ?
    ●   COMET is the answer
●   COMET overview
    ●   Comet is a web application model in which a long-held
        HTTP request allows a web server to push data to a
        browser, without the browser explicitly requesting it
        (wikipedia)
    ●   Implementation: hiden iframe, ajax long-polling, script
        tag long polling
Frontend JS
●   2 developers in 4 months
●   Building from the scratch based on
    zmCore.js, a Zing Me homemade js
    framework
●   Using long-polling for pushing new messge
●   Get online friend list
●   Get last message
●   Verify session
Backend
●   Must scalable
●   Handle large number of connetions
●   Connection server handles the long-polling
    connection
●   Friend Online server keeps track online friends
●   Message Server stores the messages
●   Message Delivery Worker transfers messages from
    the Message Server to Connection Server
●   Channel Server maps the users with their
    connections
Web Chat Architect Overview
Connection Server
●   Must handle large number of concurrent
    connections ( > 100K connections)
●   Implement in C++
●   Using native EPOLL system call
●   NONBLOCKING mode for async IO
●   Dev in 8 months
Connection Server
            Implementation
●   Long polling
Connection Server
            Implementation
●   Keep connections until message come or
    timeout
●   Server must keep a large number of
    connections (C100K)
●   Use the same solution like memcached,
    haproxy
Connection Server
              Implementation
●   Why EPOLL?
    ●   General way to implement tcp servers is “one
        thread/process per connection”. But on high
        loads this approach can be not so efficient and
        we need to use another patterns of connection
        handling.(kovyri.net)
    ●   Need an asynchronous way
    ●   EPOLL is the solution
Connection Server
                   Implementation
●   Coding with EPOLL
    ●   Create specific file descriptor for epoll calls:
        epfd = epoll_create(EPOLL_QUEUE_LEN);
    ●   After first step you can add your descriptors to epoll with following call:
        static struct epoll_event ev;
        int client_sock;
         ...
        ev.events = EPOLLIN | EPOLLPRI | EPOLLERR | EPOLLHUP;
        ev.data.fd = client_sock;
        int res = epoll_ctl(epfd, EPOLL_CTL_ADD, client_sock, &ev);
Connection Server
                            Implementation
●   When all your descriptors will be added to epoll, your process can idle and wait to
    something to do with epoll’ed sockets:
     while (1) {
         // wait for something to do...
         int nfds = epoll_wait(epfd, events,
                               MAX_EPOLL_EVENTS_PER_RUN,
                               EPOLL_RUN_TIMEOUT);
         if (nfds < 0) die("Error in epoll_wait!");
         // for each ready socket
         for(int i = 0; i < nfds; i++) {
             int fd = events[i].data.fd;
             handle_io_on_socket(fd);
         }
     }
Friend Online Server
●   Hard to scale
●   Implement in C++
●   Using some cheats to define user online
●   Caching is hard
●   Dev in 1 month
Message Server
●   Store the messages
●   Implement in Java
●   Problem with memory usage
    ●   C++ version in progress
●   Notify new message by queue
●   Worker will deliver message to user by
    connection server
Web Chat statistic
Total message
Hourly stats
Q&A




Contact info:
         Chau Nguyen Nhat Thanh

       thanhcnn@vng.com.vn

       me.zing.vn/thanhcnn2000

Weitere ähnliche Inhalte

Was ist angesagt?

Experience lessons from architecture of zalo real time system
Experience lessons from architecture of zalo real time systemExperience lessons from architecture of zalo real time system
Experience lessons from architecture of zalo real time system
Zalo_app
 
Zing Database – Distributed Key-Value Database
Zing Database – Distributed Key-Value DatabaseZing Database – Distributed Key-Value Database
Zing Database – Distributed Key-Value Database
zingopen
 
Php & web server performace
Php & web server performacePhp & web server performace
Php & web server performace
Tuyển Đoàn
 
ASP.NET Scalability - WebDD
ASP.NET Scalability - WebDDASP.NET Scalability - WebDD
ASP.NET Scalability - WebDD
Phil Pursglove
 
From One to a Cluster
From One to a ClusterFrom One to a Cluster
From One to a Cluster
guestd34230
 
ASP.NET Scalability - VBUG London
ASP.NET Scalability - VBUG LondonASP.NET Scalability - VBUG London
ASP.NET Scalability - VBUG London
Phil Pursglove
 

Was ist angesagt? (16)

Experience lessons from architecture of zalo real time system
Experience lessons from architecture of zalo real time systemExperience lessons from architecture of zalo real time system
Experience lessons from architecture of zalo real time system
 
Web performance optimization - MercadoLibre
Web performance optimization - MercadoLibreWeb performance optimization - MercadoLibre
Web performance optimization - MercadoLibre
 
Zing Database – Distributed Key-Value Database
Zing Database – Distributed Key-Value DatabaseZing Database – Distributed Key-Value Database
Zing Database – Distributed Key-Value Database
 
SPDY @Zynga
SPDY @ZyngaSPDY @Zynga
SPDY @Zynga
 
Php & web server performace
Php & web server performacePhp & web server performace
Php & web server performace
 
Web Performance Part 3 "Server-side tips"
Web Performance Part 3  "Server-side tips"Web Performance Part 3  "Server-side tips"
Web Performance Part 3 "Server-side tips"
 
Optimising for Performance
Optimising for PerformanceOptimising for Performance
Optimising for Performance
 
2013 - Brian Stanley - Memcached, Cached all the things
2013 - Brian Stanley - Memcached, Cached all the things2013 - Brian Stanley - Memcached, Cached all the things
2013 - Brian Stanley - Memcached, Cached all the things
 
NGINX for Application Delivery & Acceleration
NGINX for Application Delivery & AccelerationNGINX for Application Delivery & Acceleration
NGINX for Application Delivery & Acceleration
 
WordCamp RVA
WordCamp RVAWordCamp RVA
WordCamp RVA
 
ASP.NET Scalability - WebDD
ASP.NET Scalability - WebDDASP.NET Scalability - WebDD
ASP.NET Scalability - WebDD
 
From One to a Cluster
From One to a ClusterFrom One to a Cluster
From One to a Cluster
 
How fast is it?
How fast is it?How fast is it?
How fast is it?
 
ASP.NET Scalability - VBUG London
ASP.NET Scalability - VBUG LondonASP.NET Scalability - VBUG London
ASP.NET Scalability - VBUG London
 
Warsaw MuleSoft Meetup #12 Effective Streaming
Warsaw MuleSoft Meetup #12 Effective StreamingWarsaw MuleSoft Meetup #12 Effective Streaming
Warsaw MuleSoft Meetup #12 Effective Streaming
 
Benchmarking NGINX for Accuracy and Results
Benchmarking NGINX for Accuracy and ResultsBenchmarking NGINX for Accuracy and Results
Benchmarking NGINX for Accuracy and Results
 

Andere mochten auch

Design a scalable social network: Problems and solutions
Design a scalable social network: Problems and solutionsDesign a scalable social network: Problems and solutions
Design a scalable social network: Problems and solutions
Chau Thanh
 
megastar - zing me social network story
megastar - zing me social network storymegastar - zing me social network story
megastar - zing me social network story
zingopen
 
Zing Me Launch Meetup July 2011
Zing Me Launch Meetup July 2011Zing Me Launch Meetup July 2011
Zing Me Launch Meetup July 2011
Nguyen Trong
 
Zing Me - Open Platform Introduction
Zing Me - Open Platform IntroductionZing Me - Open Platform Introduction
Zing Me - Open Platform Introduction
khaivq
 
Buiding and Deploying SaaS with WSO2 as as-a-Service
Buiding and Deploying SaaS with WSO2 as as-a-ServiceBuiding and Deploying SaaS with WSO2 as as-a-Service
Buiding and Deploying SaaS with WSO2 as as-a-Service
WSO2
 
Distributing Data The Aerospike Way
Distributing Data The Aerospike WayDistributing Data The Aerospike Way
Distributing Data The Aerospike Way
Aerospike, Inc.
 

Andere mochten auch (20)

Building ZingMe News Feed System
Building ZingMe News Feed SystemBuilding ZingMe News Feed System
Building ZingMe News Feed System
 
Design a scalable social network: Problems and solutions
Design a scalable social network: Problems and solutionsDesign a scalable social network: Problems and solutions
Design a scalable social network: Problems and solutions
 
Inside Zalo: Developing a mobile messenger for the audience of millions - VN ...
Inside Zalo: Developing a mobile messenger for the audience of millions - VN ...Inside Zalo: Developing a mobile messenger for the audience of millions - VN ...
Inside Zalo: Developing a mobile messenger for the audience of millions - VN ...
 
Architecture Patterns - Open Discussion
Architecture Patterns - Open DiscussionArchitecture Patterns - Open Discussion
Architecture Patterns - Open Discussion
 
facebook architecture for 600M users
facebook architecture for 600M usersfacebook architecture for 600M users
facebook architecture for 600M users
 
Developing High Performance Application with Aerospike & Go
Developing High Performance Application with Aerospike & GoDeveloping High Performance Application with Aerospike & Go
Developing High Performance Application with Aerospike & Go
 
IoT and developer chances
IoT and developer chancesIoT and developer chances
IoT and developer chances
 
Design a scalable social network: Problems and Solutions
Design a scalable social network: Problems and SolutionsDesign a scalable social network: Problems and Solutions
Design a scalable social network: Problems and Solutions
 
Live Analytics with Go & Aerospike
Live Analytics with Go & AerospikeLive Analytics with Go & Aerospike
Live Analytics with Go & Aerospike
 
Zing me overview
Zing me overviewZing me overview
Zing me overview
 
Zing me credential
Zing me credentialZing me credential
Zing me credential
 
Zing me build brand engagement with zing me aug 2011
Zing me   build brand engagement with zing me aug 2011Zing me   build brand engagement with zing me aug 2011
Zing me build brand engagement with zing me aug 2011
 
megastar - zing me social network story
megastar - zing me social network storymegastar - zing me social network story
megastar - zing me social network story
 
Zing Me Launch Meetup July 2011
Zing Me Launch Meetup July 2011Zing Me Launch Meetup July 2011
Zing Me Launch Meetup July 2011
 
ZING: the Next Generation of Z39.50
ZING: the Next Generation of Z39.50ZING: the Next Generation of Z39.50
ZING: the Next Generation of Z39.50
 
Giving Your Presentations Zing!
Giving Your Presentations Zing!Giving Your Presentations Zing!
Giving Your Presentations Zing!
 
Zing Me - Open Platform Introduction
Zing Me - Open Platform IntroductionZing Me - Open Platform Introduction
Zing Me - Open Platform Introduction
 
Getting The Most Out Of Your Flash/SSDs
Getting The Most Out Of Your Flash/SSDsGetting The Most Out Of Your Flash/SSDs
Getting The Most Out Of Your Flash/SSDs
 
Buiding and Deploying SaaS with WSO2 as as-a-Service
Buiding and Deploying SaaS with WSO2 as as-a-ServiceBuiding and Deploying SaaS with WSO2 as as-a-Service
Buiding and Deploying SaaS with WSO2 as as-a-Service
 
Distributing Data The Aerospike Way
Distributing Data The Aerospike WayDistributing Data The Aerospike Way
Distributing Data The Aerospike Way
 

Ähnlich wie Zing Me Real Time Web Chat Architect

Zingme practice for building scalable website with PHP
Zingme practice for building scalable website with PHPZingme practice for building scalable website with PHP
Zingme practice for building scalable website with PHP
Võ Duy Tuấn
 
zingmepracticeforbuildingscalablewebsitewithphp
zingmepracticeforbuildingscalablewebsitewithphpzingmepracticeforbuildingscalablewebsitewithphp
zingmepracticeforbuildingscalablewebsitewithphp
hazzaz
 
01 zingme practice for building scalable website with php
01 zingme practice for building scalable website with php01 zingme practice for building scalable website with php
01 zingme practice for building scalable website with php
Nguyen Duc Phu
 
Php Inside - confoo 2011 - Derick Rethans
Php Inside -  confoo 2011 - Derick RethansPhp Inside -  confoo 2011 - Derick Rethans
Php Inside - confoo 2011 - Derick Rethans
Bachkoutou Toutou
 
HTML5/JavaScript Communication APIs - DPC 2014
HTML5/JavaScript Communication APIs - DPC 2014HTML5/JavaScript Communication APIs - DPC 2014
HTML5/JavaScript Communication APIs - DPC 2014
Christian Wenz
 
Integrating Node.js with PHP
Integrating Node.js with PHPIntegrating Node.js with PHP
Integrating Node.js with PHP
Lee Boynton
 

Ähnlich wie Zing Me Real Time Web Chat Architect (20)

Monkey Server
Monkey ServerMonkey Server
Monkey Server
 
Zingme practice for building scalable website with PHP
Zingme practice for building scalable website with PHPZingme practice for building scalable website with PHP
Zingme practice for building scalable website with PHP
 
zingmepracticeforbuildingscalablewebsitewithphp
zingmepracticeforbuildingscalablewebsitewithphpzingmepracticeforbuildingscalablewebsitewithphp
zingmepracticeforbuildingscalablewebsitewithphp
 
01 zingme practice for building scalable website with php
01 zingme practice for building scalable website with php01 zingme practice for building scalable website with php
01 zingme practice for building scalable website with php
 
Nodejs
NodejsNodejs
Nodejs
 
Beginners Node.js
Beginners Node.jsBeginners Node.js
Beginners Node.js
 
Full stack development
Full stack developmentFull stack development
Full stack development
 
Node.js scaling in highload
Node.js scaling in highloadNode.js scaling in highload
Node.js scaling in highload
 
Node.js Presentation
Node.js PresentationNode.js Presentation
Node.js Presentation
 
ServerSentEvents.pdf
ServerSentEvents.pdfServerSentEvents.pdf
ServerSentEvents.pdf
 
Netty training
Netty trainingNetty training
Netty training
 
Zero Downtime JEE Architectures
Zero Downtime JEE ArchitecturesZero Downtime JEE Architectures
Zero Downtime JEE Architectures
 
USENIX LISA15: How TubeMogul Handles over One Trillion HTTP Requests a Month
USENIX LISA15: How TubeMogul Handles over One Trillion HTTP Requests a MonthUSENIX LISA15: How TubeMogul Handles over One Trillion HTTP Requests a Month
USENIX LISA15: How TubeMogul Handles over One Trillion HTTP Requests a Month
 
Netty training
Netty trainingNetty training
Netty training
 
Php Inside - confoo 2011 - Derick Rethans
Php Inside -  confoo 2011 - Derick RethansPhp Inside -  confoo 2011 - Derick Rethans
Php Inside - confoo 2011 - Derick Rethans
 
Massively Scaled High Performance Web Services with PHP
Massively Scaled High Performance Web Services with PHPMassively Scaled High Performance Web Services with PHP
Massively Scaled High Performance Web Services with PHP
 
Unite2014 Bunny Necropsy - Servers, Syncing Game State, Security and Optimiza...
Unite2014 Bunny Necropsy - Servers, Syncing Game State, Security and Optimiza...Unite2014 Bunny Necropsy - Servers, Syncing Game State, Security and Optimiza...
Unite2014 Bunny Necropsy - Servers, Syncing Game State, Security and Optimiza...
 
How to connect 1980 and 2018
How to connect 1980 and 2018How to connect 1980 and 2018
How to connect 1980 and 2018
 
HTML5/JavaScript Communication APIs - DPC 2014
HTML5/JavaScript Communication APIs - DPC 2014HTML5/JavaScript Communication APIs - DPC 2014
HTML5/JavaScript Communication APIs - DPC 2014
 
Integrating Node.js with PHP
Integrating Node.js with PHPIntegrating Node.js with PHP
Integrating Node.js with PHP
 

Kürzlich hochgeladen

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 

Kürzlich hochgeladen (20)

Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Cyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfCyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdf
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 

Zing Me Real Time Web Chat Architect

  • 1. Zing Me Web Chat Architect By Chau Nguyen Nhat Thanh ZingMe Technical Manager Web Technical - VNG
  • 2. Agenda ● About Zing Me ● Zing Me platform strategy ● Zing Me web chat architect ● Problem with real time message in HTTP ● Connection server ● Message server ● Online server ● Some statistic information 2
  • 5. Updated stats ● 45M registered accounts ● 2.2M daily active users ● 7M monthly active users ● > 500 servers (2 K cores) ● 70 DB servers, >60 Memcached servers ● ~ 150 Web servers ● 40 servers for Hadoop farm ● Others (storage, ...)
  • 6. Zing Me Technology ● Load balancing: HA proxy, LVS ● Web server: Nginx, Lighttpd ● Web caching: Squid, Varnish ● Caching: Redis, Memcached, Membase ● CDN: in progress ● Programming language: PHP, C++,Java, Python, Bash script, Erlang ● Searching: Solr, Lucene ● DB: MySQL , Cassandra, HBase ● Log system: Scriber + Hadoop
  • 7. Zing Me platform strategy ● Open platform ● Open Social API ● Open Auth ● Zing Connect ● http://open.me.zing.vn/ ● Open service ● Cloud Memcache ● Cloud Key Value Storage ● Virtualization for Hosting Service
  • 8. Zing Me platform strategy ● Focus on communication tools: ● Email: Zing mail ● Private message ● IM : ZingMe Web Chat ● Notification: Zing Notification System
  • 9. Zing Me Web Chat Architect
  • 11. Problem with realtime message ● Realtime message in HTTP ● Browser actively connect to web server ● How can web server push the new message to the browser ? ● COMET is the answer ● COMET overview ● Comet is a web application model in which a long-held HTTP request allows a web server to push data to a browser, without the browser explicitly requesting it (wikipedia) ● Implementation: hiden iframe, ajax long-polling, script tag long polling
  • 12. Frontend JS ● 2 developers in 4 months ● Building from the scratch based on zmCore.js, a Zing Me homemade js framework ● Using long-polling for pushing new messge ● Get online friend list ● Get last message ● Verify session
  • 13. Backend ● Must scalable ● Handle large number of connetions ● Connection server handles the long-polling connection ● Friend Online server keeps track online friends ● Message Server stores the messages ● Message Delivery Worker transfers messages from the Message Server to Connection Server ● Channel Server maps the users with their connections
  • 14. Web Chat Architect Overview
  • 15. Connection Server ● Must handle large number of concurrent connections ( > 100K connections) ● Implement in C++ ● Using native EPOLL system call ● NONBLOCKING mode for async IO ● Dev in 8 months
  • 16. Connection Server Implementation ● Long polling
  • 17. Connection Server Implementation ● Keep connections until message come or timeout ● Server must keep a large number of connections (C100K) ● Use the same solution like memcached, haproxy
  • 18. Connection Server Implementation ● Why EPOLL? ● General way to implement tcp servers is “one thread/process per connection”. But on high loads this approach can be not so efficient and we need to use another patterns of connection handling.(kovyri.net) ● Need an asynchronous way ● EPOLL is the solution
  • 19. Connection Server Implementation ● Coding with EPOLL ● Create specific file descriptor for epoll calls: epfd = epoll_create(EPOLL_QUEUE_LEN); ● After first step you can add your descriptors to epoll with following call: static struct epoll_event ev; int client_sock; ... ev.events = EPOLLIN | EPOLLPRI | EPOLLERR | EPOLLHUP; ev.data.fd = client_sock; int res = epoll_ctl(epfd, EPOLL_CTL_ADD, client_sock, &ev);
  • 20. Connection Server Implementation ● When all your descriptors will be added to epoll, your process can idle and wait to something to do with epoll’ed sockets: while (1) { // wait for something to do... int nfds = epoll_wait(epfd, events, MAX_EPOLL_EVENTS_PER_RUN, EPOLL_RUN_TIMEOUT); if (nfds < 0) die("Error in epoll_wait!"); // for each ready socket for(int i = 0; i < nfds; i++) { int fd = events[i].data.fd; handle_io_on_socket(fd); } }
  • 21. Friend Online Server ● Hard to scale ● Implement in C++ ● Using some cheats to define user online ● Caching is hard ● Dev in 1 month
  • 22. Message Server ● Store the messages ● Implement in Java ● Problem with memory usage ● C++ version in progress ● Notify new message by queue ● Worker will deliver message to user by connection server
  • 26. Q&A Contact info: Chau Nguyen Nhat Thanh thanhcnn@vng.com.vn me.zing.vn/thanhcnn2000