SlideShare uma empresa Scribd logo
1 de 20
Baixar para ler offline
JRuby on Rails and
Thread Safety
Naoto Takai
Akasaka.rb / Itochu Techno-Solutions Corp.
29 November 2008
‣ JRuby on Rails and Thread Safety
‣ ActiveRecord and Connection Pooling
‣ JNDI and Connection Pooling
‣ JRuby on Rails and Thread Safety
‣ ActiveRecord and Connection Pooling
‣ JNDI and Connection Pooling
Ruby on Rails 2.2 Release Notes
Ruby on Rails 2.1 or Prior

            Ruby
Process              Rails
          Instance




            Ruby
Process              Rails         Database
          Instance




            Ruby
Process              Rails
          Instance
JRuby on Rails 2.1 or Prior

Thread

           JRuby
                     Rails
          Instance

Thread

           JRuby
                     Rails         Database
          Instance

Thread

           JRuby
                     Rails
          Instance

Thread
One JRuby Instance,
  One Database Connection




          JRuby
Thread              Rails   Database
         Instance
JRuby on Rails 2.2 or Later

Thread

              JRuby
                        Rails
             Instance

Thread

              JRuby             Connection
                        Rails                Database
             Instance             Pool

Thread

              JRuby
                        Rails
             Instance

Thread
One JRuby Instance,
Many Database Connections


Thread

            JRuby
                        Rails      Database
           Instance

Thread




   You need less JRuby instances
     per database connections.
‣ JRuby on Rails and Thread Safety
‣ ActiveRecord and Connection Pooling
‣ JNDI and Connection Pooling
ActiveRecord Connection Pool



ActiveRecord::Base.establish_connection(
  :adapter => quot;mysqlquot;,
  :username => quot;rootquot;,
  :database => quot;databasequot;,
  :pool     => 5
)
Demo Code


10.times do
  Thread.new do
    ActiveRecord::Base.connection_pool 
                      .with_connection do |c|
      ret = c.execute(quot;select connection_id()quot;)
      puts quot;Connection ID: %squot; % ret.fetch_row
    end
  end
end
ActiveRecord Connection Pooling (1)


               Check-out                 Connect
                            Connection
ActiveRecord                                       Database
                              Pool
               Connection
ActiveRecord Connection Pooling (2)


               Check-out
                            Connection
ActiveRecord                             Database
                              Pool
               Connection
ActiveRecord Connection Pooling (3)


                                         Wait
               Check-out
                            Connection
ActiveRecord                                      Database
                              Pool
               Connection

                                      Check-out

                Check-in

                            ActiveRecord
‣ JRuby on Rails and Thread Safety
‣ ActiveRecord and Connection Pooling
‣ JNDI and Connection Pooling
‣ JNDI
 (Java Naming and Directory Service)
 ‣ Binding a name to an object.
 ‣ Look-up the object by name.
Using JNDI Look-up



ActiveRecord::Base.establish_connection(
  :adapter => quot;jdbcquot;,
  :jndi     => quot;jdbc/MySQLquot;,
  :driver   => quot;com.mysql.jdbc.Driverquot;,
  :pool     => 5
)
JNDI Look-up




         Look-up
                      Reference
                                  Connection
Client                                         Database
                                    Pool
          Data
         Source
Java EE Application Server
                  Connection Pooling

                                            Connect or
                 Check-out                  Reconnect
                             ActiveRecord                App Server
ActiveRecord                  Connection                 Connection
                                  Pool                     Pool
                Connection                  Connection




                 Check-in                   Disconnect

                                                         Database

Mais conteúdo relacionado

Mais procurados

Using Node.js to Build Great Streaming Services - HTML5 Dev Conf
Using Node.js to  Build Great  Streaming Services - HTML5 Dev ConfUsing Node.js to  Build Great  Streaming Services - HTML5 Dev Conf
Using Node.js to Build Great Streaming Services - HTML5 Dev ConfTom Croucher
 
EPAM IT WEEK: AEM & TDD. It's so boring...
EPAM IT WEEK: AEM & TDD. It's so boring...EPAM IT WEEK: AEM & TDD. It's so boring...
EPAM IT WEEK: AEM & TDD. It's so boring...Andrew Manuev
 
Elastic search 클러스터관리
Elastic search 클러스터관리Elastic search 클러스터관리
Elastic search 클러스터관리HyeonSeok Choi
 
