SlideShare a Scribd company logo
1 of 36
Download to read offline
ServerEngine 
Server programming framework for Ruby 
Masahiro Nakagawa 
Sep 19, 2014 
RubyKaigi 2014
Who are you? 
> Masahiro Nakagawa 
> github/twitter: @repeatedly 
> Treasure Data, Inc. 
> Senior Software Engineer 
> Fluentd / td-agent developer 
> I love OSS :) 
> D language - Phobos committer 
> Fluentd - Main maintainer 
> MessagePack / RPC- D and Python (only RPC) 
> The organizer of Presto Source Code Reading 
> etc…
0. Background + Intro
Ruby is not only for web apps! 
> System programs 
• Chef - server configuration management tool 
• Serverspec - spec framework for servers 
•Apache Deltacloud - IaaS API abstraction library 
> Network servers 
• Starling - distributed message queue server 
•Unicorn - multiprocess HTTP server 
> Log servers 
• Fluentd - extensible data collection tool
Problem: server programming is hard 
Server programs should support: 
> multi-process or multi-thread 
> robust error handling 
> log rotation 
> signal handling 
> dynamic reconfiguration 
> metrics collection 
> etc...
Solution: Use a framework 
ServerEngine A framework for server programming in Ruby 
github.com/fluent/serverengine
What’s ServerEngine? 
With ServerEngine, we can write multi-process 
server programs, like Unicorn, easily. 
What we need to write is a 2 modules: 
Worker module and Server module. 
Everything else, including daemonize, logging, 
dynamic reconfiguration, multi-processing 
is done by ServerEngine.
Hello world in ServerEngine 
require 
'serverengine' 
! 
module 
MyWorker 
def 
run 
until 
@stop 
logger.info 
"Hello 
world!" 
sleep 
1 
end 
end 
! 
def 
stop 
@stop 
= 
true 
end 
end 
! 
se 
Worker 
Server 
= 
ServerEngine.create(nil, 
MyWorker, 
{ 
log: 
'myserver.log', 
pid_path: 
'myserver.pid', 
}) 
se.run 
Config
How ServerEngine works? 
1. Robust process management (supervisor) 
2. Multi-process and multi-threading 
3. Dynamic configuration reloading 
4. Log rotation 
5. Signal handling 
6. Live restart 
7. “sigdump”
1. Robust process management 
Heartbeat via pipe 
& auto-restart 
Supervisor Server 
Dynamic reconfiguration 
& live restart support 
Multi-process 
Worker 
Worker or Multi-thread 
Worker
Each role overview 
Supervisor Server Worker 
• Manage Server 
• heartbeat 
• attach / detach 
• restart 
! 
• Disable by default 
! 
• No extension point 
• Manage Worker 
• monitor 
• restart 
! 
• Some execution types 
• Embedded 
• Thread 
• Process 
! 
• Extension point 
• before_run 
• after_run 
• after_restart 
• Execution unit 
• implement run 
method 
! 
• Extension point 
• stop 
• reload 
• before_fork 
• after_start
2. Multi-process & multi-threading 
require 
'serverengine' 
! 
module 
MyWorker 
def 
run 
until 
@stop 
logger.info 
"Awesome 
work!" 
sleep 
1 
end 
end 
! 
def 
stop 
@stop 
= 
true 
end 
end 
! 
se 
= 
ServerEngine.create(nil, 
MyWorker, 
{ 
daemonize: 
true, 
log: 
'myserver.log', 
pid_path: 
'myserver.pid', 
worker_type: 
'process', 
workers: 
4, 
}) 
se.run 
> 3 server types 
> embedded 
> process 
> thread 
- thread example 
se 
= 
ServerEngine.create(nil, 
MyWorker,{ 
daemonize: 
true, 
log: 
'myserver.log', 
pid_path: 
'myserver.pid', 
worker_type: 
'thread', 
workers: 
8, 
}) 
se.run
2. Multi-process & multi-threading 
embedded process thread 
fork 
Worker 
• default mode 
• use main thread 
Server 
Worker 
• use fork for parallel 
execution 
• not work on Windows 
• use thread for parallel 
execution 
• for JRuby and Rubinius 
Server 
WWorokrekrer 
Server 
Thread.new 
WWorokrekrer 
Worker
3. Dynamic reconfiguration 
module 
MyWorker 
def 
initialize 
reload 
end 
! 
def 
run 
# 
… 
end 
! 
def 
reload 
@message 
= 
config["message"] 
|| 
"default" 
@sleep 
= 
config["sleep"] 
|| 
1 
end 
end 
! 
se 
= 
ServerEngine.create(nil, 
MyWorker) 
do 
YAML.load_file("config.yml").merge({ 
:daemonize 
=> 
true, 
:worker_type 
=> 
'process', 
}) 
end 
se.run 
> Overwrite method 
> reload 
in worker 
> reload_config 
in server 
> Send USR2 signal
4. Log rotation 
> Support useful features 
> multi-process aware log rotation 
> support “trace” level 
> Port to Ruby core 
> https://github.com/ruby/ruby/pull/428 
se 
= 
ServerEngine.create(MyServer, 
MyWorker, 
{ 
log: 
'myserver.log', 
log_level: 
'debug', 
log_rotate_age: 
5, 
log_rotate_size: 
1 
* 
1024 
* 
1024, 
}) 
se.run
5. Signal handling 
> Queue based signal handling 
> serialize signal processing 
> signal handling is separated from 
signal handler to avoid lock issues 
SignalThread.new 
do 
|st| 
st.trap(:TERM) 
{ 
server.stop(true) 
} 
st.trap(:QUIT) 
{ 
server.stop(false) 
} 
st.trap(:USR1) 
{ 
server.restart(true) 
} 
st.trap(:HUP) 
{ 
server.restart(false) 
} 
st.trap(:USR2) 
{ 
server.reload 
} 
# 
... 
end
5. Signal handling - register 1 
SignalThread 
INT { process_int } 
Register Signal 
INT
5. Signal handling - register 2 
SignalThread 
USR1 { process_usr1 } 
INT { process_int } 
Register Signal 
USR1
5. Signal handling - register 3 
SignalThread 
QUIT { process_quit } 
TERM { process_term } 
USR1 { process_usr1 } 
INT { process_int } 
Register Signal 
XXX
5. Signal handling - process 1 
SignalThread 
QUIT { process_quit } 
TERM { process_term } 
USR1 { process_usr1 } 
{ process_int } 
USR1 
Send Signal 
USR1 
INT 
Monitor queue
5. Signal handling - process 2 
SignalThread 
QUIT { process_quit } 
TERM { process_term } 
USR1 { process_usr1 } 
INT { process_int } 
QUIT 
USR1 
Send Signal 
QUIT
5. Signal handling - process 3 
SignalThread 
QUIT { process_quit } 
TERM { process_term } 
USR1 { process_usr1 } 
INT { process_int } 
QUIT 
Send Signal 
XXX
6. Live Restart 
> Minimize server restart downtime 
> via INT signal 
> enable_detach and 
supervisor parameters must be true 
> Network server can’t use live restart 
> “Address already in use” occurred 
> use “process” worker and USR1 instead 
• restart workers, not server
6. Live Restart - flow 1 
1. start a server 
Supervisor Server WWWooorrkrkkeeerrr
6. Live Restart - flow 2 
2. receive SIGINT and 
wait for shutdown of the server 
Supervisor Server WWWooorrkrkkeeerrr
6. Live Restart - flow 3 
3. start new server if 
the server doesn’t exit in server_detach_wait 
Supervisor Server 
Worker 
Server WWWooorrkrkkeeerrr
7. “sigdump” 
> SIGQUIT of JavaVM for Ruby 
> https://github.com/frsyuki/sigdump 
> dump backtrace of running threads 
and allocated object list 
> for debugging, slow code, dead-lock, … 
> ServerEngine traps SIGCONT for sigdump 
> Trapping signal is configurable using 
“SIGDUMP_SIGNAL” environment variable
7. sigdump example 
% kill -CONT pid 
% cat /tmp/sigdump-66276.log 
Sigdump at 2014-09-18 18:44:43 +0900 process 66276 (se.rb) 
Thread #<Thread:0x007fdc130cb7e0> status=sleep priority=0 
se.rb:7:in `sleep' 
se.rb:7:in `run' 
/Users/repeatedly/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/serverengine-1.5.9/ 
lib/serverengine/worker.rb:67:in `main' 
/Users/repeatedly/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/serverengine-1.5.9/ 
lib/serverengine/embedded_server.rb:24:in `run' 
/Users/repeatedly/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/serverengine-1.5.9/ 
lib/serverengine/server.rb:85:in `main' 
/Users/repeatedly/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/serverengine-1.5.9/ 
lib/serverengine/daemon.rb:101:in `main' 
… 
Thread #<ServerEngine::SignalThread:0x007fdc13314038> status=run priority=0 
… 
Built-in objects: 
33,017: TOTAL 
16,845: T_STRING 
… 
All objects: 
8,939: String 
1,459: Array 
… 
String 210,569 bytes 
Array 4 elements 
Hash 14 pairs
Use-case1: Sneakers 
> A fast background processing 
framework for Ruby 
> use ServerEngine and RabbitMQ 
> jondot.github.io/sneakers/ 
Server WWWooorrkrkkeeerrr 
Task 
Sneakers RabbitMQ
Use-case2: Fluentd v1 
> Data collector for unified logging layer 
> http://www.fluentd.org/ 
> Improve core features 
> Logging 
> Signal handling 
> New features based on ServerEngine 
> Multi-process support 
> Zero downtime restart 
> etc…
Fluentd v1 - Multi-process 
Worker 
Supervisor 
Worker Worker 
<Worker> 
input tail 
output forward 
</worker> 
<Worker> 
input forward 
output webhdfs 
</worker> 
<Worker> 
input foo 
output bar 
</worker> 
Separate stream pipelines in one instance!
Fluentd v1 - Zero downtime restart 
> SocketManager shares the resource 
32 
Supervisor 
TCP 
1. Listen TCP socket
Fluentd v1 - Zero downtime restart 
> SocketManager shares the resource 
33 
Worker 
Supervisor 
heartbeat 
TCP 
TCP 
1. Listen TCP socket 
2. Pass its socket to worker
Fluentd v1 - Zero downtime restart 
> SocketManager shares the resource 
34 
Worker 
Supervisor 
1. Listen TCP socket 
2. Pass its socket to worker 
3. Do same action 
at worker restarting 
with keeping TCP socket 
Worker 
TCP 
TCP 
heartbeat
Demo (if I have a time…)
Cloud service for the entire data pipeline 
Check: www.treasuredata.com

