SlideShare une entreprise Scribd logo
1  sur  42
Experiences of
Rails site stabilized
     operation

                                 Hirotomo Oi
                                    Chief Architect
            Media Technology Lab., Recruit Co.,Ltd.
Agenda

• Our “Rails” websites
• Software
 • httpd
 • Server virtualization
• Tips
About Me

• Hirotomo Ōi
• Chief Architect of infrastructure of web.
• And “engekilife.com” tech guy.
• And...planning/developing new website.
About MTL
• MTL(Media Technology Lab.) is an
  applied study institute to promote future
  media communication, and to seek for a
  sympathetic world for all of us.

• One of our focus:
  Develop prototype web sites, and verify
  responses and feedbacks through beta
  releases.
MTL Websites
MTL   Websites
MTL   Websites
Software


• Httpd for Ruby Apps.
• Virtualization
Rails Version

• Use various versions.
 • 1.2.x, 2.0.x, 2.1.x, 2.2.x, 2.3,x...
 • We choose the newest version at
    launch time of each site.
httpd
• ...Donʼt fix, now trying...
 • Mongrel
 • Thin
 • Passenger
    • Some sites were changed from
     Mongrel.
Benchmark
           Time per request(ms):

31.00


23.25


15.50


 7.75


   0
         Mongrel                   Passenger
Ruby Version

• 1.8.6
 • If apps didnʼt work, use another vers.
• Ruby Enterprise Edition
 • for Passenger
Virtualization
Virtualization


      +
Virtualize servers

• Two or more servers
  can be running on one
                          Web,
  hardware.               App        DB         cache
                                                (memory-
                          (CPU-    (IO-bound)
                                                 bound)

• Generally, different    bound)


  resources are put
  together is good
  efficiency.
virtualize webservers
• We are virtualizing
  web+app tier.

  •   Generally web     site A
                        (ruby)
                                 site B
                                 (php)
                                          site C
                                          (perl)
      apps are CPU-
      bound.

  • RoR apps need
      memory.
How many VMs?
•   Hardware
    • 16GB memory
    • 2x Quad Core Xeon


•   VM Spec
    • 1GB memory
    • 10GB disk space
    • 8 CPU cores
      available
How many VMs?
•   Hardware
    • 16GB memory
    • 2x Quad Core Xeon


•   VM Spec                  13
    • 1GB memory          VMs / Hard
    • 10GB disk space
    • 8 CPU cores
      available
How many
instances?
How many
          instances?

•   10 Mongrel instances / 1GB mem VM.
•   24 Mongrel instances / 2GB mem VM
Tips

• DB Tuning
• Log rotation
• Restart Mongrel
DB Tuning

• Developers often forget DB tuning when
  launch the site.

 • Developers use ActiveRecord, not
    connect DB directly.
DB Tuning

• Developers often forget DB tuning when
  launch the site.

 • Developers use ActiveRecord, not
    connect DB directly.


   DO NOT FORGET DATABASE!!
Get Slow Query Log

• Step 1: know slow query.
 • my.cnf
    [mysqld]
    log-slow-queries
    long_query_time=1
EXPLAIN

• Step 2: Analysis of slow query
 • Use “EXPLAIN”
    mysql> EXPLAIN SELECT...Your Slow Query;
EXPLAIN

• Step 2: Analysis of slow query
 • Use “EXPLAIN”
    mysql> EXPLAIN SELECT...Your Slow Query;
Fix Slow Query

• Add Index
• Examine to change (ex:divide) the
  query

 • Donʼt use join...
 • Donʼt use subquery...
ex)
 mysql> show create table rubykaigi_demo
 G
 | rubykaigi_demo | CREATE TABLE
 `rubykaigi_demo` (
   `id` int(11) NOT NULL auto_increment,
   `type` varchar(255) default NULL,
   `bukken_id` int(11) default NULL,
   PRIMARY KEY (`id`)
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 |
1) Know Slow Query
mysql> SELECT * FROM `rubykaigi_demo`
WHERE `type` = 'PlayguideTicketInfoShow'
and `bukken_id` = 435;
+-------+-------------------------+-----------+
| id | type             | bukken_id |
+-------+-------------------------+-----------+
| 13139 | PlayguideTicketInfoShow |   435 |
+-------+-------------------------+-----------+
1 row in set (0.01 sec)
2) EXPLAIN
mysql> EXPLAIN SELECT * FROM
`rubykaigi_demo` WHERE `type` =
'PlayguideTicketInfoShow' and `bukken_id`
= 435G
        id: 1
 select_type: SIMPLE
     table: rubykaigi_demo
      type: ALL