Introduction to reactive programming & ReactiveCocoa
Introduction to reactive programming & ReactiveCocoaIntroduction to reactive programming & ReactiveCocoa
Introduction to reactive programming & ReactiveCocoaFlorent Pillet
 
Django REST Framework
Django REST FrameworkDjango REST Framework
Django REST FrameworkLoad Impact
 
[Srijan Wednesday Webinar] Rails 5: What's in It for Me?
[Srijan Wednesday Webinar] Rails 5: What's in It for Me?[Srijan Wednesday Webinar] Rails 5: What's in It for Me?
[Srijan Wednesday Webinar] Rails 5: What's in It for Me?Srijan Technologies
 
Celery - A Distributed Task Queue
Celery - A Distributed Task QueueCelery - A Distributed Task Queue
Celery - A Distributed Task QueueDuy Do
 
Spring & Hibernate
Spring & HibernateSpring & Hibernate
Spring & HibernateJiayun Zhou
 
Building your first Node app with Connect & Express
Building your first Node app with Connect & ExpressBuilding your first Node app with Connect & Express
Building your first Node app with Connect & ExpressChristian Joudrey
 
RESTful API In Node Js using Express
RESTful API In Node Js using Express RESTful API In Node Js using Express
RESTful API In Node Js using Express Jeetendra singh
 
Scaling up task processing with Celery
Scaling up task processing with CeleryScaling up task processing with Celery
Scaling up task processing with CeleryNicolas Grasset
 
Node js presentation
Node js presentationNode js presentation
Node js presentationmartincabrera
 
Dmp hadoop getting_start
Dmp hadoop getting_startDmp hadoop getting_start
Dmp hadoop getting_startGim GyungJin
 

Mais procurados (20)

Using Node.js to Build Great Streaming Services - HTML5 Dev Conf
Using Node.js to  Build Great  Streaming Services - HTML5 Dev ConfUsing Node.js to  Build Great  Streaming Services - HTML5 Dev Conf
Using Node.js to Build Great Streaming Services - HTML5 Dev Conf
 
EPAM IT WEEK: AEM & TDD. It's so boring...
EPAM IT WEEK: AEM & TDD. It's so boring...EPAM IT WEEK: AEM & TDD. It's so boring...
EPAM IT WEEK: AEM & TDD. It's so boring...
 
Elastic search 클러스터관리
Elastic search 클러스터관리Elastic search 클러스터관리
Elastic search 클러스터관리
 
Introduction to reactive programming & ReactiveCocoa
Introduction to reactive programming & ReactiveCocoaIntroduction to reactive programming & ReactiveCocoa
Introduction to reactive programming & ReactiveCocoa
 
Django REST Framework
Django REST FrameworkDjango REST Framework
Django REST Framework
 
[Srijan Wednesday Webinar] Rails 5: What's in It for Me?
[Srijan Wednesday Webinar] Rails 5: What's in It for Me?[Srijan Wednesday Webinar] Rails 5: What's in It for Me?
[Srijan Wednesday Webinar] Rails 5: What's in It for Me?
 
Celery with python
Celery with pythonCelery with python
Celery with python
 
Celery - A Distributed Task Queue
Celery - A Distributed Task QueueCelery - A Distributed Task Queue
Celery - A Distributed Task Queue
 
Everything as a code
Everything as a codeEverything as a code
Everything as a code
 
Django Celery
Django Celery Django Celery
Django Celery
 
Spring & Hibernate
Spring & HibernateSpring & Hibernate
Spring & Hibernate
 
Gradle Introduction
Gradle IntroductionGradle Introduction
Gradle Introduction
 
Building your first Node app with Connect & Express
Building your first Node app with Connect & ExpressBuilding your first Node app with Connect & Express
Building your first Node app with Connect & Express
 
RESTful API In Node Js using Express
RESTful API In Node Js using Express RESTful API In Node Js using Express
RESTful API In Node Js using Express
 
Scaling up task processing with Celery
Scaling up task processing with CeleryScaling up task processing with Celery
Scaling up task processing with Celery
 
Connection Pooling
Connection PoolingConnection Pooling
Connection Pooling
 
Node.js
Node.jsNode.js
Node.js
 
Node js presentation
Node js presentationNode js presentation
Node js presentation
 