More Related Content

What's hot

Hoodie - DataEngConf 2017
Hoodie - DataEngConf 2017Hoodie - DataEngConf 2017
Hoodie - DataEngConf 2017Vinoth Chandar
 
Hadoop For Enterprises
Hadoop For EnterprisesHadoop For Enterprises
Hadoop For Enterprisesnvvrajesh
 
Building robust CDC pipeline with Apache Hudi and Debezium
Building robust CDC pipeline with Apache Hudi and DebeziumBuilding robust CDC pipeline with Apache Hudi and Debezium
Building robust CDC pipeline with Apache Hudi and DebeziumTathastu.ai
 
Strata NYC 2015: What's new in Spark Streaming
Strata NYC 2015: What's new in Spark StreamingStrata NYC 2015: What's new in Spark Streaming
Strata NYC 2015: What's new in Spark StreamingDatabricks
 
A Container-based Sizing Framework for Apache Hadoop/Spark Clusters
A Container-based Sizing Framework for Apache Hadoop/Spark ClustersA Container-based Sizing Framework for Apache Hadoop/Spark Clusters
A Container-based Sizing Framework for Apache Hadoop/Spark ClustersDataWorks Summit/Hadoop Summit
 
Designing and Building Next Generation Data Pipelines at Scale with Structure...
Designing and Building Next Generation Data Pipelines at Scale with Structure...Designing and Building Next Generation Data Pipelines at Scale with Structure...
Designing and Building Next Generation Data Pipelines at Scale with Structure...Databricks
 
