SlideShare une entreprise Scribd logo
1  sur  10
Télécharger pour lire hors ligne
@agatestudio
Scalable Socket
Server
Aryo
Knight
Agate Studio
Scalable Socket Server by Aryo
 Built on Chrome’s javascript runtime
 Event driven (non blocking I/O model)
 Multiplatform (Mac OSX, Linux, Windows)
 Only single-threaded
// module required
var net = require('net');
// create server
var svr = net.createServer(function(sock) {
console.log('Connected: ' + sock.remoteAddress + ':' + sock.remotePort);
// error listener & handler
function sockOnError(err) {
console.log('Socket Error: ' + err.stack + 'n');
}
sock.on('error', sockOnError);
// server get data from client
function sockOnData(data) {
console.log('Data: ' + data.toString());
// simple echo back to client
sock.write(data, function() {
// called on write finished
}
}
sock.on('data', sockOnData);
// client disconnected
function sockOnEnd() {
console.log('Disconnected');
}
sock.on('end', sockOnEnd);
// function to disconnect player
function destroy() {
sock.removeListener('data', sockOnData);
sock.removeListener('end', sockOnEnd);
sock.removeListener('error', sockOnError);
sock.destroy();
sock = null;
console.log("Destroyed");
}
}
// listen on port and ip
svr.listen(SERVER_PORT, SERVER_ADDR);
 Only use single thread
› Not take advantages from multiple core CPU
› Slow response on busy server (lot of clients or
messages)
› Delay become unacceptable
 Using multiple server, even on one
computer to utilize other CPU cores
 Use message queue as a central
› We are using Redis in this slide
 Use load balancer to spreading request
from client to our servers
› Using HAProxy in this slide
 Message Queue
› Redirect message from all servers to one
database
 Advanced key-value store
› Pros, very fast to write and read
› Cons, data is not persistent
 Since we’re using to centralize data,
persistency in not important
› Use persistent database instead to store client
data
 Use publisher/subscriber to store and notify
to other server
 HTTP/TCP load balancer
› Use to distribute request from many clients
 Fast, efficient, and stable
› In terms of processor and memory usage
 Easy to implement
› Using file config
 Can be used to implement blocker
› Like DDOS protection
› Client can’t directly connect to actual server
global
log 127.0.0.1 local0 notice
maxconn 2000
user haproxy
group haproxy
defaults
log global
mode http
option httplog
option dontlognull
retries 3
option redispatch
timeout connect 5000
timeout client 10000
timeout server 10000
listen nodeserver :7070
mode tcp
option tcplog
balance roundrobin
server nodeserver1 127.0.0.1:7071
server nodeserver2 127.0.0.1:7072
timeout client 60s
timeout server 60s
timeout queue 10s
timeout connect 4s
 Single computer with 4 CPU cores
› Redis listen to 127.0.0.1:6379 (Multiple Core)
› Server 1 listen to 127.0.0.1:7071 (1 Core)
› Server 2 listen to 127.0.0.1:7072 (1 Core)
› HAProxy listen to 172.16.1.9:7070 (Multiple Core)
 HAProxy listen to IP public and distribute to
server 1 & 2
 Server 1 & 2 store & receive message data
to & from redis (publish&subscribe)
 Server 1 & 2 send back to client through
HAProxy

Contenu connexe

Tendances

Containers: What are they, Really?
Containers: What are they, Really?Containers: What are they, Really?
Containers: What are they, Really?Sneha Inguva
 
Object Storage with Gluster
Object Storage with GlusterObject Storage with Gluster
Object Storage with GlusterGluster.org
 
LMAX Disruptor as real-life example
LMAX Disruptor as real-life exampleLMAX Disruptor as real-life example
LMAX Disruptor as real-life exampleGuy Nir
 
Как понять, что происходит на сервере? / Александр Крижановский (NatSys Lab.,...
Как понять, что происходит на сервере? / Александр Крижановский (NatSys Lab.,...Как понять, что происходит на сервере? / Александр Крижановский (NatSys Lab.,...
Как понять, что происходит на сервере? / Александр Крижановский (NatSys Lab.,...Ontico
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.jsNodeXperts
 
nginx: writing your first module
nginx: writing your first modulenginx: writing your first module
nginx: writing your first moduleredivy
 
Nginx cheat sheet
Nginx cheat sheetNginx cheat sheet
Nginx cheat sheetLam Hoang
 
Azure ServiceBus Queues and Topics
Azure ServiceBus Queues and TopicsAzure ServiceBus Queues and Topics
Azure ServiceBus Queues and TopicsIgor Moochnick
 
Backing up thousands of containers
Backing up thousands of containersBacking up thousands of containers
Backing up thousands of containersMarian Marinov
 
Automation m ysql_and_customer_photo
Automation m ysql_and_customer_photoAutomation m ysql_and_customer_photo
Automation m ysql_and_customer_photoManju Kb
 
20140513_jeffyang_demo_openstack
20140513_jeffyang_demo_openstack20140513_jeffyang_demo_openstack
20140513_jeffyang_demo_openstackJeff Yang
 
An High Available Database for OpenStack Cloud Production by Pacemaker, Coros...
An High Available Database for OpenStack Cloud Production by Pacemaker, Coros...An High Available Database for OpenStack Cloud Production by Pacemaker, Coros...
An High Available Database for OpenStack Cloud Production by Pacemaker, Coros...Jeff Yang
 
Squid Proxy Server
Squid Proxy ServerSquid Proxy Server
Squid Proxy Server13bcs0012
 
Ethernet Shield
Ethernet ShieldEthernet Shield
Ethernet ShieldTinker
 
NginX - good practices, tips and advanced techniques
NginX - good practices, tips and advanced techniquesNginX - good practices, tips and advanced techniques
NginX - good practices, tips and advanced techniquesClaudio Borges
 
HTTP 완벽가이드- 13 다이제스트 인증
HTTP 완벽가이드- 13 다이제스트 인증HTTP 완벽가이드- 13 다이제스트 인증
HTTP 완벽가이드- 13 다이제스트 인증박 민규
 

Tendances (20)

Containers: What are they, Really?
Containers: What are they, Really?Containers: What are they, Really?
Containers: What are they, Really?
 
Object Storage with Gluster
Object Storage with GlusterObject Storage with Gluster
Object Storage with Gluster
 
Threads and Node.js
Threads and Node.jsThreads and Node.js
Threads and Node.js
 
LMAX Disruptor as real-life example
LMAX Disruptor as real-life exampleLMAX Disruptor as real-life example
LMAX Disruptor as real-life example
 
Как понять, что происходит на сервере? / Александр Крижановский (NatSys Lab.,...
Как понять, что происходит на сервере? / Александр Крижановский (NatSys Lab.,...Как понять, что происходит на сервере? / Александр Крижановский (NatSys Lab.,...
Как понять, что происходит на сервере? / Александр Крижановский (NatSys Lab.,...
 
Squid Server
Squid ServerSquid Server
Squid Server
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.js
 
Query logging with proxysql
Query logging with proxysqlQuery logging with proxysql
Query logging with proxysql
 
nginx: writing your first module
nginx: writing your first modulenginx: writing your first module
nginx: writing your first module
 
Nginx cheat sheet
Nginx cheat sheetNginx cheat sheet
Nginx cheat sheet
 
Azure ServiceBus Queues and Topics
Azure ServiceBus Queues and TopicsAzure ServiceBus Queues and Topics
Azure ServiceBus Queues and Topics
 
Backing up thousands of containers
Backing up thousands of containersBacking up thousands of containers
Backing up thousands of containers
 
Automation m ysql_and_customer_photo
Automation m ysql_and_customer_photoAutomation m ysql_and_customer_photo
Automation m ysql_and_customer_photo
 
20140513_jeffyang_demo_openstack
20140513_jeffyang_demo_openstack20140513_jeffyang_demo_openstack
20140513_jeffyang_demo_openstack
 
An High Available Database for OpenStack Cloud Production by Pacemaker, Coros...
An High Available Database for OpenStack Cloud Production by Pacemaker, Coros...An High Available Database for OpenStack Cloud Production by Pacemaker, Coros...
An High Available Database for OpenStack Cloud Production by Pacemaker, Coros...
 
Squid Proxy Server
Squid Proxy ServerSquid Proxy Server
Squid Proxy Server
 
CoreOS intro
CoreOS introCoreOS intro
CoreOS intro
 
Ethernet Shield
Ethernet ShieldEthernet Shield
Ethernet Shield
 
NginX - good practices, tips and advanced techniques
NginX - good practices, tips and advanced techniquesNginX - good practices, tips and advanced techniques
NginX - good practices, tips and advanced techniques
 
HTTP 완벽가이드- 13 다이제스트 인증
HTTP 완벽가이드- 13 다이제스트 인증HTTP 완벽가이드- 13 다이제스트 인증
HTTP 완벽가이드- 13 다이제스트 인증
 

En vedette

My Weekend Diary #3 by Bea
My Weekend Diary #3 by BeaMy Weekend Diary #3 by Bea
My Weekend Diary #3 by BeaAgate Studio
 
Hearth Stone - Game Review by Valen RK
Hearth Stone - Game Review by Valen RKHearth Stone - Game Review by Valen RK
Hearth Stone - Game Review by Valen RKAgate Studio
 
Postmortem Jokowi Go by Tama
Postmortem Jokowi Go by TamaPostmortem Jokowi Go by Tama
Postmortem Jokowi Go by TamaAgate Studio
 
Bandung Game Jam 2014: Tips & trik programming untuk membuat game dalam 48 jam
Bandung Game Jam 2014: Tips & trik programming untuk membuat game dalam 48 jamBandung Game Jam 2014: Tips & trik programming untuk membuat game dalam 48 jam
Bandung Game Jam 2014: Tips & trik programming untuk membuat game dalam 48 jamAgate Studio
 
Book Review David and Goliath by Andrew
Book Review David and Goliath by AndrewBook Review David and Goliath by Andrew
Book Review David and Goliath by AndrewAgate Studio
 
Basic Typography by Suryo
Basic Typography by SuryoBasic Typography by Suryo
Basic Typography by SuryoAgate Studio
 
Physically Based Rendering by Gege
Physically Based Rendering by GegePhysically Based Rendering by Gege
Physically Based Rendering by GegeAgate Studio
 
Final Fantasy XIV Review by Zaki Andiga
Final Fantasy XIV Review by Zaki AndigaFinal Fantasy XIV Review by Zaki Andiga
Final Fantasy XIV Review by Zaki AndigaAgate Studio
 
Interaction Fiction Gaming by yinan
Interaction Fiction Gaming by yinanInteraction Fiction Gaming by yinan
Interaction Fiction Gaming by yinanAgate Studio
 
Agate Academy Open course 02 - Peran dalam game developer
Agate Academy Open course 02 - Peran dalam game developerAgate Academy Open course 02 - Peran dalam game developer
Agate Academy Open course 02 - Peran dalam game developerAgate Studio
 
Unleashing the potential of Consultative Selling by Shieny Aprilia
Unleashing the potential of Consultative Selling by Shieny ApriliaUnleashing the potential of Consultative Selling by Shieny Aprilia
Unleashing the potential of Consultative Selling by Shieny ApriliaAgate Studio
 
Chibi Fanart by Luluz
Chibi Fanart by LuluzChibi Fanart by Luluz
Chibi Fanart by LuluzAgate Studio
 
Interpersonal Skill by Restya
Interpersonal Skill by RestyaInterpersonal Skill by Restya
Interpersonal Skill by RestyaAgate Studio
 

En vedette (13)

My Weekend Diary #3 by Bea
My Weekend Diary #3 by BeaMy Weekend Diary #3 by Bea
My Weekend Diary #3 by Bea
 
Hearth Stone - Game Review by Valen RK
Hearth Stone - Game Review by Valen RKHearth Stone - Game Review by Valen RK
Hearth Stone - Game Review by Valen RK
 
Postmortem Jokowi Go by Tama
Postmortem Jokowi Go by TamaPostmortem Jokowi Go by Tama
Postmortem Jokowi Go by Tama
 
Bandung Game Jam 2014: Tips & trik programming untuk membuat game dalam 48 jam
Bandung Game Jam 2014: Tips & trik programming untuk membuat game dalam 48 jamBandung Game Jam 2014: Tips & trik programming untuk membuat game dalam 48 jam
Bandung Game Jam 2014: Tips & trik programming untuk membuat game dalam 48 jam
 
Book Review David and Goliath by Andrew
Book Review David and Goliath by AndrewBook Review David and Goliath by Andrew
Book Review David and Goliath by Andrew
 
Basic Typography by Suryo
Basic Typography by SuryoBasic Typography by Suryo
Basic Typography by Suryo
 
Physically Based Rendering by Gege
Physically Based Rendering by GegePhysically Based Rendering by Gege
Physically Based Rendering by Gege
 
Final Fantasy XIV Review by Zaki Andiga
Final Fantasy XIV Review by Zaki AndigaFinal Fantasy XIV Review by Zaki Andiga
Final Fantasy XIV Review by Zaki Andiga
 
Interaction Fiction Gaming by yinan
Interaction Fiction Gaming by yinanInteraction Fiction Gaming by yinan
Interaction Fiction Gaming by yinan
 
Agate Academy Open course 02 - Peran dalam game developer
Agate Academy Open course 02 - Peran dalam game developerAgate Academy Open course 02 - Peran dalam game developer
Agate Academy Open course 02 - Peran dalam game developer
 
Unleashing the potential of Consultative Selling by Shieny Aprilia
Unleashing the potential of Consultative Selling by Shieny ApriliaUnleashing the potential of Consultative Selling by Shieny Aprilia
Unleashing the potential of Consultative Selling by Shieny Aprilia
 
Chibi Fanart by Luluz
Chibi Fanart by LuluzChibi Fanart by Luluz
Chibi Fanart by Luluz
 
Interpersonal Skill by Restya
Interpersonal Skill by RestyaInterpersonal Skill by Restya
Interpersonal Skill by Restya
 

Similaire à Scalable Socket Server by Aryo

Building and Scaling Node.js Applications
Building and Scaling Node.js ApplicationsBuilding and Scaling Node.js Applications
Building and Scaling Node.js ApplicationsOhad Kravchick
 
Writing robust Node.js applications
Writing robust Node.js applicationsWriting robust Node.js applications
Writing robust Node.js applicationsTom Croucher
 
Original slides from Ryan Dahl's NodeJs intro talk
Original slides from Ryan Dahl's NodeJs intro talkOriginal slides from Ryan Dahl's NodeJs intro talk
Original slides from Ryan Dahl's NodeJs intro talkAarti Parikh
 
Monitoring with Syslog and EventMachine
Monitoring with Syslog and EventMachineMonitoring with Syslog and EventMachine
Monitoring with Syslog and EventMachineWooga
 
"Swoole: double troubles in c", Alexandr Vronskiy
"Swoole: double troubles in c", Alexandr Vronskiy"Swoole: double troubles in c", Alexandr Vronskiy
"Swoole: double troubles in c", Alexandr VronskiyFwdays
 
Nodejs 프로그래밍 ch.3
Nodejs 프로그래밍 ch.3Nodejs 프로그래밍 ch.3
Nodejs 프로그래밍 ch.3HyeonSeok Choi
 
A language for the Internet: Why JavaScript and Node.js is right for Internet...
A language for the Internet: Why JavaScript and Node.js is right for Internet...A language for the Internet: Why JavaScript and Node.js is right for Internet...
A language for the Internet: Why JavaScript and Node.js is right for Internet...Tom Croucher
 
A language for the Internet: Why JavaScript and Node.js is right for Internet...
A language for the Internet: Why JavaScript and Node.js is right for Internet...A language for the Internet: Why JavaScript and Node.js is right for Internet...
A language for the Internet: Why JavaScript and Node.js is right for Internet...Tom Croucher
 
Real World Lessons on the Pain Points of Node.JS Application
Real World Lessons on the Pain Points of Node.JS ApplicationReal World Lessons on the Pain Points of Node.JS Application
Real World Lessons on the Pain Points of Node.JS ApplicationBen Hall
 
WebSockets Everywhere: the Future Transport Protocol for Everything (Almost)
WebSockets Everywhere: the Future Transport Protocol for Everything (Almost)WebSockets Everywhere: the Future Transport Protocol for Everything (Almost)
WebSockets Everywhere: the Future Transport Protocol for Everything (Almost)Ericom Software
 
Nodejs and WebSockets
Nodejs and WebSocketsNodejs and WebSockets
Nodejs and WebSocketsGonzalo Ayuso
 
Introduce about Nodejs - duyetdev.com
Introduce about Nodejs - duyetdev.comIntroduce about Nodejs - duyetdev.com
Introduce about Nodejs - duyetdev.comVan-Duyet Le
 
Building an ActionScript Game Server with over 15,000 Concurrent Connections
Building an ActionScript Game Server with over 15,000 Concurrent ConnectionsBuilding an ActionScript Game Server with over 15,000 Concurrent Connections
Building an ActionScript Game Server with over 15,000 Concurrent Connections Renaun Erickson
 
Scaling asp.net websites to millions of users
Scaling asp.net websites to millions of usersScaling asp.net websites to millions of users
Scaling asp.net websites to millions of usersoazabir
 
Socket programming, and openresty
Socket programming, and openrestySocket programming, and openresty
Socket programming, and openrestyTavish Naruka
 
ClickHouse Defense Against the Dark Arts - Intro to Security and Privacy
ClickHouse Defense Against the Dark Arts - Intro to Security and PrivacyClickHouse Defense Against the Dark Arts - Intro to Security and Privacy
ClickHouse Defense Against the Dark Arts - Intro to Security and PrivacyAltinity Ltd
 
17937858 squid-server - [the-xp.blogspot.com]
17937858 squid-server - [the-xp.blogspot.com]17937858 squid-server - [the-xp.blogspot.com]
17937858 squid-server - [the-xp.blogspot.com]Krisman Tarigan
 

Similaire à Scalable Socket Server by Aryo (20)

Building and Scaling Node.js Applications
Building and Scaling Node.js ApplicationsBuilding and Scaling Node.js Applications
Building and Scaling Node.js Applications
 
Writing robust Node.js applications
Writing robust Node.js applicationsWriting robust Node.js applications
Writing robust Node.js applications
 
Original slides from Ryan Dahl's NodeJs intro talk
Original slides from Ryan Dahl's NodeJs intro talkOriginal slides from Ryan Dahl's NodeJs intro talk
Original slides from Ryan Dahl's NodeJs intro talk
 
Monitoring with Syslog and EventMachine
Monitoring with Syslog and EventMachineMonitoring with Syslog and EventMachine
Monitoring with Syslog and EventMachine
 
"Swoole: double troubles in c", Alexandr Vronskiy
"Swoole: double troubles in c", Alexandr Vronskiy"Swoole: double troubles in c", Alexandr Vronskiy
"Swoole: double troubles in c", Alexandr Vronskiy
 
Nodejs 프로그래밍 ch.3
Nodejs 프로그래밍 ch.3Nodejs 프로그래밍 ch.3
Nodejs 프로그래밍 ch.3
 
A language for the Internet: Why JavaScript and Node.js is right for Internet...
A language for the Internet: Why JavaScript and Node.js is right for Internet...A language for the Internet: Why JavaScript and Node.js is right for Internet...
A language for the Internet: Why JavaScript and Node.js is right for Internet...
 
A language for the Internet: Why JavaScript and Node.js is right for Internet...
A language for the Internet: Why JavaScript and Node.js is right for Internet...A language for the Internet: Why JavaScript and Node.js is right for Internet...
A language for the Internet: Why JavaScript and Node.js is right for Internet...
 
Real World Lessons on the Pain Points of Node.JS Application
Real World Lessons on the Pain Points of Node.JS ApplicationReal World Lessons on the Pain Points of Node.JS Application
Real World Lessons on the Pain Points of Node.JS Application
 
Node js lecture
Node js lectureNode js lecture
Node js lecture
 
WebSockets Everywhere: the Future Transport Protocol for Everything (Almost)
WebSockets Everywhere: the Future Transport Protocol for Everything (Almost)WebSockets Everywhere: the Future Transport Protocol for Everything (Almost)
WebSockets Everywhere: the Future Transport Protocol for Everything (Almost)
 
Nodejs and WebSockets
Nodejs and WebSocketsNodejs and WebSockets
Nodejs and WebSockets
 
Introduce about Nodejs - duyetdev.com
Introduce about Nodejs - duyetdev.comIntroduce about Nodejs - duyetdev.com
Introduce about Nodejs - duyetdev.com
 
Building an ActionScript Game Server with over 15,000 Concurrent Connections
Building an ActionScript Game Server with over 15,000 Concurrent ConnectionsBuilding an ActionScript Game Server with over 15,000 Concurrent Connections
Building an ActionScript Game Server with over 15,000 Concurrent Connections
 
Scaling asp.net websites to millions of users
Scaling asp.net websites to millions of usersScaling asp.net websites to millions of users
Scaling asp.net websites to millions of users
 
FreeBSD and Hardening Web Server
FreeBSD and Hardening Web ServerFreeBSD and Hardening Web Server
FreeBSD and Hardening Web Server
 
Socket programming, and openresty
Socket programming, and openrestySocket programming, and openresty
Socket programming, and openresty
 
ClickHouse Defense Against the Dark Arts - Intro to Security and Privacy
ClickHouse Defense Against the Dark Arts - Intro to Security and PrivacyClickHouse Defense Against the Dark Arts - Intro to Security and Privacy
ClickHouse Defense Against the Dark Arts - Intro to Security and Privacy
 
17937858 squid-server - [the-xp.blogspot.com]
17937858 squid-server - [the-xp.blogspot.com]17937858 squid-server - [the-xp.blogspot.com]
17937858 squid-server - [the-xp.blogspot.com]
 
A java servers
A java serversA java servers
A java servers
 

Plus de Agate Studio

Digital Coloring by Raksa
Digital Coloring by RaksaDigital Coloring by Raksa
Digital Coloring by RaksaAgate Studio
 
Computational Advertising by Icha
Computational Advertising by IchaComputational Advertising by Icha
Computational Advertising by IchaAgate Studio
 
Freemium conceptanalytics leemarvin
Freemium conceptanalytics leemarvinFreemium conceptanalytics leemarvin
Freemium conceptanalytics leemarvinAgate Studio
 
Game Programming Pattern by Restya
Game Programming Pattern by RestyaGame Programming Pattern by Restya
Game Programming Pattern by RestyaAgate Studio
 
Community Management by Yudhit
Community Management by YudhitCommunity Management by Yudhit
Community Management by YudhitAgate Studio
 
[Habli] tds agustus
[Habli] tds agustus[Habli] tds agustus
[Habli] tds agustusAgate Studio
 
Wp quality bar tedy
Wp quality bar   tedyWp quality bar   tedy
Wp quality bar tedyAgate Studio
 
Lee marvin pitching-hacks
Lee marvin pitching-hacksLee marvin pitching-hacks
Lee marvin pitching-hacksAgate Studio
 
Emotiv EPOC by Neneng
Emotiv EPOC by NenengEmotiv EPOC by Neneng
Emotiv EPOC by NenengAgate Studio
 
Aksi – Koneksi – Deviasi by Valent
Aksi – Koneksi – Deviasi by ValentAksi – Koneksi – Deviasi by Valent
Aksi – Koneksi – Deviasi by ValentAgate Studio
 
MMO Design Architecture by Andrew
MMO Design Architecture by AndrewMMO Design Architecture by Andrew
MMO Design Architecture by AndrewAgate Studio
 
How to Persuade People by Dave
How to Persuade People by DaveHow to Persuade People by Dave
How to Persuade People by DaveAgate Studio
 
Eddie supersmash goodminton
Eddie   supersmash goodmintonEddie   supersmash goodminton
Eddie supersmash goodmintonAgate Studio
 
Satriyo digital audio gears
Satriyo   digital audio gearsSatriyo   digital audio gears
Satriyo digital audio gearsAgate Studio
 
Yinan heroes of-the_strom
Yinan   heroes of-the_stromYinan   heroes of-the_strom
Yinan heroes of-the_stromAgate Studio
 
Advanced encryption standard (aes) epul
Advanced encryption standard (aes)   epulAdvanced encryption standard (aes)   epul
Advanced encryption standard (aes) epulAgate Studio
 
Real Time Framework by Tonny
Real Time Framework by TonnyReal Time Framework by Tonny
Real Time Framework by TonnyAgate Studio
 
Unity Camera & Simple Image Editing by Puthut
Unity Camera & Simple Image Editing by PuthutUnity Camera & Simple Image Editing by Puthut
Unity Camera & Simple Image Editing by PuthutAgate Studio
 
Hibernate by Jason
Hibernate by JasonHibernate by Jason
Hibernate by JasonAgate Studio
 

Plus de Agate Studio (20)

Digital Coloring by Raksa
Digital Coloring by RaksaDigital Coloring by Raksa
Digital Coloring by Raksa
 
Computational Advertising by Icha
Computational Advertising by IchaComputational Advertising by Icha
Computational Advertising by Icha
 
Freemium conceptanalytics leemarvin
Freemium conceptanalytics leemarvinFreemium conceptanalytics leemarvin
Freemium conceptanalytics leemarvin
 
Game Programming Pattern by Restya
Game Programming Pattern by RestyaGame Programming Pattern by Restya
Game Programming Pattern by Restya
 
Community Management by Yudhit
Community Management by YudhitCommunity Management by Yudhit
Community Management by Yudhit
 
[Habli] tds agustus
[Habli] tds agustus[Habli] tds agustus
[Habli] tds agustus
 
Wp quality bar tedy
Wp quality bar   tedyWp quality bar   tedy
Wp quality bar tedy
 
Toku DB by Aswin
Toku DB by AswinToku DB by Aswin
Toku DB by Aswin
 
Lee marvin pitching-hacks
Lee marvin pitching-hacksLee marvin pitching-hacks
Lee marvin pitching-hacks
 
Emotiv EPOC by Neneng
Emotiv EPOC by NenengEmotiv EPOC by Neneng
Emotiv EPOC by Neneng
 
Aksi – Koneksi – Deviasi by Valent
Aksi – Koneksi – Deviasi by ValentAksi – Koneksi – Deviasi by Valent
Aksi – Koneksi – Deviasi by Valent
 
MMO Design Architecture by Andrew
MMO Design Architecture by AndrewMMO Design Architecture by Andrew
MMO Design Architecture by Andrew
 
How to Persuade People by Dave
How to Persuade People by DaveHow to Persuade People by Dave
How to Persuade People by Dave
 
Eddie supersmash goodminton
Eddie   supersmash goodmintonEddie   supersmash goodminton
Eddie supersmash goodminton
 
Satriyo digital audio gears
Satriyo   digital audio gearsSatriyo   digital audio gears
Satriyo digital audio gears
 
Yinan heroes of-the_strom
Yinan   heroes of-the_stromYinan   heroes of-the_strom
Yinan heroes of-the_strom
 
Advanced encryption standard (aes) epul
Advanced encryption standard (aes)   epulAdvanced encryption standard (aes)   epul
Advanced encryption standard (aes) epul
 
Real Time Framework by Tonny
Real Time Framework by TonnyReal Time Framework by Tonny
Real Time Framework by Tonny
 
Unity Camera & Simple Image Editing by Puthut
Unity Camera & Simple Image Editing by PuthutUnity Camera & Simple Image Editing by Puthut
Unity Camera & Simple Image Editing by Puthut
 
Hibernate by Jason
Hibernate by JasonHibernate by Jason
Hibernate by Jason
 

Dernier

How to Make a Field read-only in Odoo 17
How to Make a Field read-only in Odoo 17How to Make a Field read-only in Odoo 17
How to Make a Field read-only in Odoo 17Celine George
 
Benefits & Challenges of Inclusive Education
Benefits & Challenges of Inclusive EducationBenefits & Challenges of Inclusive Education
Benefits & Challenges of Inclusive EducationMJDuyan
 
Quality Assurance_GOOD LABORATORY PRACTICE
Quality Assurance_GOOD LABORATORY PRACTICEQuality Assurance_GOOD LABORATORY PRACTICE
Quality Assurance_GOOD LABORATORY PRACTICESayali Powar
 
General views of Histopathology and step
General views of Histopathology and stepGeneral views of Histopathology and step
General views of Histopathology and stepobaje godwin sunday
 
Patterns of Written Texts Across Disciplines.pptx
Patterns of Written Texts Across Disciplines.pptxPatterns of Written Texts Across Disciplines.pptx
Patterns of Written Texts Across Disciplines.pptxMYDA ANGELICA SUAN
 
The Singapore Teaching Practice document
The Singapore Teaching Practice documentThe Singapore Teaching Practice document
The Singapore Teaching Practice documentXsasf Sfdfasd
 
AUDIENCE THEORY -- FANDOM -- JENKINS.pptx
AUDIENCE THEORY -- FANDOM -- JENKINS.pptxAUDIENCE THEORY -- FANDOM -- JENKINS.pptx
AUDIENCE THEORY -- FANDOM -- JENKINS.pptxiammrhaywood
 
HED Office Sohayok Exam Question Solution 2023.pdf
HED Office Sohayok Exam Question Solution 2023.pdfHED Office Sohayok Exam Question Solution 2023.pdf
HED Office Sohayok Exam Question Solution 2023.pdfMohonDas
 
Presentation on the Basics of Writing. Writing a Paragraph
Presentation on the Basics of Writing. Writing a ParagraphPresentation on the Basics of Writing. Writing a Paragraph
Presentation on the Basics of Writing. Writing a ParagraphNetziValdelomar1
 
Education and training program in the hospital APR.pptx
Education and training program in the hospital APR.pptxEducation and training program in the hospital APR.pptx
Education and training program in the hospital APR.pptxraviapr7
 
CHUYÊN ĐỀ DẠY THÊM TIẾNG ANH LỚP 11 - GLOBAL SUCCESS - NĂM HỌC 2023-2024 - HK...
CHUYÊN ĐỀ DẠY THÊM TIẾNG ANH LỚP 11 - GLOBAL SUCCESS - NĂM HỌC 2023-2024 - HK...CHUYÊN ĐỀ DẠY THÊM TIẾNG ANH LỚP 11 - GLOBAL SUCCESS - NĂM HỌC 2023-2024 - HK...
CHUYÊN ĐỀ DẠY THÊM TIẾNG ANH LỚP 11 - GLOBAL SUCCESS - NĂM HỌC 2023-2024 - HK...Nguyen Thanh Tu Collection
 
Easter in the USA presentation by Chloe.
Easter in the USA presentation by Chloe.Easter in the USA presentation by Chloe.
Easter in the USA presentation by Chloe.EnglishCEIPdeSigeiro
 
How to Add Existing Field in One2Many Tree View in Odoo 17
How to Add Existing Field in One2Many Tree View in Odoo 17How to Add Existing Field in One2Many Tree View in Odoo 17
How to Add Existing Field in One2Many Tree View in Odoo 17Celine George
 
M-2- General Reactions of amino acids.pptx
M-2- General Reactions of amino acids.pptxM-2- General Reactions of amino acids.pptx
M-2- General Reactions of amino acids.pptxDr. Santhosh Kumar. N
 
2024.03.23 What do successful readers do - Sandy Millin for PARK.pptx
2024.03.23 What do successful readers do - Sandy Millin for PARK.pptx2024.03.23 What do successful readers do - Sandy Millin for PARK.pptx
2024.03.23 What do successful readers do - Sandy Millin for PARK.pptxSandy Millin
 
UKCGE Parental Leave Discussion March 2024
UKCGE Parental Leave Discussion March 2024UKCGE Parental Leave Discussion March 2024
UKCGE Parental Leave Discussion March 2024UKCGE
 
PISA-VET launch_El Iza Mohamedou_19 March 2024.pptx
PISA-VET launch_El Iza Mohamedou_19 March 2024.pptxPISA-VET launch_El Iza Mohamedou_19 March 2024.pptx
PISA-VET launch_El Iza Mohamedou_19 March 2024.pptxEduSkills OECD
 
Drug Information Services- DIC and Sources.
Drug Information Services- DIC and Sources.Drug Information Services- DIC and Sources.
Drug Information Services- DIC and Sources.raviapr7
 
In - Vivo and In - Vitro Correlation.pptx
In - Vivo and In - Vitro Correlation.pptxIn - Vivo and In - Vitro Correlation.pptx
In - Vivo and In - Vitro Correlation.pptxAditiChauhan701637
 

Dernier (20)

How to Make a Field read-only in Odoo 17
How to Make a Field read-only in Odoo 17How to Make a Field read-only in Odoo 17
How to Make a Field read-only in Odoo 17
 
Benefits & Challenges of Inclusive Education
Benefits & Challenges of Inclusive EducationBenefits & Challenges of Inclusive Education
Benefits & Challenges of Inclusive Education
 
Quality Assurance_GOOD LABORATORY PRACTICE
Quality Assurance_GOOD LABORATORY PRACTICEQuality Assurance_GOOD LABORATORY PRACTICE
Quality Assurance_GOOD LABORATORY PRACTICE
 
General views of Histopathology and step
General views of Histopathology and stepGeneral views of Histopathology and step
General views of Histopathology and step
 
Patterns of Written Texts Across Disciplines.pptx
Patterns of Written Texts Across Disciplines.pptxPatterns of Written Texts Across Disciplines.pptx
Patterns of Written Texts Across Disciplines.pptx
 
The Singapore Teaching Practice document
The Singapore Teaching Practice documentThe Singapore Teaching Practice document
The Singapore Teaching Practice document
 
AUDIENCE THEORY -- FANDOM -- JENKINS.pptx
AUDIENCE THEORY -- FANDOM -- JENKINS.pptxAUDIENCE THEORY -- FANDOM -- JENKINS.pptx
AUDIENCE THEORY -- FANDOM -- JENKINS.pptx
 
HED Office Sohayok Exam Question Solution 2023.pdf
HED Office Sohayok Exam Question Solution 2023.pdfHED Office Sohayok Exam Question Solution 2023.pdf
HED Office Sohayok Exam Question Solution 2023.pdf
 
Presentation on the Basics of Writing. Writing a Paragraph
Presentation on the Basics of Writing. Writing a ParagraphPresentation on the Basics of Writing. Writing a Paragraph
Presentation on the Basics of Writing. Writing a Paragraph
 
Education and training program in the hospital APR.pptx
Education and training program in the hospital APR.pptxEducation and training program in the hospital APR.pptx
Education and training program in the hospital APR.pptx
 
CHUYÊN ĐỀ DẠY THÊM TIẾNG ANH LỚP 11 - GLOBAL SUCCESS - NĂM HỌC 2023-2024 - HK...
CHUYÊN ĐỀ DẠY THÊM TIẾNG ANH LỚP 11 - GLOBAL SUCCESS - NĂM HỌC 2023-2024 - HK...CHUYÊN ĐỀ DẠY THÊM TIẾNG ANH LỚP 11 - GLOBAL SUCCESS - NĂM HỌC 2023-2024 - HK...
CHUYÊN ĐỀ DẠY THÊM TIẾNG ANH LỚP 11 - GLOBAL SUCCESS - NĂM HỌC 2023-2024 - HK...
 
Easter in the USA presentation by Chloe.
Easter in the USA presentation by Chloe.Easter in the USA presentation by Chloe.
Easter in the USA presentation by Chloe.
 
Finals of Kant get Marx 2.0 : a general politics quiz
Finals of Kant get Marx 2.0 : a general politics quizFinals of Kant get Marx 2.0 : a general politics quiz
Finals of Kant get Marx 2.0 : a general politics quiz
 
How to Add Existing Field in One2Many Tree View in Odoo 17
How to Add Existing Field in One2Many Tree View in Odoo 17How to Add Existing Field in One2Many Tree View in Odoo 17
How to Add Existing Field in One2Many Tree View in Odoo 17
 
M-2- General Reactions of amino acids.pptx
M-2- General Reactions of amino acids.pptxM-2- General Reactions of amino acids.pptx
M-2- General Reactions of amino acids.pptx
 
2024.03.23 What do successful readers do - Sandy Millin for PARK.pptx
2024.03.23 What do successful readers do - Sandy Millin for PARK.pptx2024.03.23 What do successful readers do - Sandy Millin for PARK.pptx
2024.03.23 What do successful readers do - Sandy Millin for PARK.pptx
 
UKCGE Parental Leave Discussion March 2024
UKCGE Parental Leave Discussion March 2024UKCGE Parental Leave Discussion March 2024
UKCGE Parental Leave Discussion March 2024
 
PISA-VET launch_El Iza Mohamedou_19 March 2024.pptx
PISA-VET launch_El Iza Mohamedou_19 March 2024.pptxPISA-VET launch_El Iza Mohamedou_19 March 2024.pptx
PISA-VET launch_El Iza Mohamedou_19 March 2024.pptx
 
Drug Information Services- DIC and Sources.
Drug Information Services- DIC and Sources.Drug Information Services- DIC and Sources.
Drug Information Services- DIC and Sources.
 
In - Vivo and In - Vitro Correlation.pptx
In - Vivo and In - Vitro Correlation.pptxIn - Vivo and In - Vitro Correlation.pptx
In - Vivo and In - Vitro Correlation.pptx
 

Scalable Socket Server by Aryo

  • 3.  Built on Chrome’s javascript runtime  Event driven (non blocking I/O model)  Multiplatform (Mac OSX, Linux, Windows)  Only single-threaded
  • 4. // module required var net = require('net'); // create server var svr = net.createServer(function(sock) { console.log('Connected: ' + sock.remoteAddress + ':' + sock.remotePort); // error listener & handler function sockOnError(err) { console.log('Socket Error: ' + err.stack + 'n'); } sock.on('error', sockOnError); // server get data from client function sockOnData(data) { console.log('Data: ' + data.toString()); // simple echo back to client sock.write(data, function() { // called on write finished } } sock.on('data', sockOnData); // client disconnected function sockOnEnd() { console.log('Disconnected'); } sock.on('end', sockOnEnd); // function to disconnect player function destroy() { sock.removeListener('data', sockOnData); sock.removeListener('end', sockOnEnd); sock.removeListener('error', sockOnError); sock.destroy(); sock = null; console.log("Destroyed"); } } // listen on port and ip svr.listen(SERVER_PORT, SERVER_ADDR);
  • 5.  Only use single thread › Not take advantages from multiple core CPU › Slow response on busy server (lot of clients or messages) › Delay become unacceptable
  • 6.  Using multiple server, even on one computer to utilize other CPU cores  Use message queue as a central › We are using Redis in this slide  Use load balancer to spreading request from client to our servers › Using HAProxy in this slide
  • 7.  Message Queue › Redirect message from all servers to one database  Advanced key-value store › Pros, very fast to write and read › Cons, data is not persistent  Since we’re using to centralize data, persistency in not important › Use persistent database instead to store client data  Use publisher/subscriber to store and notify to other server
  • 8.  HTTP/TCP load balancer › Use to distribute request from many clients  Fast, efficient, and stable › In terms of processor and memory usage  Easy to implement › Using file config  Can be used to implement blocker › Like DDOS protection › Client can’t directly connect to actual server
  • 9. global log 127.0.0.1 local0 notice maxconn 2000 user haproxy group haproxy defaults log global mode http option httplog option dontlognull retries 3 option redispatch timeout connect 5000 timeout client 10000 timeout server 10000 listen nodeserver :7070 mode tcp option tcplog balance roundrobin server nodeserver1 127.0.0.1:7071 server nodeserver2 127.0.0.1:7072 timeout client 60s timeout server 60s timeout queue 10s timeout connect 4s
  • 10.  Single computer with 4 CPU cores › Redis listen to 127.0.0.1:6379 (Multiple Core) › Server 1 listen to 127.0.0.1:7071 (1 Core) › Server 2 listen to 127.0.0.1:7072 (1 Core) › HAProxy listen to 172.16.1.9:7070 (Multiple Core)  HAProxy listen to IP public and distribute to server 1 & 2  Server 1 & 2 store & receive message data to & from redis (publish&subscribe)  Server 1 & 2 send back to client through HAProxy