Dmp hadoop getting_start
Dmp hadoop getting_startDmp hadoop getting_start
Dmp hadoop getting_start
 
NodeJs
NodeJsNodeJs
NodeJs
 

Semelhante a JRuby on Rails thread safety and connection pooling

Rollin onj Rubyv3
Rollin onj Rubyv3Rollin onj Rubyv3
Rollin onj Rubyv3Oracle
 
DeveloperWeek Europe 2023 - Revolutionize Java DB AppDev with Reactive Stream...
DeveloperWeek Europe 2023 - Revolutionize Java DB AppDev with Reactive Stream...DeveloperWeek Europe 2023 - Revolutionize Java DB AppDev with Reactive Stream...
DeveloperWeek Europe 2023 - Revolutionize Java DB AppDev with Reactive Stream...Juarez Junior
 
TDC Connections 2023 - Revolutionize Java DB AppDev with Reactive Streams and...
TDC Connections 2023 - Revolutionize Java DB AppDev with Reactive Streams and...TDC Connections 2023 - Revolutionize Java DB AppDev with Reactive Streams and...
TDC Connections 2023 - Revolutionize Java DB AppDev with Reactive Streams and...Juarez Junior
 
04.egovFrame Runtime Environment Workshop
04.egovFrame Runtime Environment Workshop04.egovFrame Runtime Environment Workshop
04.egovFrame Runtime Environment WorkshopChuong Nguyen
 
Connecting the Worlds of Java and Ruby with JRuby
Connecting the Worlds of Java and Ruby with JRubyConnecting the Worlds of Java and Ruby with JRuby
Connecting the Worlds of Java and Ruby with JRubyNick Sieger
 
JRuby - Programmer's Best Friend on JVM
JRuby - Programmer's Best Friend on JVMJRuby - Programmer's Best Friend on JVM
JRuby - Programmer's Best Friend on JVMRaimonds Simanovskis
 
The Java EE 7 Platform: Productivity++ & Embracing HTML5
The Java EE 7 Platform: Productivity++ & Embracing HTML5The Java EE 7 Platform: Productivity++ & Embracing HTML5
The Java EE 7 Platform: Productivity++ & Embracing HTML5Arun Gupta
 
jPrime 2023 - Revolutionize Java DB AppDev with Reactive Streams and Virtual ...
jPrime 2023 - Revolutionize Java DB AppDev with Reactive Streams and Virtual ...jPrime 2023 - Revolutionize Java DB AppDev with Reactive Streams and Virtual ...
jPrime 2023 - Revolutionize Java DB AppDev with Reactive Streams and Virtual ...Juarez Junior
 
The Java EE 7 Platform: Productivity & HTML5 at San Francisco JUG
The Java EE 7 Platform: Productivity & HTML5 at San Francisco JUGThe Java EE 7 Platform: Productivity & HTML5 at San Francisco JUG
The Java EE 7 Platform: Productivity & HTML5 at San Francisco JUGArun Gupta
 
Data Integration with server side Mashups
Data Integration with server side MashupsData Integration with server side Mashups
Data Integration with server side Mashupsjbrendel
 
Spring db-access mod03
Spring db-access mod03Spring db-access mod03
Spring db-access mod03Guo Albert
 
Admin High Availability
Admin High AvailabilityAdmin High Availability
Admin High Availabilityrsnarayanan
 
Clojure at BackType
Clojure at BackTypeClojure at BackType
Clojure at BackTypenathanmarz
 
Quick Intro To JRuby
Quick Intro To JRubyQuick Intro To JRuby
Quick Intro To JRubyFrederic Jean
 
MongoDB for Java Devs with Spring Data - MongoPhilly 2011
MongoDB for Java Devs with Spring Data - MongoPhilly 2011MongoDB for Java Devs with Spring Data - MongoPhilly 2011
MongoDB for Java Devs with Spring Data - MongoPhilly 2011MongoDB
 

Semelhante a JRuby on Rails thread safety and connection pooling (20)

Rollin onj Rubyv3
Rollin onj Rubyv3Rollin onj Rubyv3
Rollin onj Rubyv3
 
Jdbc
JdbcJdbc
Jdbc
 
DeveloperWeek Europe 2023 - Revolutionize Java DB AppDev with Reactive Stream...
DeveloperWeek Europe 2023 - Revolutionize Java DB AppDev with Reactive Stream...DeveloperWeek Europe 2023 - Revolutionize Java DB AppDev with Reactive Stream...
DeveloperWeek Europe 2023 - Revolutionize Java DB AppDev with Reactive Stream...
 