Apache sqoop with an use case
Apache sqoop with an use caseApache sqoop with an use case
Apache sqoop with an use caseDavin Abraham
 
Impala Architecture presentation
Impala Architecture presentationImpala Architecture presentation
Impala Architecture presentationhadooparchbook
 
Spark Internals Training | Apache Spark | Spark | Anika Technologies
Spark Internals Training | Apache Spark | Spark | Anika TechnologiesSpark Internals Training | Apache Spark | Spark | Anika Technologies
Spark Internals Training | Apache Spark | Spark | Anika TechnologiesAnand Narayanan
 
Processing Large Data with Apache Spark -- HasGeek
Processing Large Data with Apache Spark -- HasGeekProcessing Large Data with Apache Spark -- HasGeek
Processing Large Data with Apache Spark -- HasGeekVenkata Naga Ravi
 
Reactive app using actor model & apache spark
Reactive app using actor model & apache sparkReactive app using actor model & apache spark
Reactive app using actor model & apache sparkRahul Kumar
 
Hudi: Large-Scale, Near Real-Time Pipelines at Uber with Nishith Agarwal and ...
Hudi: Large-Scale, Near Real-Time Pipelines at Uber with Nishith Agarwal and ...Hudi: Large-Scale, Near Real-Time Pipelines at Uber with Nishith Agarwal and ...
Hudi: Large-Scale, Near Real-Time Pipelines at Uber with Nishith Agarwal and ...Databricks
 
Spark Streaming & Kafka-The Future of Stream Processing
Spark Streaming & Kafka-The Future of Stream ProcessingSpark Streaming & Kafka-The Future of Stream Processing
Spark Streaming & Kafka-The Future of Stream ProcessingJack Gudenkauf
 
Near Real Time Indexing Kafka Messages into Apache Blur: Presented by Dibyend...
Near Real Time Indexing Kafka Messages into Apache Blur: Presented by Dibyend...Near Real Time Indexing Kafka Messages into Apache Blur: Presented by Dibyend...
Near Real Time Indexing Kafka Messages into Apache Blur: Presented by Dibyend...Lucidworks
 
Hadoop and rdbms with sqoop
Hadoop and rdbms with sqoop Hadoop and rdbms with sqoop
Hadoop and rdbms with sqoop Guy Harrison
 
Alpine academy apache spark series #1 introduction to cluster computing wit...
Alpine academy apache spark series #1   introduction to cluster computing wit...Alpine academy apache spark series #1   introduction to cluster computing wit...
Alpine academy apache spark series #1 introduction to cluster computing wit...Holden Karau
 
High concurrency,
Low latency analytics
using Spark/Kudu
 High concurrency,
Low latency analytics
using Spark/Kudu High concurrency,
Low latency analytics
using Spark/Kudu
High concurrency,
Low latency analytics
using Spark/KuduChris George
 
Real time data viz with Spark Streaming, Kafka and D3.js
Real time data viz with Spark Streaming, Kafka and D3.jsReal time data viz with Spark Streaming, Kafka and D3.js
Real time data viz with Spark Streaming, Kafka and D3.jsBen Laird
 
Spark-on-Yarn: The Road Ahead-(Marcelo Vanzin, Cloudera)
Spark-on-Yarn: The Road Ahead-(Marcelo Vanzin, Cloudera)Spark-on-Yarn: The Road Ahead-(Marcelo Vanzin, Cloudera)
Spark-on-Yarn: The Road Ahead-(Marcelo Vanzin, Cloudera)Spark Summit
 

What's hot (20)

Hoodie - DataEngConf 2017
Hoodie - DataEngConf 2017Hoodie - DataEngConf 2017
Hoodie - DataEngConf 2017
 
Hadoop For Enterprises
Hadoop For EnterprisesHadoop For Enterprises
Hadoop For Enterprises
 
spark-kafka_mod
spark-kafka_modspark-kafka_mod
spark-kafka_mod
 
Building robust CDC pipeline with Apache Hudi and Debezium
Building robust CDC pipeline with Apache Hudi and DebeziumBuilding robust CDC pipeline with Apache Hudi and Debezium
Building robust CDC pipeline with Apache Hudi and Debezium
 
Strata NYC 2015: What's new in Spark Streaming
Strata NYC 2015: What's new in Spark StreamingStrata NYC 2015: What's new in Spark Streaming
Strata NYC 2015: What's new in Spark Streaming
 
A Container-based Sizing Framework for Apache Hadoop/Spark Clusters
A Container-based Sizing Framework for Apache Hadoop/Spark ClustersA Container-based Sizing Framework for Apache Hadoop/Spark Clusters
A Container-based Sizing Framework for Apache Hadoop/Spark Clusters
 
