SlideShare une entreprise Scribd logo
1  sur  22
Télécharger pour lire hors ligne
Is Ruby Logger
Thread(Process)safe?
RubyConf 2013 @Miami
SEO Naotoshi (@sonots)
2013/11/09
Naotoshi SEO
like Now-toshi Say-oh

@sonots (twitter, github)
Dev Engineer for Operations
Became as a commiter of Fluentd
•realtime pipelining of log streams
•plugins written in ruby
Log Management Tool
•syslog-ng / rsyslog Only collection
Not Free
•splunk
No Plugin
•scribed
Java Plugin
•flumeNG
Ruby Plugin (Not Gem)
•logstash
•fluentd Ruby Plugin (Gem Support)
Try the
fluentd!
It s very nice tool, check it out!
http://fluentd.org/
Today s
Talk
Logger
We needed a
Logger which
works safely
in multiprocess
for Fluentd
Examined Ruby Logger
• 1) Will logs not be mixtured in multi-threads?
• 2) Will logs not be mixtured in multi-processes?
• 3) Does log rotation work safely in multi-threads?
• 4) Does log rotation work safely in multi-processes?
1) Will logs not be mixtured in multi-threads?
Code

require 'logger'
require 'parallel'
logger = Logger.new("/tmp/test.log")
Parallel.map(['a', 'b'], :in_threads => 2) do |letter|
10000.times do
logger.info letter * 5000
end
end
Result

$ egrep -e 'ab' -e 'ba' /tmp/test.log
[empty]

OK
WHY?
logger.rb#L559
def write(message)
begin
@mutex.synchronize do
...
@dev.write(message)
...
end

Ruby’s Logger is taking mutex to be thread-safe.
2) Will logs not be mixtured in multi-processes?
Code
require 'logger'
require 'parallel'
logger = Logger.new("/tmp/test.log")
Parallel.map(['a', 'b'], :in_processes => 2) do |letter|
10000.times do
logger.info letter * 5000
end
end
Result
$ egrep -e 'ab' -e 'ba' /tmp/test.log
[empty]

OK
Really? Why?
Mutex does not work to exclusively lock in multiprocesses environment.
Atomic/non-atomic: A write is atomic if the whole amount written in one
operation is not interleaved with data from any other process. This is
useful when there are multiple writers sending data to a single reader.
Applications need to know how large a write request can be expected to
be performed atomically. This maximum is called {PIPE_BUF}. This volume
of IEEE Std 1003.1-2001 does not say whether write requests for more
than {PIPE_BUF} bytes are atomic, but requires that writes of {PIPE_BUF} or
fewer bytes shall be atomic.

But, Linux system call write(2) itself is atomic as long
as writing to a local file.

OK
3) Does log rotation work safely multi-threads?
Code
require 'logger'
require 'parallel'
logger = Logger.new("/tmp/test.log", 3, 1024 * 10)
Parallel.map(['a', 'b'], :in_threads => 2) do |letter|
10000.times do
logger.info letter * 5000
end
end
Result
$ ls -l /tmp/test*
-rw-r--r-- 1 sonots sonots 10806

9月 29 23:03 /tmp/test.log

-rw-r--r-- 1 sonots sonots 10806

9月 29 23:03 /tmp/test.log.0

-rw-r--r-- 1 sonots sonots 10806

9月 29 23:03 /tmp/test.log.1

No Error, OK
4) Does log rotation work safely in multi-processes?
Code
require 'logger'
require 'parallel'
logger = Logger.new("/tmp/test.log", 3, 1024 * 10)
Parallel.map(['a', 'b'], :in_processes => 2) do |letter|
10000.times do
logger.info letter * 5000
end
end
Result
log
log
log
log
...

writing failed. closed stream
shifting failed. closed stream
writing failed. closed stream
shifting failed. closed stream

Oops, Bad!
WHY?
logger.rb#L559
def write(message)
begin
@mutex.synchronize do
...
check_shift_log
...
end

Ruby’s Logger is taking mutex to be thread-safe,
but was not treating anything for multi-processes.
We(@frsyuki and me) Fixed