Complete java
Complete javaComplete java
Complete java
 
TDC Connections 2023 - Revolutionize Java DB AppDev with Reactive Streams and...
TDC Connections 2023 - Revolutionize Java DB AppDev with Reactive Streams and...TDC Connections 2023 - Revolutionize Java DB AppDev with Reactive Streams and...
TDC Connections 2023 - Revolutionize Java DB AppDev with Reactive Streams and...
 
04.egovFrame Runtime Environment Workshop
04.egovFrame Runtime Environment Workshop04.egovFrame Runtime Environment Workshop
04.egovFrame Runtime Environment Workshop
 
Connecting the Worlds of Java and Ruby with JRuby
Connecting the Worlds of Java and Ruby with JRubyConnecting the Worlds of Java and Ruby with JRuby
Connecting the Worlds of Java and Ruby with JRuby
 
JRuby - Programmer's Best Friend on JVM
JRuby - Programmer's Best Friend on JVMJRuby - Programmer's Best Friend on JVM
JRuby - Programmer's Best Friend on JVM
 
The Java EE 7 Platform: Productivity++ & Embracing HTML5
The Java EE 7 Platform: Productivity++ & Embracing HTML5The Java EE 7 Platform: Productivity++ & Embracing HTML5
The Java EE 7 Platform: Productivity++ & Embracing HTML5
 
jPrime 2023 - Revolutionize Java DB AppDev with Reactive Streams and Virtual ...
jPrime 2023 - Revolutionize Java DB AppDev with Reactive Streams and Virtual ...jPrime 2023 - Revolutionize Java DB AppDev with Reactive Streams and Virtual ...
jPrime 2023 - Revolutionize Java DB AppDev with Reactive Streams and Virtual ...
 
The Java EE 7 Platform: Productivity & HTML5 at San Francisco JUG
The Java EE 7 Platform: Productivity & HTML5 at San Francisco JUGThe Java EE 7 Platform: Productivity & HTML5 at San Francisco JUG
The Java EE 7 Platform: Productivity & HTML5 at San Francisco JUG
 
Jdbc
JdbcJdbc
Jdbc
 
Data Integration with server side Mashups
Data Integration with server side MashupsData Integration with server side Mashups
Data Integration with server side Mashups
 
Spring db-access mod03
Spring db-access mod03Spring db-access mod03
Spring db-access mod03
 
JDBC
JDBCJDBC
JDBC
 
Admin High Availability
Admin High AvailabilityAdmin High Availability
Admin High Availability
 
Clojure at BackType
Clojure at BackTypeClojure at BackType
Clojure at BackType
 
Quick Intro To JRuby
Quick Intro To JRubyQuick Intro To JRuby
Quick Intro To JRuby
 
10 J D B C
10  J D B C10  J D B C
10 J D B C
 
MongoDB for Java Devs with Spring Data - MongoPhilly 2011
MongoDB for Java Devs with Spring Data - MongoPhilly 2011MongoDB for Java Devs with Spring Data - MongoPhilly 2011
MongoDB for Java Devs with Spring Data - MongoPhilly 2011
 

Mais de Naoto Takai

私と自分戦略
私と自分戦略私と自分戦略
私と自分戦略Naoto Takai
 
地域.rbのご提案
地域.rbのご提案地域.rbのご提案
地域.rbのご提案Naoto Takai
 
JRuby最新事情@札幌
JRuby最新事情@札幌JRuby最新事情@札幌
JRuby最新事情@札幌Naoto Takai
 
JRoRでGAE/Jの手引き
JRoRでGAE/Jの手引きJRoRでGAE/Jの手引き
JRoRでGAE/Jの手引きNaoto Takai
 
『エンタープライズRails』に学ぶ企業ユーザのためのRailsアーキテクチャ
『エンタープライズRails』に学ぶ企業ユーザのためのRailsアーキテクチャ『エンタープライズRails』に学ぶ企業ユーザのためのRailsアーキテクチャ
『エンタープライズRails』に学ぶ企業ユーザのためのRailsアーキテクチャNaoto Takai
 
5分でわかるJRuby最新事情
5分でわかるJRuby最新事情5分でわかるJRuby最新事情
5分でわかるJRuby最新事情Naoto Takai
 