Designing and Building Next Generation Data Pipelines at Scale with Structure...
Designing and Building Next Generation Data Pipelines at Scale with Structure...Designing and Building Next Generation Data Pipelines at Scale with Structure...
Designing and Building Next Generation Data Pipelines at Scale with Structure...
 
Apache sqoop with an use case
Apache sqoop with an use caseApache sqoop with an use case
Apache sqoop with an use case
 
Impala Architecture presentation
Impala Architecture presentationImpala Architecture presentation
Impala Architecture presentation
 
Spark Internals Training | Apache Spark | Spark | Anika Technologies
Spark Internals Training | Apache Spark | Spark | Anika TechnologiesSpark Internals Training | Apache Spark | Spark | Anika Technologies
Spark Internals Training | Apache Spark | Spark | Anika Technologies
 
Processing Large Data with Apache Spark -- HasGeek
Processing Large Data with Apache Spark -- HasGeekProcessing Large Data with Apache Spark -- HasGeek
Processing Large Data with Apache Spark -- HasGeek
 
Reactive app using actor model & apache spark
Reactive app using actor model & apache sparkReactive app using actor model & apache spark
Reactive app using actor model & apache spark
 
Hudi: Large-Scale, Near Real-Time Pipelines at Uber with Nishith Agarwal and ...
Hudi: Large-Scale, Near Real-Time Pipelines at Uber with Nishith Agarwal and ...Hudi: Large-Scale, Near Real-Time Pipelines at Uber with Nishith Agarwal and ...
Hudi: Large-Scale, Near Real-Time Pipelines at Uber with Nishith Agarwal and ...
 
Spark Streaming & Kafka-The Future of Stream Processing
Spark Streaming & Kafka-The Future of Stream ProcessingSpark Streaming & Kafka-The Future of Stream Processing
Spark Streaming & Kafka-The Future of Stream Processing
 
Near Real Time Indexing Kafka Messages into Apache Blur: Presented by Dibyend...
Near Real Time Indexing Kafka Messages into Apache Blur: Presented by Dibyend...Near Real Time Indexing Kafka Messages into Apache Blur: Presented by Dibyend...
Near Real Time Indexing Kafka Messages into Apache Blur: Presented by Dibyend...
 
Hadoop and rdbms with sqoop
Hadoop and rdbms with sqoop Hadoop and rdbms with sqoop
Hadoop and rdbms with sqoop
 
Alpine academy apache spark series #1 introduction to cluster computing wit...
Alpine academy apache spark series #1   introduction to cluster computing wit...Alpine academy apache spark series #1   introduction to cluster computing wit...
Alpine academy apache spark series #1 introduction to cluster computing wit...
 
High concurrency,
Low latency analytics
using Spark/Kudu
 High concurrency,
Low latency analytics
using Spark/Kudu High concurrency,
Low latency analytics
using Spark/Kudu
High concurrency,
Low latency analytics
using Spark/Kudu
 
Real time data viz with Spark Streaming, Kafka and D3.js
Real time data viz with Spark Streaming, Kafka and D3.jsReal time data viz with Spark Streaming, Kafka and D3.js
Real time data viz with Spark Streaming, Kafka and D3.js
 
Spark-on-Yarn: The Road Ahead-(Marcelo Vanzin, Cloudera)
Spark-on-Yarn: The Road Ahead-(Marcelo Vanzin, Cloudera)Spark-on-Yarn: The Road Ahead-(Marcelo Vanzin, Cloudera)
Spark-on-Yarn: The Road Ahead-(Marcelo Vanzin, Cloudera)
 

Similar to RubyKaigi 2014: ServerEngine

Automating Complex Setups with Puppet
Automating Complex Setups with PuppetAutomating Complex Setups with Puppet
Automating Complex Setups with PuppetKris Buytaert
 
MySQL database replication
MySQL database replicationMySQL database replication
MySQL database replicationPoguttuezhiniVP
 
Our Puppet Story – Patterns and Learnings (sage@guug, March 2014)
Our Puppet Story – Patterns and Learnings (sage@guug, March 2014)Our Puppet Story – Patterns and Learnings (sage@guug, March 2014)
Our Puppet Story – Patterns and Learnings (sage@guug, March 2014)DECK36
 
Splunk: Forward me the REST of those shells
Splunk: Forward me the REST of those shellsSplunk: Forward me the REST of those shells
Splunk: Forward me the REST of those shellsAnthony D Hendricks
 
Ansible benelux meetup - Amsterdam 27-5-2015
Ansible benelux meetup - Amsterdam 27-5-2015Ansible benelux meetup - Amsterdam 27-5-2015
Ansible benelux meetup - Amsterdam 27-5-2015Pavel Chunyayev
 
Rhebok, High Performance Rack Handler / Rubykaigi 2015
Rhebok, High Performance Rack Handler / Rubykaigi 2015Rhebok, High Performance Rack Handler / Rubykaigi 2015
Rhebok, High Performance Rack Handler / Rubykaigi 2015Masahiro Nagano
 
MySQL Utilities -- PyTexas 2015
MySQL Utilities -- PyTexas 2015MySQL Utilities -- PyTexas 2015
MySQL Utilities -- PyTexas 2015Dave Stokes
 
Linux Du Jour
Linux Du JourLinux Du Jour
Linux Du Jourmwedgwood
 
Automating complex infrastructures with Puppet
Automating complex infrastructures with PuppetAutomating complex infrastructures with Puppet
Automating complex infrastructures with PuppetKris Buytaert
 
Treasure Data Summer Internship 2016
Treasure Data Summer Internship 2016Treasure Data Summer Internship 2016
Treasure Data Summer Internship 2016Yuta Iwama
 