possible_keys: NULL
       key: NULL
    key_len: NULL
       ref: NULL
      rows: 2299
     Extra: Using where
2) EXPLAIN
mysql> EXPLAIN SELECT * FROM
`rubykaigi_demo` WHERE `type` =
'PlayguideTicketInfoShow' and `bukken_id`
= 435G
        id: 1
 select_type: SIMPLE
     table: rubykaigi_demo
      type: ALL
possible_keys: NULL
       key: NULL
    key_len: NULL
       ref: NULL          Not   Using Index
      rows: 2299
     Extra: Using where
3) ADD INDEX
mysql> ALTER TABLE `rubykaigi_demo`
ADD INDEX( `type`, `bukken_id`);
Query OK, 1977 rows affected (0.18 sec)
Records: 1977 Duplicates: 0 Warnings: 0


or migration:
add_index "type_bukken", ["type",
"bukken_id"], :name => "type_bukken"
4) RESULT
mysql> EXPLAIN SELECT * FROM
`rubykaigi_demo` WHERE `type` =
'PlayguideTicketInfoShow' and `bukken_id`
= 435G
        id: 1
 select_type: SIMPLE
     table: rubykaigi_demo
      type: ref
possible_keys: type
       key: type
    key_len: 773
       ref: const,const
      rows: 1
     Extra: Using where; Using index
4) RESULT
mysql> EXPLAIN SELECT * FROM
`rubykaigi_demo` WHERE `type` =
'PlayguideTicketInfoShow' and `bukken_id`
= 435G
        id: 1
 select_type: SIMPLE
     table: rubykaigi_demo
      type: ref
possible_keys: type
       key: type
    key_len: 773
       ref: const,const       Using    Index
      rows: 1
     Extra: Using where; Using index