Mais de Naoto Takai (6)

私と自分戦略
私と自分戦略私と自分戦略
私と自分戦略
 
地域.rbのご提案
地域.rbのご提案地域.rbのご提案
地域.rbのご提案
 
JRuby最新事情@札幌
JRuby最新事情@札幌JRuby最新事情@札幌
JRuby最新事情@札幌
 
JRoRでGAE/Jの手引き
JRoRでGAE/Jの手引きJRoRでGAE/Jの手引き
JRoRでGAE/Jの手引き
 
『エンタープライズRails』に学ぶ企業ユーザのためのRailsアーキテクチャ
『エンタープライズRails』に学ぶ企業ユーザのためのRailsアーキテクチャ『エンタープライズRails』に学ぶ企業ユーザのためのRailsアーキテクチャ
『エンタープライズRails』に学ぶ企業ユーザのためのRailsアーキテクチャ
 
5分でわかるJRuby最新事情
5分でわかるJRuby最新事情5分でわかるJRuby最新事情
5分でわかるJRuby最新事情
 

Último

Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
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
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
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
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAndikSusilo4
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 

Último (20)

Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
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
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
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
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & Application
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 

JRuby on Rails thread safety and connection pooling

  • 1. JRuby on Rails and Thread Safety Naoto Takai Akasaka.rb / Itochu Techno-Solutions Corp. 29 November 2008
  • 2. ‣ JRuby on Rails and Thread Safety ‣ ActiveRecord and Connection Pooling ‣ JNDI and Connection Pooling
  • 3. ‣ JRuby on Rails and Thread Safety ‣ ActiveRecord and Connection Pooling ‣ JNDI and Connection Pooling
  • 4. Ruby on Rails 2.2 Release Notes
  • 5. Ruby on Rails 2.1 or Prior Ruby Process Rails Instance Ruby Process Rails Database Instance Ruby Process Rails Instance
  • 6. JRuby on Rails 2.1 or Prior Thread JRuby Rails Instance Thread JRuby Rails Database Instance Thread JRuby Rails Instance Thread
  • 7. One JRuby Instance, One Database Connection JRuby Thread Rails Database Instance
  • 8. JRuby on Rails 2.2 or Later Thread JRuby Rails Instance Thread JRuby Connection Rails Database Instance Pool Thread JRuby Rails Instance Thread
  • 9. One JRuby Instance, Many Database Connections Thread JRuby Rails Database Instance Thread You need less JRuby instances per database connections.
  • 10. ‣ JRuby on Rails and Thread Safety ‣ ActiveRecord and Connection Pooling ‣ JNDI and Connection Pooling
  • 11. ActiveRecord Connection Pool ActiveRecord::Base.establish_connection( :adapter => quot;mysqlquot;, :username => quot;rootquot;, :database => quot;databasequot;, :pool => 5 )
  • 12. Demo Code 10.times do Thread.new do ActiveRecord::Base.connection_pool .with_connection do |c| ret = c.execute(quot;select connection_id()quot;) puts quot;Connection ID: %squot; % ret.fetch_row end end end
  • 13. ActiveRecord Connection Pooling (1) Check-out Connect Connection ActiveRecord Database Pool Connection
  • 14. ActiveRecord Connection Pooling (2) Check-out Connection ActiveRecord Database Pool Connection
  • 15. ActiveRecord Connection Pooling (3) Wait Check-out Connection ActiveRecord Database Pool Connection Check-out Check-in ActiveRecord
  • 16. ‣ JRuby on Rails and Thread Safety ‣ ActiveRecord and Connection Pooling ‣ JNDI and Connection Pooling
  • 17. ‣ JNDI (Java Naming and Directory Service) ‣ Binding a name to an object. ‣ Look-up the object by name.
  • 18. Using JNDI Look-up ActiveRecord::Base.establish_connection( :adapter => quot;jdbcquot;, :jndi => quot;jdbc/MySQLquot;, :driver => quot;com.mysql.jdbc.Driverquot;, :pool => 5 )
  • 19. JNDI Look-up Look-up Reference Connection Client Database Pool Data Source
  • 20. Java EE Application Server Connection Pooling Connect or Check-out Reconnect ActiveRecord App Server ActiveRecord Connection Connection Pool Pool Connection Connection Check-in Disconnect Database