Ansible for Configuration Management for Lohika DevOps training 2018 @ Lohika...
Ansible for Configuration Management for Lohika DevOps training 2018 @ Lohika...Ansible for Configuration Management for Lohika DevOps training 2018 @ Lohika...
Ansible for Configuration Management for Lohika DevOps training 2018 @ Lohika...Ihor Banadiga
 
Ansible presentation
Ansible presentationAnsible presentation
Ansible presentationSuresh Kumar
 
Performance Tuning Your Puppet Infrastructure - PuppetConf 2014
Performance Tuning Your Puppet Infrastructure - PuppetConf 2014Performance Tuning Your Puppet Infrastructure - PuppetConf 2014
Performance Tuning Your Puppet Infrastructure - PuppetConf 2014Puppet
 
Puppet Camp NYC 2014: Build a Modern Infrastructure in 45 min!
Puppet Camp NYC 2014: Build a Modern Infrastructure in 45 min!Puppet Camp NYC 2014: Build a Modern Infrastructure in 45 min!
Puppet Camp NYC 2014: Build a Modern Infrastructure in 45 min!Puppet
 
Summit demystifying systemd1
Summit demystifying systemd1Summit demystifying systemd1
Summit demystifying systemd1Susant Sahani
 
introduction to node.js
introduction to node.jsintroduction to node.js
introduction to node.jsorkaplan
 

Similar to RubyKaigi 2014: ServerEngine (20)

Cooking with Chef
Cooking with ChefCooking with Chef
Cooking with Chef
 
Automating Complex Setups with Puppet
Automating Complex Setups with PuppetAutomating Complex Setups with Puppet
Automating Complex Setups with Puppet
 
Rails Performance
Rails PerformanceRails Performance
Rails Performance
 
MySQL database replication
MySQL database replicationMySQL database replication
MySQL database replication
 
Our Puppet Story – Patterns and Learnings (sage@guug, March 2014)
Our Puppet Story – Patterns and Learnings (sage@guug, March 2014)Our Puppet Story – Patterns and Learnings (sage@guug, March 2014)
Our Puppet Story – Patterns and Learnings (sage@guug, March 2014)
 
Splunk: Forward me the REST of those shells
Splunk: Forward me the REST of those shellsSplunk: Forward me the REST of those shells
Splunk: Forward me the REST of those shells
 
Ansible benelux meetup - Amsterdam 27-5-2015
Ansible benelux meetup - Amsterdam 27-5-2015Ansible benelux meetup - Amsterdam 27-5-2015
Ansible benelux meetup - Amsterdam 27-5-2015
 
Rhebok, High Performance Rack Handler / Rubykaigi 2015
Rhebok, High Performance Rack Handler / Rubykaigi 2015Rhebok, High Performance Rack Handler / Rubykaigi 2015
Rhebok, High Performance Rack Handler / Rubykaigi 2015
 
MySQL Utilities -- PyTexas 2015
MySQL Utilities -- PyTexas 2015MySQL Utilities -- PyTexas 2015
MySQL Utilities -- PyTexas 2015
 
Linux Du Jour
Linux Du JourLinux Du Jour
Linux Du Jour
 
Automating complex infrastructures with Puppet
Automating complex infrastructures with PuppetAutomating complex infrastructures with Puppet
Automating complex infrastructures with Puppet
 
Treasure Data Summer Internship 2016
Treasure Data Summer Internship 2016Treasure Data Summer Internship 2016
Treasure Data Summer Internship 2016
 
Ansible for Configuration Management for Lohika DevOps training 2018 @ Lohika...
Ansible for Configuration Management for Lohika DevOps training 2018 @ Lohika...Ansible for Configuration Management for Lohika DevOps training 2018 @ Lohika...
Ansible for Configuration Management for Lohika DevOps training 2018 @ Lohika...
 
Ansible presentation
Ansible presentationAnsible presentation
Ansible presentation
 
Performance Tuning Your Puppet Infrastructure - PuppetConf 2014
Performance Tuning Your Puppet Infrastructure - PuppetConf 2014Performance Tuning Your Puppet Infrastructure - PuppetConf 2014
Performance Tuning Your Puppet Infrastructure - PuppetConf 2014
 
Puppet Camp NYC 2014: Build a Modern Infrastructure in 45 min!
Puppet Camp NYC 2014: Build a Modern Infrastructure in 45 min!Puppet Camp NYC 2014: Build a Modern Infrastructure in 45 min!
Puppet Camp NYC 2014: Build a Modern Infrastructure in 45 min!
 
Summit demystifying systemd1
Summit demystifying systemd1Summit demystifying systemd1
Summit demystifying systemd1
 
introduction to node.js
introduction to node.jsintroduction to node.js
introduction to node.js
 
Beyond Puppet
Beyond PuppetBeyond Puppet
Beyond Puppet
 
Node.js
Node.jsNode.js
Node.js
 

More from Treasure Data, Inc.

GDPR: A Practical Guide for Marketers
GDPR: A Practical Guide for MarketersGDPR: A Practical Guide for Marketers
GDPR: A Practical Guide for MarketersTreasure Data, Inc.
 
AR and VR by the Numbers: A Data First Approach to the Technology and Market
AR and VR by the Numbers: A Data First Approach to the Technology and MarketAR and VR by the Numbers: A Data First Approach to the Technology and Market
AR and VR by the Numbers: A Data First Approach to the Technology and MarketTreasure Data, Inc.
 
Introduction to Customer Data Platforms
Introduction to Customer Data PlatformsIntroduction to Customer Data Platforms
Introduction to Customer Data PlatformsTreasure Data, Inc.
 