• The approach is to use flock(2) without creating
another *.lock file
Pull requested to ruby

My first contribution to ruby
Merged!!
Thanks to @naruse for his review and advice!!
Will be released
with 2.1.0!!
on 12/25
CONCLUSION
• Ruby Logger was not safe in multiprocesses, but it is safe now!!!

• Try ruby-trunk or
https://github.com/sonots/
process_safe_logger
Try the
fluentd!
It s very nice tool, check it out!
http://fluentd.org/

Contenu connexe

Tendances

Understanding eBPF in a Hurry!
Understanding eBPF in a Hurry!Understanding eBPF in a Hurry!
Understanding eBPF in a Hurry!Ray Jenkins
 
Tracing MariaDB server with bpftrace - MariaDB Server Fest 2021
Tracing MariaDB server with bpftrace - MariaDB Server Fest 2021Tracing MariaDB server with bpftrace - MariaDB Server Fest 2021
Tracing MariaDB server with bpftrace - MariaDB Server Fest 2021Valeriy Kravchuk
 
Linux kernel tracing superpowers in the cloud
Linux kernel tracing superpowers in the cloudLinux kernel tracing superpowers in the cloud
Linux kernel tracing superpowers in the cloudAndrea Righi
 
Andrea Righi - Spying on the Linux kernel for fun and profit
Andrea Righi - Spying on the Linux kernel for fun and profitAndrea Righi - Spying on the Linux kernel for fun and profit
Andrea Righi - Spying on the Linux kernel for fun and profitlinuxlab_conf
 
Bpf performance tools chapter 4 bcc
Bpf performance tools chapter 4   bccBpf performance tools chapter 4   bcc
Bpf performance tools chapter 4 bccViller Hsiao
 
Linux fundamental - Chap 14 shell script
Linux fundamental - Chap 14 shell scriptLinux fundamental - Chap 14 shell script
Linux fundamental - Chap 14 shell scriptKenny (netman)
 
eBPF Trace from Kernel to Userspace
eBPF Trace from Kernel to UserspaceeBPF Trace from Kernel to Userspace
eBPF Trace from Kernel to UserspaceSUSE Labs Taipei
 
Windows IOCP vs Linux EPOLL Performance Comparison
Windows IOCP vs Linux EPOLL Performance ComparisonWindows IOCP vs Linux EPOLL Performance Comparison
Windows IOCP vs Linux EPOLL Performance ComparisonSeungmo Koo
 
Performance Analysis Tools for Linux Kernel
Performance Analysis Tools for Linux KernelPerformance Analysis Tools for Linux Kernel
Performance Analysis Tools for Linux Kernellcplcp1
 
Staring into the eBPF Abyss
Staring into the eBPF AbyssStaring into the eBPF Abyss
Staring into the eBPF AbyssSasha Goldshtein
 
Make Your Containers Faster: Linux Container Performance Tools
Make Your Containers Faster: Linux Container Performance ToolsMake Your Containers Faster: Linux Container Performance Tools
Make Your Containers Faster: Linux Container Performance ToolsKernel TLV
 
zebra & openconfigd Introduction
zebra & openconfigd Introductionzebra & openconfigd Introduction
zebra & openconfigd IntroductionKentaro Ebisawa
 
Systemtap
SystemtapSystemtap
SystemtapFeng Yu
 
Security Monitoring with eBPF
Security Monitoring with eBPFSecurity Monitoring with eBPF
Security Monitoring with eBPFAlex Maestretti
 
netfilter and iptables
netfilter and iptablesnetfilter and iptables
netfilter and iptablesKernel TLV
 
Porting and Optimization of Numerical Libraries for ARM SVE
Porting and Optimization of Numerical Libraries for ARM SVEPorting and Optimization of Numerical Libraries for ARM SVE
Porting and Optimization of Numerical Libraries for ARM SVELinaro
 
Modern Linux Tracing Landscape
Modern Linux Tracing LandscapeModern Linux Tracing Landscape
Modern Linux Tracing LandscapeKernel TLV
 