Log rotation
• “production.log” increase continuously.
• Itʼs necessary to rotate logs.
   ex) logrotate.d conf file
   (Your Rails App Log Dir)/*.log {
     daily
     missingok
     rotate 30
     compress
     notifempty
     copytruncate
     create 0644 user group
   }
Log rotation
• “production.log” increase continuously.
• Itʼs necessary to rotate logs.
   ex) logrotate.d conf file
   (Your Rails App Log Dir)/*.log {
     daily
     missingok
     rotate 30
     compress
     notifempty
     copytruncate                     Important!
     create 0644 user group
   }
Restart Mongrel

• Restart periodically for fix memory leak
  of Mongrel processes.

 • Using swap, not only the VM but all
    VMs on same HW are slow down...
Restart Mongrel
• Cron
• Logrotate.d
• Monit
Agenda
• Our “Rails” websites
• Softwares
 • httpd, virtualization,...
• Tips
 • Donʼt forget DB Tuning
 • Donʼt forget log rotation
 • Restart Mongrel
...one more thing
Comming Soon!!
  http://mashupaward.jp/
Thank you


Please contact : http://mtl.recruit.co.jp/

Contenu connexe

Tendances

MySQL Storage Engines - which do you use? TokuDB? MyRocks? InnoDB?
MySQL Storage Engines - which do you use? TokuDB? MyRocks? InnoDB?MySQL Storage Engines - which do you use? TokuDB? MyRocks? InnoDB?
MySQL Storage Engines - which do you use? TokuDB? MyRocks? InnoDB?Sveta Smirnova
 
Ansible 101 - Presentation at Ansible STL Meetup
Ansible 101 - Presentation at Ansible STL MeetupAnsible 101 - Presentation at Ansible STL Meetup
Ansible 101 - Presentation at Ansible STL MeetupJeff Geerling
 
Windows deployment on bare metal using ironic
Windows deployment on bare metal using ironicWindows deployment on bare metal using ironic
Windows deployment on bare metal using ironicSrinivasa Acharya
 
OGDC2012 Lua In Game_Mr. Van, Nguyen Ngoc
OGDC2012 Lua In Game_Mr. Van, Nguyen NgocOGDC2012 Lua In Game_Mr. Van, Nguyen Ngoc
OGDC2012 Lua In Game_Mr. Van, Nguyen NgocBuff Nguyen
 
General Bare-metal Provisioning Framework.pdf
General Bare-metal Provisioning Framework.pdfGeneral Bare-metal Provisioning Framework.pdf
General Bare-metal Provisioning Framework.pdfOpenStack Foundation
 
Building an ActionScript Game Server with over 15,000 Concurrent Connections
Building an ActionScript Game Server with over 15,000 Concurrent ConnectionsBuilding an ActionScript Game Server with over 15,000 Concurrent Connections
Building an ActionScript Game Server with over 15,000 Concurrent Connections Renaun Erickson
 
Building Windows Images with Packer
Building Windows Images with PackerBuilding Windows Images with Packer
Building Windows Images with PackerMatt Wrock
 
MongoDB Basic Concepts
MongoDB Basic ConceptsMongoDB Basic Concepts
MongoDB Basic ConceptsMongoDB
 
MongoDB Engines: Demystified
MongoDB Engines: DemystifiedMongoDB Engines: Demystified
MongoDB Engines: DemystifiedSveta Smirnova
 
Sheepdog: yet another all in-one storage for openstack
Sheepdog: yet another all in-one storage for openstackSheepdog: yet another all in-one storage for openstack
Sheepdog: yet another all in-one storage for openstackLiu Yuan
 
T4T Training day - NodeJS
T4T Training day - NodeJST4T Training day - NodeJS
T4T Training day - NodeJSTim Sommer
 
Windows Azure PowerShell CmdLets
Windows Azure PowerShell CmdLetsWindows Azure PowerShell CmdLets
Windows Azure PowerShell CmdLetsPavel Revenkov
 
PLNOG 4: Leszek Urbański - A modern HTTP accelerator for content providers
PLNOG 4: Leszek Urbański - A modern HTTP accelerator for content providersPLNOG 4: Leszek Urbański - A modern HTTP accelerator for content providers
PLNOG 4: Leszek Urbański - A modern HTTP accelerator for content providersPROIDEA
 
M|18 Writing Stored Procedures in the Real World
M|18 Writing Stored Procedures in the Real WorldM|18 Writing Stored Procedures in the Real World
M|18 Writing Stored Procedures in the Real WorldMariaDB plc
 
MOW2010: 1TB MySQL Database Migration and HA Infrastructure by Alex Gorbachev...
MOW2010: 1TB MySQL Database Migration and HA Infrastructure by Alex Gorbachev...MOW2010: 1TB MySQL Database Migration and HA Infrastructure by Alex Gorbachev...
MOW2010: 1TB MySQL Database Migration and HA Infrastructure by Alex Gorbachev...Alex Gorbachev
 
Best practices for MySQL High Availability
Best practices for MySQL High AvailabilityBest practices for MySQL High Availability
Best practices for MySQL High AvailabilityColin Charles
 
Using Capifony for Symfony apps deployment (updated)
Using Capifony for Symfony apps deployment (updated)Using Capifony for Symfony apps deployment (updated)
Using Capifony for Symfony apps deployment (updated)Žilvinas Kuusas
 
Replication features, technologies and 3rd party Extinction
Replication features, technologies and 3rd party ExtinctionReplication features, technologies and 3rd party Extinction
Replication features, technologies and 3rd party ExtinctionBen Mildren
 
OSDC 2016 - Tuning Linux for your Database by Colin Charles
OSDC 2016 - Tuning Linux for your Database by Colin CharlesOSDC 2016 - Tuning Linux for your Database by Colin Charles
OSDC 2016 - Tuning Linux for your Database by Colin CharlesNETWAYS
 

Tendances (20)

MySQL Storage Engines - which do you use? TokuDB? MyRocks? InnoDB?
MySQL Storage Engines - which do you use? TokuDB? MyRocks? InnoDB?MySQL Storage Engines - which do you use? TokuDB? MyRocks? InnoDB?
MySQL Storage Engines - which do you use? TokuDB? MyRocks? InnoDB?
 
Ansible 101 - Presentation at Ansible STL Meetup
Ansible 101 - Presentation at Ansible STL MeetupAnsible 101 - Presentation at Ansible STL Meetup
Ansible 101 - Presentation at Ansible STL Meetup
 
Windows deployment on bare metal using ironic
Windows deployment on bare metal using ironicWindows deployment on bare metal using ironic
Windows deployment on bare metal using ironic
 
OGDC2012 Lua In Game_Mr. Van, Nguyen Ngoc
OGDC2012 Lua In Game_Mr. Van, Nguyen NgocOGDC2012 Lua In Game_Mr. Van, Nguyen Ngoc
OGDC2012 Lua In Game_Mr. Van, Nguyen Ngoc
 
General Bare-metal Provisioning Framework.pdf
General Bare-metal Provisioning Framework.pdfGeneral Bare-metal Provisioning Framework.pdf
General Bare-metal Provisioning Framework.pdf
 
Building an ActionScript Game Server with over 15,000 Concurrent Connections
Building an ActionScript Game Server with over 15,000 Concurrent ConnectionsBuilding an ActionScript Game Server with over 15,000 Concurrent Connections
Building an ActionScript Game Server with over 15,000 Concurrent Connections
 
Building Windows Images with Packer
Building Windows Images with PackerBuilding Windows Images with Packer
Building Windows Images with Packer
 
The SPDY Protocol
The SPDY ProtocolThe SPDY Protocol
The SPDY Protocol
 
MongoDB Basic Concepts
MongoDB Basic ConceptsMongoDB Basic Concepts
MongoDB Basic Concepts
 
MongoDB Engines: Demystified
MongoDB Engines: DemystifiedMongoDB Engines: Demystified
MongoDB Engines: Demystified
 
Sheepdog: yet another all in-one storage for openstack
Sheepdog: yet another all in-one storage for openstackSheepdog: yet another all in-one storage for openstack
Sheepdog: yet another all in-one storage for openstack
 
T4T Training day - NodeJS
T4T Training day - NodeJST4T Training day - NodeJS
T4T Training day - NodeJS
 
Windows Azure PowerShell CmdLets
Windows Azure PowerShell CmdLetsWindows Azure PowerShell CmdLets
Windows Azure PowerShell CmdLets
 
PLNOG 4: Leszek Urbański - A modern HTTP accelerator for content providers
PLNOG 4: Leszek Urbański - A modern HTTP accelerator for content providersPLNOG 4: Leszek Urbański - A modern HTTP accelerator for content providers
PLNOG 4: Leszek Urbański - A modern HTTP accelerator for content providers
 
M|18 Writing Stored Procedures in the Real World
M|18 Writing Stored Procedures in the Real WorldM|18 Writing Stored Procedures in the Real World
M|18 Writing Stored Procedures in the Real World
 
MOW2010: 1TB MySQL Database Migration and HA Infrastructure by Alex Gorbachev...
MOW2010: 1TB MySQL Database Migration and HA Infrastructure by Alex Gorbachev...MOW2010: 1TB MySQL Database Migration and HA Infrastructure by Alex Gorbachev...
MOW2010: 1TB MySQL Database Migration and HA Infrastructure by Alex Gorbachev...
 
Best practices for MySQL High Availability
Best practices for MySQL High AvailabilityBest practices for MySQL High Availability
Best practices for MySQL High Availability
 
Using Capifony for Symfony apps deployment (updated)
Using Capifony for Symfony apps deployment (updated)Using Capifony for Symfony apps deployment (updated)
Using Capifony for Symfony apps deployment (updated)
 
Replication features, technologies and 3rd party Extinction
Replication features, technologies and 3rd party ExtinctionReplication features, technologies and 3rd party Extinction
Replication features, technologies and 3rd party Extinction
 
OSDC 2016 - Tuning Linux for your Database by Colin Charles
OSDC 2016 - Tuning Linux for your Database by Colin CharlesOSDC 2016 - Tuning Linux for your Database by Colin Charles
OSDC 2016 - Tuning Linux for your Database by Colin Charles
 

En vedette

A Part of RubyKaigi Ecosystem
A Part of RubyKaigi EcosystemA Part of RubyKaigi Ecosystem
A Part of RubyKaigi Ecosystembash0C7
 
IoTに活用!センサの基礎セミナー
IoTに活用!センサの基礎セミナーIoTに活用!センサの基礎セミナー
IoTに活用!センサの基礎セミナーshimane-itoc
 
「mruby/c」の利用期待分野~M2Mでの利用~160726
「mruby/c」の利用期待分野~M2Mでの利用~160726「mruby/c」の利用期待分野~M2Mでの利用~160726
「mruby/c」の利用期待分野~M2Mでの利用~160726shimane-itoc
 
M2M製品開発におけるmrubyの効果160726
M2M製品開発におけるmrubyの効果160726M2M製品開発におけるmrubyの効果160726
M2M製品開発におけるmrubyの効果160726shimane-itoc
 
Ruby For Java Programmers
Ruby For Java ProgrammersRuby For Java Programmers
Ruby For Java ProgrammersMike Bowler
 
mruby/c in TokyoRubyKaigi#11
mruby/c in TokyoRubyKaigi#11mruby/c in TokyoRubyKaigi#11
mruby/c in TokyoRubyKaigi#11Kazuaki Tanaka
 

En vedette (7)

A Part of RubyKaigi Ecosystem
A Part of RubyKaigi EcosystemA Part of RubyKaigi Ecosystem
A Part of RubyKaigi Ecosystem
 
IoTに活用!センサの基礎セミナー
IoTに活用!センサの基礎セミナーIoTに活用!センサの基礎セミナー
IoTに活用!センサの基礎セミナー
 
「mruby/c」の利用期待分野~M2Mでの利用~160726
「mruby/c」の利用期待分野~M2Mでの利用~160726「mruby/c」の利用期待分野~M2Mでの利用~160726
「mruby/c」の利用期待分野~M2Mでの利用~160726
 
M2M製品開発におけるmrubyの効果160726
M2M製品開発におけるmrubyの効果160726M2M製品開発におけるmrubyの効果160726
M2M製品開発におけるmrubyの効果160726
 
Ruby For Java Programmers
Ruby For Java ProgrammersRuby For Java Programmers
Ruby For Java Programmers
 
mruby/c in TokyoRubyKaigi#11
mruby/c in TokyoRubyKaigi#11mruby/c in TokyoRubyKaigi#11
mruby/c in TokyoRubyKaigi#11
 
Ruby everywhere
Ruby everywhereRuby everywhere
Ruby everywhere
 

Similaire à Experiences of stabilizing Rails site operations

Performance Benchmarking: Tips, Tricks, and Lessons Learned
Performance Benchmarking: Tips, Tricks, and Lessons LearnedPerformance Benchmarking: Tips, Tricks, and Lessons Learned
Performance Benchmarking: Tips, Tricks, and Lessons LearnedTim Callaghan
 
OrigoDB - take the red pill
OrigoDB - take the red pillOrigoDB - take the red pill
OrigoDB - take the red pillRobert Friberg
 
Play Framework and Activator
Play Framework and ActivatorPlay Framework and Activator
Play Framework and ActivatorKevin Webber
 
My Site is slow - Drupal Camp London 2013
My Site is slow - Drupal Camp London 2013My Site is slow - Drupal Camp London 2013
My Site is slow - Drupal Camp London 2013hernanibf
 
My site is slow
My site is slowMy site is slow
My site is slowhernanibf
 
Why Kubernetes as a container orchestrator is a right choice for running spar...
Why Kubernetes as a container orchestrator is a right choice for running spar...Why Kubernetes as a container orchestrator is a right choice for running spar...
Why Kubernetes as a container orchestrator is a right choice for running spar...DataWorks Summit
 
Achieving Infrastructure Portability with Chef
Achieving Infrastructure Portability with ChefAchieving Infrastructure Portability with Chef
Achieving Infrastructure Portability with ChefMatt Ray
 
The Architecture of PicCollage Server
The Architecture of PicCollage ServerThe Architecture of PicCollage Server
The Architecture of PicCollage ServerLin Jen-Shin
 
introduction to node.js
introduction to node.jsintroduction to node.js
introduction to node.jsorkaplan
 
Automating Complex Setups with Puppet
Automating Complex Setups with PuppetAutomating Complex Setups with Puppet
Automating Complex Setups with PuppetKris Buytaert
 
Server-Side JavaScript Developement - Node.JS Quick Tour
Server-Side JavaScript Developement - Node.JS Quick TourServer-Side JavaScript Developement - Node.JS Quick Tour
Server-Side JavaScript Developement - Node.JS Quick Tourq3boy
 
Running Airflow Workflows as ETL Processes on Hadoop
Running Airflow Workflows as ETL Processes on HadoopRunning Airflow Workflows as ETL Processes on Hadoop
Running Airflow Workflows as ETL Processes on Hadoopclairvoyantllc
 
Using Spring with NoSQL databases (SpringOne China 2012)
Using Spring with NoSQL databases (SpringOne China 2012)Using Spring with NoSQL databases (SpringOne China 2012)
Using Spring with NoSQL databases (SpringOne China 2012)Chris Richardson
 
John adams talk cloudy
John adams   talk cloudyJohn adams   talk cloudy
John adams talk cloudyJohn Adams
 
Performance Oriented Design
Performance Oriented DesignPerformance Oriented Design
Performance Oriented DesignRodrigo Campos
 
First Hive Meetup London 2012-07-10 - Tomas Cervenka - VisualDNA
First Hive Meetup London 2012-07-10 - Tomas Cervenka - VisualDNAFirst Hive Meetup London 2012-07-10 - Tomas Cervenka - VisualDNA
First Hive Meetup London 2012-07-10 - Tomas Cervenka - VisualDNATomas Cervenka
 
[DBA]_HiramFleitas_SQL_PASS_Summit_2017_Summary
[DBA]_HiramFleitas_SQL_PASS_Summit_2017_Summary[DBA]_HiramFleitas_SQL_PASS_Summit_2017_Summary
[DBA]_HiramFleitas_SQL_PASS_Summit_2017_SummaryHiram Fleitas León
 

Similaire à Experiences of stabilizing Rails site operations (20)

Performance Benchmarking: Tips, Tricks, and Lessons Learned
Performance Benchmarking: Tips, Tricks, and Lessons LearnedPerformance Benchmarking: Tips, Tricks, and Lessons Learned
Performance Benchmarking: Tips, Tricks, and Lessons Learned
 
OrigoDB - take the red pill
OrigoDB - take the red pillOrigoDB - take the red pill
OrigoDB - take the red pill
 
Play Framework and Activator
Play Framework and ActivatorPlay Framework and Activator
Play Framework and Activator
 
My Site is slow - Drupal Camp London 2013
My Site is slow - Drupal Camp London 2013My Site is slow - Drupal Camp London 2013
My Site is slow - Drupal Camp London 2013
 
My site is slow
My site is slowMy site is slow
My site is slow
 
Why Kubernetes as a container orchestrator is a right choice for running spar...
Why Kubernetes as a container orchestrator is a right choice for running spar...Why Kubernetes as a container orchestrator is a right choice for running spar...
Why Kubernetes as a container orchestrator is a right choice for running spar...
 
Achieving Infrastructure Portability with Chef
Achieving Infrastructure Portability with ChefAchieving Infrastructure Portability with Chef
Achieving Infrastructure Portability with Chef
 
Rails Performance
Rails PerformanceRails Performance
Rails Performance
 
Hosting Ruby Web Apps
Hosting Ruby Web AppsHosting Ruby Web Apps
Hosting Ruby Web Apps
 
The Architecture of PicCollage Server
The Architecture of PicCollage ServerThe Architecture of PicCollage Server
The Architecture of PicCollage Server
 
introduction to node.js
introduction to node.jsintroduction to node.js
introduction to node.js
 
Node azure
Node azureNode azure
Node azure
 
Automating Complex Setups with Puppet
Automating Complex Setups with PuppetAutomating Complex Setups with Puppet
Automating Complex Setups with Puppet
 
Server-Side JavaScript Developement - Node.JS Quick Tour
Server-Side JavaScript Developement - Node.JS Quick TourServer-Side JavaScript Developement - Node.JS Quick Tour
Server-Side JavaScript Developement - Node.JS Quick Tour
 
Running Airflow Workflows as ETL Processes on Hadoop
Running Airflow Workflows as ETL Processes on HadoopRunning Airflow Workflows as ETL Processes on Hadoop
Running Airflow Workflows as ETL Processes on Hadoop
 
Using Spring with NoSQL databases (SpringOne China 2012)
Using Spring with NoSQL databases (SpringOne China 2012)Using Spring with NoSQL databases (SpringOne China 2012)
Using Spring with NoSQL databases (SpringOne China 2012)
 
John adams talk cloudy
John adams   talk cloudyJohn adams   talk cloudy
John adams talk cloudy
 
Performance Oriented Design
Performance Oriented DesignPerformance Oriented Design
Performance Oriented Design
 
First Hive Meetup London 2012-07-10 - Tomas Cervenka - VisualDNA
First Hive Meetup London 2012-07-10 - Tomas Cervenka - VisualDNAFirst Hive Meetup London 2012-07-10 - Tomas Cervenka - VisualDNA
First Hive Meetup London 2012-07-10 - Tomas Cervenka - VisualDNA
 
[DBA]_HiramFleitas_SQL_PASS_Summit_2017_Summary
[DBA]_HiramFleitas_SQL_PASS_Summit_2017_Summary[DBA]_HiramFleitas_SQL_PASS_Summit_2017_Summary
[DBA]_HiramFleitas_SQL_PASS_Summit_2017_Summary
 

Plus de Hirotomo Oi

APIもDirect Hostingで配信してみた
APIもDirect Hostingで配信してみたAPIもDirect Hostingで配信してみた
APIもDirect Hostingで配信してみたHirotomo Oi
 
Jaws days ランキング1位の人気スマホアプリを カジュアル×セキュアに運用する
Jaws days ランキング1位の人気スマホアプリを カジュアル×セキュアに運用するJaws days ランキング1位の人気スマホアプリを カジュアル×セキュアに運用する
Jaws days ランキング1位の人気スマホアプリを カジュアル×セキュアに運用するHirotomo Oi
 
Ambrotypeにおける、Facebook連携方法
Ambrotypeにおける、Facebook連携方法Ambrotypeにおける、Facebook連携方法
Ambrotypeにおける、Facebook連携方法Hirotomo Oi
 
Ambrotype fb night20130222
Ambrotype fb night20130222Ambrotype fb night20130222
Ambrotype fb night20130222Hirotomo Oi
 
沢山のスマホサービス環境を カジュアルにセキュアに運用する
沢山のスマホサービス環境を カジュアルにセキュアに運用する沢山のスマホサービス環境を カジュアルにセキュアに運用する
沢山のスマホサービス環境を カジュアルにセキュアに運用するHirotomo Oi
 
Ambrotype/Reviocam CloudFront事例
Ambrotype/Reviocam CloudFront事例Ambrotype/Reviocam CloudFront事例
Ambrotype/Reviocam CloudFront事例Hirotomo Oi
 
Ambrotype on AWS
Ambrotype on AWSAmbrotype on AWS
Ambrotype on AWSHirotomo Oi
 

Plus de Hirotomo Oi (7)

APIもDirect Hostingで配信してみた
APIもDirect Hostingで配信してみたAPIもDirect Hostingで配信してみた
APIもDirect Hostingで配信してみた
 
Jaws days ランキング1位の人気スマホアプリを カジュアル×セキュアに運用する
Jaws days ランキング1位の人気スマホアプリを カジュアル×セキュアに運用するJaws days ランキング1位の人気スマホアプリを カジュアル×セキュアに運用する
Jaws days ランキング1位の人気スマホアプリを カジュアル×セキュアに運用する
 
Ambrotypeにおける、Facebook連携方法
Ambrotypeにおける、Facebook連携方法Ambrotypeにおける、Facebook連携方法
Ambrotypeにおける、Facebook連携方法
 
Ambrotype fb night20130222
Ambrotype fb night20130222Ambrotype fb night20130222
Ambrotype fb night20130222
 
沢山のスマホサービス環境を カジュアルにセキュアに運用する
沢山のスマホサービス環境を カジュアルにセキュアに運用する沢山のスマホサービス環境を カジュアルにセキュアに運用する
沢山のスマホサービス環境を カジュアルにセキュアに運用する
 
Ambrotype/Reviocam CloudFront事例
Ambrotype/Reviocam CloudFront事例Ambrotype/Reviocam CloudFront事例
Ambrotype/Reviocam CloudFront事例
 
Ambrotype on AWS
Ambrotype on AWSAmbrotype on AWS
Ambrotype on AWS
 

Experiences of stabilizing Rails site operations

  • 1. Experiences of Rails site stabilized operation Hirotomo Oi Chief Architect Media Technology Lab., Recruit Co.,Ltd.
  • 2. Agenda • Our “Rails” websites • Software • httpd • Server virtualization • Tips
  • 3. About Me • Hirotomo Ōi • Chief Architect of infrastructure of web. • And “engekilife.com” tech guy. • And...planning/developing new website.
  • 4. About MTL • MTL(Media Technology Lab.) is an applied study institute to promote future media communication, and to seek for a sympathetic world for all of us. • One of our focus: Develop prototype web sites, and verify responses and feedbacks through beta releases.
  • 6. MTL Websites
  • 7. MTL Websites
  • 8. Software • Httpd for Ruby Apps. • Virtualization
  • 9. Rails Version • Use various versions. • 1.2.x, 2.0.x, 2.1.x, 2.2.x, 2.3,x... • We choose the newest version at launch time of each site.
  • 10. httpd • ...Donʼt fix, now trying... • Mongrel • Thin • Passenger • Some sites were changed from Mongrel.
  • 11. Benchmark Time per request(ms): 31.00 23.25 15.50 7.75 0 Mongrel Passenger
  • 12. Ruby Version • 1.8.6 • If apps didnʼt work, use another vers. • Ruby Enterprise Edition • for Passenger
  • 15. Virtualize servers • Two or more servers can be running on one Web, hardware. App DB cache (memory- (CPU- (IO-bound) bound) • Generally, different bound) resources are put together is good efficiency.
  • 16. virtualize webservers • We are virtualizing web+app tier. • Generally web site A (ruby) site B (php) site C (perl) apps are CPU- bound. • RoR apps need memory.
  • 17. How many VMs? • Hardware • 16GB memory • 2x Quad Core Xeon • VM Spec • 1GB memory • 10GB disk space • 8 CPU cores available
  • 18. How many VMs? • Hardware • 16GB memory • 2x Quad Core Xeon • VM Spec 13 • 1GB memory VMs / Hard • 10GB disk space • 8 CPU cores available
  • 20. How many instances? • 10 Mongrel instances / 1GB mem VM. • 24 Mongrel instances / 2GB mem VM
  • 21. Tips • DB Tuning • Log rotation • Restart Mongrel
  • 22. DB Tuning • Developers often forget DB tuning when launch the site. • Developers use ActiveRecord, not connect DB directly.
  • 23. DB Tuning • Developers often forget DB tuning when launch the site. • Developers use ActiveRecord, not connect DB directly. DO NOT FORGET DATABASE!!
  • 24. Get Slow Query Log • Step 1: know slow query. • my.cnf [mysqld] log-slow-queries long_query_time=1
  • 25. EXPLAIN • Step 2: Analysis of slow query • Use “EXPLAIN” mysql> EXPLAIN SELECT...Your Slow Query;
  • 26. EXPLAIN • Step 2: Analysis of slow query • Use “EXPLAIN” mysql> EXPLAIN SELECT...Your Slow Query;
  • 27. Fix Slow Query • Add Index • Examine to change (ex:divide) the query • Donʼt use join... • Donʼt use subquery...
  • 28. ex) mysql> show create table rubykaigi_demo G | rubykaigi_demo | CREATE TABLE `rubykaigi_demo` ( `id` int(11) NOT NULL auto_increment, `type` varchar(255) default NULL, `bukken_id` int(11) default NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 |
  • 29. 1) Know Slow Query mysql> SELECT * FROM `rubykaigi_demo` WHERE `type` = 'PlayguideTicketInfoShow' and `bukken_id` = 435; +-------+-------------------------+-----------+ | id | type | bukken_id | +-------+-------------------------+-----------+ | 13139 | PlayguideTicketInfoShow | 435 | +-------+-------------------------+-----------+ 1 row in set (0.01 sec)
  • 30. 2) EXPLAIN mysql> EXPLAIN SELECT * FROM `rubykaigi_demo` WHERE `type` = 'PlayguideTicketInfoShow' and `bukken_id` = 435G id: 1 select_type: SIMPLE table: rubykaigi_demo type: ALL possible_keys: NULL key: NULL key_len: NULL ref: NULL rows: 2299 Extra: Using where
  • 31. 2) EXPLAIN mysql> EXPLAIN SELECT * FROM `rubykaigi_demo` WHERE `type` = 'PlayguideTicketInfoShow' and `bukken_id` = 435G id: 1 select_type: SIMPLE table: rubykaigi_demo type: ALL possible_keys: NULL key: NULL key_len: NULL ref: NULL Not Using Index rows: 2299 Extra: Using where
  • 32. 3) ADD INDEX mysql> ALTER TABLE `rubykaigi_demo` ADD INDEX( `type`, `bukken_id`); Query OK, 1977 rows affected (0.18 sec) Records: 1977 Duplicates: 0 Warnings: 0 or migration: add_index "type_bukken", ["type", "bukken_id"], :name => "type_bukken"
  • 33. 4) RESULT mysql> EXPLAIN SELECT * FROM `rubykaigi_demo` WHERE `type` = 'PlayguideTicketInfoShow' and `bukken_id` = 435G id: 1 select_type: SIMPLE table: rubykaigi_demo type: ref possible_keys: type key: type key_len: 773 ref: const,const rows: 1 Extra: Using where; Using index
  • 34. 4) RESULT mysql> EXPLAIN SELECT * FROM `rubykaigi_demo` WHERE `type` = 'PlayguideTicketInfoShow' and `bukken_id` = 435G id: 1 select_type: SIMPLE table: rubykaigi_demo type: ref possible_keys: type key: type key_len: 773 ref: const,const Using Index rows: 1 Extra: Using where; Using index
  • 35. Log rotation • “production.log” increase continuously. • Itʼs necessary to rotate logs. ex) logrotate.d conf file (Your Rails App Log Dir)/*.log { daily missingok rotate 30 compress notifempty copytruncate create 0644 user group }
  • 36. Log rotation • “production.log” increase continuously. • Itʼs necessary to rotate logs. ex) logrotate.d conf file (Your Rails App Log Dir)/*.log { daily missingok rotate 30 compress notifempty copytruncate Important! create 0644 user group }
  • 37. Restart Mongrel • Restart periodically for fix memory leak of Mongrel processes. • Using swap, not only the VM but all VMs on same HW are slow down...
  • 38. Restart Mongrel • Cron • Logrotate.d • Monit
  • 39. Agenda • Our “Rails” websites • Softwares • httpd, virtualization,... • Tips • Donʼt forget DB Tuning • Donʼt forget log rotation • Restart Mongrel
  • 41. Comming Soon!! http://mashupaward.jp/
  • 42. Thank you Please contact : http://mtl.recruit.co.jp/