Hands-On: Managing Slowly Changing Dimensions Using TD Workflow
Hands-On: Managing Slowly Changing Dimensions Using TD WorkflowHands-On: Managing Slowly Changing Dimensions Using TD Workflow
Hands-On: Managing Slowly Changing Dimensions Using TD WorkflowTreasure Data, Inc.
 
Brand Analytics Management: Measuring CLV Across Platforms, Devices and Apps
Brand Analytics Management: Measuring CLV Across Platforms, Devices and AppsBrand Analytics Management: Measuring CLV Across Platforms, Devices and Apps
Brand Analytics Management: Measuring CLV Across Platforms, Devices and AppsTreasure Data, Inc.
 
How to Power Your Customer Experience with Data
How to Power Your Customer Experience with DataHow to Power Your Customer Experience with Data
How to Power Your Customer Experience with DataTreasure Data, Inc.
 
Why Your VR Game is Virtually Useless Without Data
Why Your VR Game is Virtually Useless Without DataWhy Your VR Game is Virtually Useless Without Data
Why Your VR Game is Virtually Useless Without DataTreasure Data, Inc.
 
Connecting the Customer Data Dots
Connecting the Customer Data DotsConnecting the Customer Data Dots
Connecting the Customer Data DotsTreasure Data, Inc.
 
Harnessing Data for Better Customer Experience and Company Success
Harnessing Data for Better Customer Experience and Company SuccessHarnessing Data for Better Customer Experience and Company Success
Harnessing Data for Better Customer Experience and Company SuccessTreasure Data, Inc.
 
Packaging Ecosystems -Monki Gras 2017
Packaging Ecosystems -Monki Gras 2017Packaging Ecosystems -Monki Gras 2017
Packaging Ecosystems -Monki Gras 2017Treasure Data, Inc.
 
글로벌 사례로 보는 데이터로 돈 버는 법 - 트레저데이터 (Treasure Data)
글로벌 사례로 보는 데이터로 돈 버는 법 - 트레저데이터 (Treasure Data)글로벌 사례로 보는 데이터로 돈 버는 법 - 트레저데이터 (Treasure Data)
글로벌 사례로 보는 데이터로 돈 버는 법 - 트레저데이터 (Treasure Data)Treasure Data, Inc.
 
Introduction to New features and Use cases of Hivemall
Introduction to New features and Use cases of HivemallIntroduction to New features and Use cases of Hivemall
Introduction to New features and Use cases of HivemallTreasure Data, Inc.
 
Scaling to Infinity - Open Source meets Big Data
Scaling to Infinity - Open Source meets Big DataScaling to Infinity - Open Source meets Big Data
Scaling to Infinity - Open Source meets Big DataTreasure Data, Inc.
 