Profiling and optimizing go programs
Profiling and optimizing go programsProfiling and optimizing go programs
Profiling and optimizing go programsBadoo Development
 
A brief history of system calls
A brief history of system callsA brief history of system calls
A brief history of system callsSysdig
 

Tendances (20)

Understanding eBPF in a Hurry!
Understanding eBPF in a Hurry!Understanding eBPF in a Hurry!
Understanding eBPF in a Hurry!
 
Tracing MariaDB server with bpftrace - MariaDB Server Fest 2021
Tracing MariaDB server with bpftrace - MariaDB Server Fest 2021Tracing MariaDB server with bpftrace - MariaDB Server Fest 2021
Tracing MariaDB server with bpftrace - MariaDB Server Fest 2021
 
Linux crontab
Linux crontabLinux crontab
Linux crontab
 
Linux kernel tracing superpowers in the cloud
Linux kernel tracing superpowers in the cloudLinux kernel tracing superpowers in the cloud
Linux kernel tracing superpowers in the cloud
 
Andrea Righi - Spying on the Linux kernel for fun and profit
Andrea Righi - Spying on the Linux kernel for fun and profitAndrea Righi - Spying on the Linux kernel for fun and profit
Andrea Righi - Spying on the Linux kernel for fun and profit
 
Bpf performance tools chapter 4 bcc
Bpf performance tools chapter 4   bccBpf performance tools chapter 4   bcc
Bpf performance tools chapter 4 bcc
 
Linux fundamental - Chap 14 shell script
Linux fundamental - Chap 14 shell scriptLinux fundamental - Chap 14 shell script
Linux fundamental - Chap 14 shell script
 
eBPF Trace from Kernel to Userspace
eBPF Trace from Kernel to UserspaceeBPF Trace from Kernel to Userspace
eBPF Trace from Kernel to Userspace
 
Windows IOCP vs Linux EPOLL Performance Comparison
Windows IOCP vs Linux EPOLL Performance ComparisonWindows IOCP vs Linux EPOLL Performance Comparison
Windows IOCP vs Linux EPOLL Performance Comparison
 
Performance Analysis Tools for Linux Kernel
Performance Analysis Tools for Linux KernelPerformance Analysis Tools for Linux Kernel
Performance Analysis Tools for Linux Kernel
 
Staring into the eBPF Abyss
Staring into the eBPF AbyssStaring into the eBPF Abyss
Staring into the eBPF Abyss
 
Make Your Containers Faster: Linux Container Performance Tools
Make Your Containers Faster: Linux Container Performance ToolsMake Your Containers Faster: Linux Container Performance Tools
Make Your Containers Faster: Linux Container Performance Tools
 
zebra & openconfigd Introduction
zebra & openconfigd Introductionzebra & openconfigd Introduction
zebra & openconfigd Introduction
 
Systemtap
SystemtapSystemtap
Systemtap
 
Security Monitoring with eBPF
Security Monitoring with eBPFSecurity Monitoring with eBPF
Security Monitoring with eBPF
 
netfilter and iptables
netfilter and iptablesnetfilter and iptables
netfilter and iptables
 
Porting and Optimization of Numerical Libraries for ARM SVE
Porting and Optimization of Numerical Libraries for ARM SVEPorting and Optimization of Numerical Libraries for ARM SVE
Porting and Optimization of Numerical Libraries for ARM SVE
 
Modern Linux Tracing Landscape
Modern Linux Tracing LandscapeModern Linux Tracing Landscape
Modern Linux Tracing Landscape
 
Profiling and optimizing go programs
Profiling and optimizing go programsProfiling and optimizing go programs
Profiling and optimizing go programs
 
A brief history of system calls
A brief history of system callsA brief history of system calls
A brief history of system calls
 

Similaire à Is ruby logger thread(process)-safe? at RubyConf 2013

Will iPython replace Bash?
Will iPython replace Bash?Will iPython replace Bash?
Will iPython replace Bash?Babel
 
Will iPython replace bash?
Will iPython replace bash?Will iPython replace bash?
Will iPython replace bash?Roberto Polli
 