Treasure Data: Move your data from MySQL to Redshift with (not much more tha...
Treasure Data:  Move your data from MySQL to Redshift with (not much more tha...Treasure Data:  Move your data from MySQL to Redshift with (not much more tha...
Treasure Data: Move your data from MySQL to Redshift with (not much more tha...Treasure Data, Inc.
 
Treasure Data From MySQL to Redshift
Treasure Data  From MySQL to RedshiftTreasure Data  From MySQL to Redshift
Treasure Data From MySQL to RedshiftTreasure Data, Inc.
 
Unifying Events and Logs into the Cloud
Unifying Events and Logs into the CloudUnifying Events and Logs into the Cloud
Unifying Events and Logs into the CloudTreasure Data, Inc.
 

More from Treasure Data, Inc. (20)

GDPR: A Practical Guide for Marketers
GDPR: A Practical Guide for MarketersGDPR: A Practical Guide for Marketers
GDPR: A Practical Guide for Marketers
 
AR and VR by the Numbers: A Data First Approach to the Technology and Market
AR and VR by the Numbers: A Data First Approach to the Technology and MarketAR and VR by the Numbers: A Data First Approach to the Technology and Market
AR and VR by the Numbers: A Data First Approach to the Technology and Market
 
Introduction to Customer Data Platforms
Introduction to Customer Data PlatformsIntroduction to Customer Data Platforms
Introduction to Customer Data Platforms
 
Hands On: Javascript SDK
Hands On: Javascript SDKHands On: Javascript SDK
Hands On: Javascript SDK
 
Hands-On: Managing Slowly Changing Dimensions Using TD Workflow
Hands-On: Managing Slowly Changing Dimensions Using TD WorkflowHands-On: Managing Slowly Changing Dimensions Using TD Workflow
Hands-On: Managing Slowly Changing Dimensions Using TD Workflow
 
Brand Analytics Management: Measuring CLV Across Platforms, Devices and Apps
Brand Analytics Management: Measuring CLV Across Platforms, Devices and AppsBrand Analytics Management: Measuring CLV Across Platforms, Devices and Apps
Brand Analytics Management: Measuring CLV Across Platforms, Devices and Apps
 
How to Power Your Customer Experience with Data
How to Power Your Customer Experience with DataHow to Power Your Customer Experience with Data
How to Power Your Customer Experience with Data
 
Why Your VR Game is Virtually Useless Without Data
Why Your VR Game is Virtually Useless Without DataWhy Your VR Game is Virtually Useless Without Data
Why Your VR Game is Virtually Useless Without Data
 
Connecting the Customer Data Dots
Connecting the Customer Data DotsConnecting the Customer Data Dots
Connecting the Customer Data Dots
 
Harnessing Data for Better Customer Experience and Company Success
Harnessing Data for Better Customer Experience and Company SuccessHarnessing Data for Better Customer Experience and Company Success
Harnessing Data for Better Customer Experience and Company Success
 
Packaging Ecosystems -Monki Gras 2017
Packaging Ecosystems -Monki Gras 2017Packaging Ecosystems -Monki Gras 2017
Packaging Ecosystems -Monki Gras 2017
 
글로벌 사례로 보는 데이터로 돈 버는 법 - 트레저데이터 (Treasure Data)
글로벌 사례로 보는 데이터로 돈 버는 법 - 트레저데이터 (Treasure Data)글로벌 사례로 보는 데이터로 돈 버는 법 - 트레저데이터 (Treasure Data)
글로벌 사례로 보는 데이터로 돈 버는 법 - 트레저데이터 (Treasure Data)
 
Keynote - Fluentd meetup v14
Keynote - Fluentd meetup v14Keynote - Fluentd meetup v14
Keynote - Fluentd meetup v14
 
Introduction to New features and Use cases of Hivemall
Introduction to New features and Use cases of HivemallIntroduction to New features and Use cases of Hivemall
Introduction to New features and Use cases of Hivemall
 
Scalable Hadoop in the cloud
Scalable Hadoop in the cloudScalable Hadoop in the cloud
Scalable Hadoop in the cloud
 
Using Embulk at Treasure Data
Using Embulk at Treasure DataUsing Embulk at Treasure Data
Using Embulk at Treasure Data
 
Scaling to Infinity - Open Source meets Big Data
Scaling to Infinity - Open Source meets Big DataScaling to Infinity - Open Source meets Big Data
Scaling to Infinity - Open Source meets Big Data
 
Treasure Data: Move your data from MySQL to Redshift with (not much more tha...
Treasure Data:  Move your data from MySQL to Redshift with (not much more tha...Treasure Data:  Move your data from MySQL to Redshift with (not much more tha...
Treasure Data: Move your data from MySQL to Redshift with (not much more tha...
 
Treasure Data From MySQL to Redshift
Treasure Data  From MySQL to RedshiftTreasure Data  From MySQL to Redshift
Treasure Data From MySQL to Redshift
 
Unifying Events and Logs into the Cloud
Unifying Events and Logs into the CloudUnifying Events and Logs into the Cloud
Unifying Events and Logs into the Cloud
 

Recently uploaded

Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDGMarianaLemus7
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentationphoebematthew05
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 

Recently uploaded (20)

Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDG
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort ServiceHot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentation
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 

RubyKaigi 2014: ServerEngine

  • 1. ServerEngine Server programming framework for Ruby Masahiro Nakagawa Sep 19, 2014 RubyKaigi 2014
  • 2. Who are you? > Masahiro Nakagawa > github/twitter: @repeatedly > Treasure Data, Inc. > Senior Software Engineer > Fluentd / td-agent developer > I love OSS :) > D language - Phobos committer > Fluentd - Main maintainer > MessagePack / RPC- D and Python (only RPC) > The organizer of Presto Source Code Reading > etc…
  • 4. Ruby is not only for web apps! > System programs • Chef - server configuration management tool • Serverspec - spec framework for servers •Apache Deltacloud - IaaS API abstraction library > Network servers • Starling - distributed message queue server •Unicorn - multiprocess HTTP server > Log servers • Fluentd - extensible data collection tool
  • 5. Problem: server programming is hard Server programs should support: > multi-process or multi-thread > robust error handling > log rotation > signal handling > dynamic reconfiguration > metrics collection > etc...
  • 6. Solution: Use a framework ServerEngine A framework for server programming in Ruby github.com/fluent/serverengine
  • 7. What’s ServerEngine? With ServerEngine, we can write multi-process server programs, like Unicorn, easily. What we need to write is a 2 modules: Worker module and Server module. Everything else, including daemonize, logging, dynamic reconfiguration, multi-processing is done by ServerEngine.
  • 8. Hello world in ServerEngine require 'serverengine' ! module MyWorker def run until @stop logger.info "Hello world!" sleep 1 end end ! def stop @stop = true end end ! se Worker Server = ServerEngine.create(nil, MyWorker, { log: 'myserver.log', pid_path: 'myserver.pid', }) se.run Config
  • 9. How ServerEngine works? 1. Robust process management (supervisor) 2. Multi-process and multi-threading 3. Dynamic configuration reloading 4. Log rotation 5. Signal handling 6. Live restart 7. “sigdump”
  • 10. 1. Robust process management Heartbeat via pipe & auto-restart Supervisor Server Dynamic reconfiguration & live restart support Multi-process Worker Worker or Multi-thread Worker
  • 11. Each role overview Supervisor Server Worker • Manage Server • heartbeat • attach / detach • restart ! • Disable by default ! • No extension point • Manage Worker • monitor • restart ! • Some execution types • Embedded • Thread • Process ! • Extension point • before_run • after_run • after_restart • Execution unit • implement run method ! • Extension point • stop • reload • before_fork • after_start
  • 12. 2. Multi-process & multi-threading require 'serverengine' ! module MyWorker def run until @stop logger.info "Awesome work!" sleep 1 end end ! def stop @stop = true end end ! se = ServerEngine.create(nil, MyWorker, { daemonize: true, log: 'myserver.log', pid_path: 'myserver.pid', worker_type: 'process', workers: 4, }) se.run > 3 server types > embedded > process > thread - thread example se = ServerEngine.create(nil, MyWorker,{ daemonize: true, log: 'myserver.log', pid_path: 'myserver.pid', worker_type: 'thread', workers: 8, }) se.run
  • 13. 2. Multi-process & multi-threading embedded process thread fork Worker • default mode • use main thread Server Worker • use fork for parallel execution • not work on Windows • use thread for parallel execution • for JRuby and Rubinius Server WWorokrekrer Server Thread.new WWorokrekrer Worker
  • 14. 3. Dynamic reconfiguration module MyWorker def initialize reload end ! def run # … end ! def reload @message = config["message"] || "default" @sleep = config["sleep"] || 1 end end ! se = ServerEngine.create(nil, MyWorker) do YAML.load_file("config.yml").merge({ :daemonize => true, :worker_type => 'process', }) end se.run > Overwrite method > reload in worker > reload_config in server > Send USR2 signal
  • 15. 4. Log rotation > Support useful features > multi-process aware log rotation > support “trace” level > Port to Ruby core > https://github.com/ruby/ruby/pull/428 se = ServerEngine.create(MyServer, MyWorker, { log: 'myserver.log', log_level: 'debug', log_rotate_age: 5, log_rotate_size: 1 * 1024 * 1024, }) se.run
  • 16. 5. Signal handling > Queue based signal handling > serialize signal processing > signal handling is separated from signal handler to avoid lock issues SignalThread.new do |st| st.trap(:TERM) { server.stop(true) } st.trap(:QUIT) { server.stop(false) } st.trap(:USR1) { server.restart(true) } st.trap(:HUP) { server.restart(false) } st.trap(:USR2) { server.reload } # ... end
  • 17. 5. Signal handling - register 1 SignalThread INT { process_int } Register Signal INT
  • 18. 5. Signal handling - register 2 SignalThread USR1 { process_usr1 } INT { process_int } Register Signal USR1
  • 19. 5. Signal handling - register 3 SignalThread QUIT { process_quit } TERM { process_term } USR1 { process_usr1 } INT { process_int } Register Signal XXX
  • 20. 5. Signal handling - process 1 SignalThread QUIT { process_quit } TERM { process_term } USR1 { process_usr1 } { process_int } USR1 Send Signal USR1 INT Monitor queue
  • 21. 5. Signal handling - process 2 SignalThread QUIT { process_quit } TERM { process_term } USR1 { process_usr1 } INT { process_int } QUIT USR1 Send Signal QUIT
  • 22. 5. Signal handling - process 3 SignalThread QUIT { process_quit } TERM { process_term } USR1 { process_usr1 } INT { process_int } QUIT Send Signal XXX
  • 23. 6. Live Restart > Minimize server restart downtime > via INT signal > enable_detach and supervisor parameters must be true > Network server can’t use live restart > “Address already in use” occurred > use “process” worker and USR1 instead • restart workers, not server
  • 24. 6. Live Restart - flow 1 1. start a server Supervisor Server WWWooorrkrkkeeerrr
  • 25. 6. Live Restart - flow 2 2. receive SIGINT and wait for shutdown of the server Supervisor Server WWWooorrkrkkeeerrr
  • 26. 6. Live Restart - flow 3 3. start new server if the server doesn’t exit in server_detach_wait Supervisor Server Worker Server WWWooorrkrkkeeerrr
  • 27. 7. “sigdump” > SIGQUIT of JavaVM for Ruby > https://github.com/frsyuki/sigdump > dump backtrace of running threads and allocated object list > for debugging, slow code, dead-lock, … > ServerEngine traps SIGCONT for sigdump > Trapping signal is configurable using “SIGDUMP_SIGNAL” environment variable
  • 28. 7. sigdump example % kill -CONT pid % cat /tmp/sigdump-66276.log Sigdump at 2014-09-18 18:44:43 +0900 process 66276 (se.rb) Thread #<Thread:0x007fdc130cb7e0> status=sleep priority=0 se.rb:7:in `sleep' se.rb:7:in `run' /Users/repeatedly/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/serverengine-1.5.9/ lib/serverengine/worker.rb:67:in `main' /Users/repeatedly/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/serverengine-1.5.9/ lib/serverengine/embedded_server.rb:24:in `run' /Users/repeatedly/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/serverengine-1.5.9/ lib/serverengine/server.rb:85:in `main' /Users/repeatedly/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/serverengine-1.5.9/ lib/serverengine/daemon.rb:101:in `main' … Thread #<ServerEngine::SignalThread:0x007fdc13314038> status=run priority=0 … Built-in objects: 33,017: TOTAL 16,845: T_STRING … All objects: 8,939: String 1,459: Array … String 210,569 bytes Array 4 elements Hash 14 pairs
  • 29. Use-case1: Sneakers > A fast background processing framework for Ruby > use ServerEngine and RabbitMQ > jondot.github.io/sneakers/ Server WWWooorrkrkkeeerrr Task Sneakers RabbitMQ
  • 30. Use-case2: Fluentd v1 > Data collector for unified logging layer > http://www.fluentd.org/ > Improve core features > Logging > Signal handling > New features based on ServerEngine > Multi-process support > Zero downtime restart > etc…
  • 31. Fluentd v1 - Multi-process Worker Supervisor Worker Worker <Worker> input tail output forward </worker> <Worker> input forward output webhdfs </worker> <Worker> input foo output bar </worker> Separate stream pipelines in one instance!
  • 32. Fluentd v1 - Zero downtime restart > SocketManager shares the resource 32 Supervisor TCP 1. Listen TCP socket
  • 33. Fluentd v1 - Zero downtime restart > SocketManager shares the resource 33 Worker Supervisor heartbeat TCP TCP 1. Listen TCP socket 2. Pass its socket to worker
  • 34. Fluentd v1 - Zero downtime restart > SocketManager shares the resource 34 Worker Supervisor 1. Listen TCP socket 2. Pass its socket to worker 3. Do same action at worker restarting with keeping TCP socket Worker TCP TCP heartbeat
  • 35. Demo (if I have a time…)
  • 36. Cloud service for the entire data pipeline Check: www.treasuredata.com