OSDC 2016 - Ingesting Logs with Style by Pere Urbon-Bayes
OSDC 2016 - Ingesting Logs with Style by Pere Urbon-BayesOSDC 2016 - Ingesting Logs with Style by Pere Urbon-Bayes
OSDC 2016 - Ingesting Logs with Style by Pere Urbon-BayesNETWAYS
 
Efficient logging in multithreaded C++ server
Efficient logging in multithreaded C++ serverEfficient logging in multithreaded C++ server
Efficient logging in multithreaded C++ serverShuo Chen
 
Nodejs a-practical-introduction-oredev
Nodejs a-practical-introduction-oredevNodejs a-practical-introduction-oredev
Nodejs a-practical-introduction-oredevFelix Geisendörfer
 
epoll() - The I/O Hero
epoll() - The I/O Heroepoll() - The I/O Hero
epoll() - The I/O HeroMohsin Hijazee
 
Open Source Swift Under the Hood
Open Source Swift Under the HoodOpen Source Swift Under the Hood
Open Source Swift Under the HoodC4Media
 
Swift 2 Under the Hood - Gotober 2015
Swift 2 Under the Hood - Gotober 2015Swift 2 Under the Hood - Gotober 2015
Swift 2 Under the Hood - Gotober 2015Alex Blewitt
 
Application Logging in the 21st century - 2014.key
Application Logging in the 21st century - 2014.keyApplication Logging in the 21st century - 2014.key
Application Logging in the 21st century - 2014.keyTim Bunce
 
uWSGI - Swiss army knife for your Python web apps
uWSGI - Swiss army knife for your Python web appsuWSGI - Swiss army knife for your Python web apps
uWSGI - Swiss army knife for your Python web appsTomislav Raseta
 
Concurrent Programming with Ruby and Tuple Spaces
Concurrent Programming with Ruby and Tuple SpacesConcurrent Programming with Ruby and Tuple Spaces
Concurrent Programming with Ruby and Tuple Spacesluccastera
 
Fedora Developer's Conference 2014 Talk
Fedora Developer's Conference 2014 TalkFedora Developer's Conference 2014 Talk
Fedora Developer's Conference 2014 TalkRainer Gerhards
 
CocoaConf: The Language of Mobile Software is APIs
CocoaConf: The Language of Mobile Software is APIsCocoaConf: The Language of Mobile Software is APIs
CocoaConf: The Language of Mobile Software is APIsTim Burks
 
3.1.c apend scripting, crond, atd
3.1.c apend   scripting, crond, atd3.1.c apend   scripting, crond, atd
3.1.c apend scripting, crond, atdAcácio Oliveira
 
Возможности интерпретатора Python в NX-OS
Возможности интерпретатора Python в NX-OSВозможности интерпретатора Python в NX-OS
Возможности интерпретатора Python в NX-OSCisco Russia
 
101 apend. scripting, crond, atd
101 apend. scripting, crond, atd101 apend. scripting, crond, atd
101 apend. scripting, crond, atdAcácio Oliveira
 

Similaire à Is ruby logger thread(process)-safe? at RubyConf 2013 (20)

Will iPython replace Bash?
Will iPython replace Bash?Will iPython replace Bash?
Will iPython replace Bash?
 
Will iPython replace bash?
Will iPython replace bash?Will iPython replace bash?
Will iPython replace bash?
 
OSDC 2016 - Ingesting Logs with Style by Pere Urbon-Bayes
OSDC 2016 - Ingesting Logs with Style by Pere Urbon-BayesOSDC 2016 - Ingesting Logs with Style by Pere Urbon-Bayes
OSDC 2016 - Ingesting Logs with Style by Pere Urbon-Bayes
 
Efficient logging in multithreaded C++ server
Efficient logging in multithreaded C++ serverEfficient logging in multithreaded C++ server
Efficient logging in multithreaded C++ server
 
Nodejs a-practical-introduction-oredev
Nodejs a-practical-introduction-oredevNodejs a-practical-introduction-oredev
Nodejs a-practical-introduction-oredev
 
epoll() - The I/O Hero
epoll() - The I/O Heroepoll() - The I/O Hero
epoll() - The I/O Hero
 
Open Source Swift Under the Hood
Open Source Swift Under the HoodOpen Source Swift Under the Hood
Open Source Swift Under the Hood
 
Swift 2 Under the Hood - Gotober 2015
Swift 2 Under the Hood - Gotober 2015Swift 2 Under the Hood - Gotober 2015
Swift 2 Under the Hood - Gotober 2015
 
Application Logging in the 21st century - 2014.key
Application Logging in the 21st century - 2014.keyApplication Logging in the 21st century - 2014.key
Application Logging in the 21st century - 2014.key
 
uWSGI - Swiss army knife for your Python web apps
uWSGI - Swiss army knife for your Python web appsuWSGI - Swiss army knife for your Python web apps
uWSGI - Swiss army knife for your Python web apps
 
How do event loops work in Python?
How do event loops work in Python?How do event loops work in Python?
How do event loops work in Python?
 
Threads
ThreadsThreads
Threads
 
Concurrent Programming with Ruby and Tuple Spaces
Concurrent Programming with Ruby and Tuple SpacesConcurrent Programming with Ruby and Tuple Spaces
Concurrent Programming with Ruby and Tuple Spaces
 
Fedora Developer's Conference 2014 Talk
Fedora Developer's Conference 2014 TalkFedora Developer's Conference 2014 Talk
Fedora Developer's Conference 2014 Talk
 
The basics of fluentd
The basics of fluentdThe basics of fluentd
The basics of fluentd
 
CocoaConf: The Language of Mobile Software is APIs
CocoaConf: The Language of Mobile Software is APIsCocoaConf: The Language of Mobile Software is APIs
CocoaConf: The Language of Mobile Software is APIs
 
3.1.c apend scripting, crond, atd
3.1.c apend   scripting, crond, atd3.1.c apend   scripting, crond, atd
3.1.c apend scripting, crond, atd
 
Syslog Protocols
Syslog ProtocolsSyslog Protocols
Syslog Protocols
 
Возможности интерпретатора Python в NX-OS
Возможности интерпретатора Python в NX-OSВозможности интерпретатора Python в NX-OS
Возможности интерпретатора Python в NX-OS
 
101 apend. scripting, crond, atd
101 apend. scripting, crond, atd101 apend. scripting, crond, atd
101 apend. scripting, crond, atd
 

Plus de Naotoshi Seo

ぼくのかんがえた Itamae/Serverspec 構成フレームワーク 〜 Kondate 〜
ぼくのかんがえた Itamae/Serverspec 構成フレームワーク 〜 Kondate 〜ぼくのかんがえた Itamae/Serverspec 構成フレームワーク 〜 Kondate 〜
ぼくのかんがえた Itamae/Serverspec 構成フレームワーク 〜 Kondate 〜Naotoshi Seo
 
HTTP/2 でリバプロするだけでグラフツールを 高速化できた話
HTTP/2 でリバプロするだけでグラフツールを 高速化できた話HTTP/2 でリバプロするだけでグラフツールを 高速化できた話
HTTP/2 でリバプロするだけでグラフツールを 高速化できた話Naotoshi Seo
 
Mobage を支える Ruby の技術 ~ 複数DB編 ~
Mobage を支える Ruby の技術 ~ 複数DB編 ~Mobage を支える Ruby の技術 ~ 複数DB編 ~
Mobage を支える Ruby の技術 ~ 複数DB編 ~Naotoshi Seo
 
InfluxDB の概要 - sonots #tokyoinfluxdb
InfluxDB の概要 - sonots #tokyoinfluxdbInfluxDB の概要 - sonots #tokyoinfluxdb
InfluxDB の概要 - sonots #tokyoinfluxdbNaotoshi Seo
 
Sinatra Pattern 20130415
Sinatra Pattern 20130415Sinatra Pattern 20130415
Sinatra Pattern 20130415Naotoshi Seo
 
Serf という Orchestration ツール #immutableinfra
Serf という Orchestration ツール #immutableinfraSerf という Orchestration ツール #immutableinfra
Serf という Orchestration ツール #immutableinfraNaotoshi Seo
 
Shadow Server on Fluentd at Fluentd Casual Talks #3
Shadow Server on Fluentd at Fluentd Casual Talks #3Shadow Server on Fluentd at Fluentd Casual Talks #3
Shadow Server on Fluentd at Fluentd Casual Talks #3Naotoshi Seo
 
Haikanko rubykaigi 20130531
Haikanko rubykaigi 20130531Haikanko rubykaigi 20130531
Haikanko rubykaigi 20130531Naotoshi Seo
 
Fluentdcasual 02-haikanko
Fluentdcasual 02-haikankoFluentdcasual 02-haikanko
Fluentdcasual 02-haikankoNaotoshi Seo
 
capistrano-colorized-stream
capistrano-colorized-streamcapistrano-colorized-stream
capistrano-colorized-streamNaotoshi Seo
 

Plus de Naotoshi Seo (13)

ぼくのかんがえた Itamae/Serverspec 構成フレームワーク 〜 Kondate 〜
ぼくのかんがえた Itamae/Serverspec 構成フレームワーク 〜 Kondate 〜ぼくのかんがえた Itamae/Serverspec 構成フレームワーク 〜 Kondate 〜
ぼくのかんがえた Itamae/Serverspec 構成フレームワーク 〜 Kondate 〜
 
HTTP/2 でリバプロするだけでグラフツールを 高速化できた話
HTTP/2 でリバプロするだけでグラフツールを 高速化できた話HTTP/2 でリバプロするだけでグラフツールを 高速化できた話
HTTP/2 でリバプロするだけでグラフツールを 高速化できた話
 
Mobage を支える Ruby の技術 ~ 複数DB編 ~
Mobage を支える Ruby の技術 ~ 複数DB編 ~Mobage を支える Ruby の技術 ~ 複数DB編 ~
Mobage を支える Ruby の技術 ~ 複数DB編 ~
 
InfluxDB の概要 - sonots #tokyoinfluxdb
InfluxDB の概要 - sonots #tokyoinfluxdbInfluxDB の概要 - sonots #tokyoinfluxdb
InfluxDB の概要 - sonots #tokyoinfluxdb
 
Sinatra Pattern 20130415
Sinatra Pattern 20130415Sinatra Pattern 20130415
Sinatra Pattern 20130415
 
Serf という Orchestration ツール #immutableinfra
Serf という Orchestration ツール #immutableinfraSerf という Orchestration ツール #immutableinfra
Serf という Orchestration ツール #immutableinfra
 
Shadow Server on Fluentd at Fluentd Casual Talks #3
Shadow Server on Fluentd at Fluentd Casual Talks #3Shadow Server on Fluentd at Fluentd Casual Talks #3
Shadow Server on Fluentd at Fluentd Casual Talks #3
 
Yohoushi
YohoushiYohoushi
Yohoushi
 
Haikanko rubykaigi 20130531
Haikanko rubykaigi 20130531Haikanko rubykaigi 20130531
Haikanko rubykaigi 20130531
 
Mina 20130417
Mina 20130417Mina 20130417
Mina 20130417
 
Fluentdcasual 02-haikanko
Fluentdcasual 02-haikankoFluentdcasual 02-haikanko
Fluentdcasual 02-haikanko
 
capistrano-colorized-stream
capistrano-colorized-streamcapistrano-colorized-stream
capistrano-colorized-stream
 
Ruby test double
Ruby test doubleRuby test double
Ruby test double
 

Dernier

TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
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 FMESafe Software
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Zilliz
 
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 TerraformAndrey Devyatkin
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...apidays
 
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...Jeffrey Haguewood
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdfSandro Moreira
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxRemote DBA Services
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityWSO2
 
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 FMESafe Software
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
"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 ...Zilliz
 

Dernier (20)

TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
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
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
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
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
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...
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
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
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
"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 ...
 

Is ruby logger thread(process)-safe? at RubyConf 2013

  • 1. Is Ruby Logger Thread(Process)safe? RubyConf 2013 @Miami SEO Naotoshi (@sonots) 2013/11/09
  • 2. Naotoshi SEO like Now-toshi Say-oh @sonots (twitter, github) Dev Engineer for Operations Became as a commiter of Fluentd
  • 3. •realtime pipelining of log streams •plugins written in ruby
  • 4. Log Management Tool •syslog-ng / rsyslog Only collection Not Free •splunk No Plugin •scribed Java Plugin •flumeNG Ruby Plugin (Not Gem) •logstash •fluentd Ruby Plugin (Gem Support)
  • 5. Try the fluentd! It s very nice tool, check it out! http://fluentd.org/
  • 8. We needed a Logger which works safely in multiprocess for Fluentd
  • 9. Examined Ruby Logger • 1) Will logs not be mixtured in multi-threads? • 2) Will logs not be mixtured in multi-processes? • 3) Does log rotation work safely in multi-threads? • 4) Does log rotation work safely in multi-processes?
  • 10. 1) Will logs not be mixtured in multi-threads? Code require 'logger' require 'parallel' logger = Logger.new("/tmp/test.log") Parallel.map(['a', 'b'], :in_threads => 2) do |letter| 10000.times do logger.info letter * 5000 end end Result $ egrep -e 'ab' -e 'ba' /tmp/test.log [empty] OK
  • 12. 2) Will logs not be mixtured in multi-processes? Code require 'logger' require 'parallel' logger = Logger.new("/tmp/test.log") Parallel.map(['a', 'b'], :in_processes => 2) do |letter| 10000.times do logger.info letter * 5000 end end Result $ egrep -e 'ab' -e 'ba' /tmp/test.log [empty] OK
  • 13. Really? Why? Mutex does not work to exclusively lock in multiprocesses environment. Atomic/non-atomic: A write is atomic if the whole amount written in one operation is not interleaved with data from any other process. This is useful when there are multiple writers sending data to a single reader. Applications need to know how large a write request can be expected to be performed atomically. This maximum is called {PIPE_BUF}. This volume of IEEE Std 1003.1-2001 does not say whether write requests for more than {PIPE_BUF} bytes are atomic, but requires that writes of {PIPE_BUF} or fewer bytes shall be atomic. But, Linux system call write(2) itself is atomic as long as writing to a local file. OK
  • 14. 3) Does log rotation work safely multi-threads? Code require 'logger' require 'parallel' logger = Logger.new("/tmp/test.log", 3, 1024 * 10) Parallel.map(['a', 'b'], :in_threads => 2) do |letter| 10000.times do logger.info letter * 5000 end end Result $ ls -l /tmp/test* -rw-r--r-- 1 sonots sonots 10806 9月 29 23:03 /tmp/test.log -rw-r--r-- 1 sonots sonots 10806 9月 29 23:03 /tmp/test.log.0 -rw-r--r-- 1 sonots sonots 10806 9月 29 23:03 /tmp/test.log.1 No Error, OK
  • 15. 4) Does log rotation work safely in multi-processes? Code require 'logger' require 'parallel' logger = Logger.new("/tmp/test.log", 3, 1024 * 10) Parallel.map(['a', 'b'], :in_processes => 2) do |letter| 10000.times do logger.info letter * 5000 end end Result log log log log ... writing failed. closed stream shifting failed. closed stream writing failed. closed stream shifting failed. closed stream Oops, Bad!
  • 16. WHY? logger.rb#L559 def write(message) begin @mutex.synchronize do ... check_shift_log ... end Ruby’s Logger is taking mutex to be thread-safe, but was not treating anything for multi-processes.
  • 17. We(@frsyuki and me) Fixed • The approach is to use flock(2) without creating another *.lock file
  • 18. Pull requested to ruby My first contribution to ruby
  • 19. Merged!! Thanks to @naruse for his review and advice!!
  • 20. Will be released with 2.1.0!! on 12/25
  • 21. CONCLUSION • Ruby Logger was not safe in multiprocesses, but it is safe now!!! • Try ruby-trunk or https://github.com/sonots/ process_safe_logger
  • 22. Try the fluentd! It s very nice tool, check it out! http://fluentd.org/