Difference between pages "Package:Varnish" and "Package:Ruby"

(Difference between pages)
(add apache benchmarking)
 
(add puma section, remove warnings, fix console spacings, add categories, adjust links to reflect ruby rather than rubygems since the gems article got railroaded to ruby some how)
 
Line 1: Line 1:
 
{{Ebuild
 
{{Ebuild
|Summary=Varnish is a state-of-the-art, high-performance HTTP accelerator
+
|Summary=Centralized Ruby extension management system
|CatPkg=www-servers/varnish
+
|CatPkg=dev-ruby/ruby
 
|Maintainer=
 
|Maintainer=
 +
|Homepage=https://www.ruby-lang.org
 
}}
 
}}
__TOC__
 
'''Varnish''' is a webcache & http accelerator.  Varnish will either serve cached content, or retireve content from the server, and cache it.  Varnish will reduce I/O pressure from webservers.
 
  
==Install==
+
Ruby is a programming language with its own package management system to extend the language.
===Emerge===
+
  
Install {{Package|www-servers/varnish}}
+
Rubygems is a package management system to extend the ruby language.
<console>###i## www-servers/varnish</console>
+
  
==Configuration==
+
Gems are packaged wonky in portage so this page will explain how to work with rubygems rather than fight it.  Arch wiki outlines a similar method. 
  
Configuration is controlled by /etc/varnish/default.vcl & /etc/conf.d/varnishd
+
https://wiki.archlinux.org/index.php/Ruby#RubyGems
  
{{file|name=/etc/varnish/default.vcl|desc=varnish configuration file|body=
+
Emerge ruby & rubygems:
vcl 4.0;
+
<console>###i## emerge ruby rubygems</console>
backend default {
+
    .host = "127.0.0.1";
+
    .port = "8080";
+
}
+
}}
+
  
{{file|name=/etc/conf.d/varnishd|desc=varnish configuration file|body=
+
Remove conflicting gems:
VARNISHD="/usr/sbin/varnishd"
+
<console>###i## emerge -C dev-ruby/rake dev-ruby/racc dev-ruby/json dev-ruby/rdoc</console>
VARNISHADM="/usr/bin/varnishadm"
+
CONFIGFILE="/etc/varnish/default.vcl"
+
VARNISHD_OPTS="-a 127.0.0.1:80"
+
VARNISHD_OPTS="${VARNISHD_OPTS} -u varnish -g varnish"
+
}}
+
  
Varnish will fetch data from localhost:8080 and serve accelerated proxy data on localhost:80
+
Flush conflicting gems bad specs:
 +
<console>###i## mv /usr/local/lib64/ruby/gems/2.1.0/specifications/ /usr/local/lib64/ruby/gems/2.1.0/specifications.backup</console>
  
== BootService ==
 
  
To start varnish immediately:
+
Fetch gems via rubygems:
<console>###i## rc-service varnishd start</console>
+
<console>###i## gem install rdoc json rake racc</console>
  
To start varnish at boot:
+
<console>###i## rubygems-update</console>
<console>###i## rc-update add varnishd default</console>
+
  
== Verification ==
+
update gem system:
To verify that your traffic is going through varnish.
+
<console>###i## update_rubygems
<console>$##i## curl -I https://www.varnish-cache.org/</console>
+
###i## gem update --system
 +
###i## gem pristine --all
 +
</console>
  
== Benchmarking ==
+
Now you're ready to use gem to manage gems.
If your system has apache installed apache benchmark can show the power of varnish.  The examples shown are running 500 requests with concurrency of 100 hits.
+
  
 +
To add gems to your path:
 +
{{file|name=$HOME/.bashrc|desc=add gem bin directory to your path|body=
 +
PATH="$(ruby -rubygems -e 'puts Gem.user_dir')/bin:$PATH"
 +
}}
  
ab against a 3 worker cluster mode puma server
+
==ruby on rails==
<console>###i## ab -n 500 -c 100 http://127.0.0.1:3000/index.html | grep Request</console>
+
<console>###i## gem install rails
Requests per second:    110.92 [#/sec] (mean)
+
###i## rails new testproject
 +
###i## cd testproject
 +
###i## bundle install</console>
  
 +
==puma==
 +
puma is a fast web server for ruby on rails.
 +
 +
To enable puma in your project:
 +
{{file|name=$HOME/testproject/Gemfile|desc=add puma gem to your rails application|body=
 +
gem 'puma'
 +
}}
 +
 +
To pull in puma:
 +
<console>###i## bundle install</console>
 +
 +
{{file|name=$HOME/testproject/config/puma.rb|desc=puma configuration file|body=
 +
<pre>workers Integer(ENV['PUMA_WORKERS'] || 3)
 +
threads Integer(ENV['MIN_THREADS']  || 1), Integer(ENV['MAX_THREADS'] || 16)
 +
 +
preload_app!
 +
 +
rackup      DefaultRackup
 +
port        ENV['PORT']    || 3000
 +
environment ENV['RACK_ENV'] || 'development'
 +
 +
on_worker_boot do
 +
  # worker specific setup
 +
  ActiveSupport.on_load(:active_record) do
 +
    config = ActiveRecord::Base.configurations[Rails.env] ||
 +
                Rails.application.config.database_configuration[Rails.env]
 +
    config['pool'] = ENV['MAX_THREADS'] || 16
 +
    ActiveRecord::Base.establish_connection(config)
 +
  end
 +
end</pre>
 +
}}
  
ab against the same server served through varnish
+
to start puma:
<console>###i## ab -n 500 -c 100 http://127.0.0.1/index.html | grep Request</console>
+
<console>###i## bundle exec puma</console>
Requests per second:    10268.42 [#/sec] (mean)
+
or if you added gems bin dir to your path
 +
<console>###i## puma</console>
  
[[Category:Server]]
+
[[Category:Programming language]]
[[Category:Daemons]]
+
  
 
{{EbuildFooter}}
 
{{EbuildFooter}}

Revision as of 19:44, 23 August 2014

dev-ruby/ruby


Source Repository:Gentoo Portage Tree
Homepage

Summary: Centralized Ruby extension management system


Ruby

Ruby is a programming language with its own package management system to extend the language.

Rubygems is a package management system to extend the ruby language.

Gems are packaged wonky in portage so this page will explain how to work with rubygems rather than fight it. Arch wiki outlines a similar method.

https://wiki.archlinux.org/index.php/Ruby#RubyGems

Emerge ruby & rubygems:

# emerge ruby rubygems

Remove conflicting gems:

# emerge -C dev-ruby/rake dev-ruby/racc dev-ruby/json dev-ruby/rdoc

Flush conflicting gems bad specs:

# mv /usr/local/lib64/ruby/gems/2.1.0/specifications/ /usr/local/lib64/ruby/gems/2.1.0/specifications.backup


Fetch gems via rubygems:

# gem install rdoc json rake racc
# rubygems-update

update gem system:

# update_rubygems
# gem update --system
# gem pristine --all

Now you're ready to use gem to manage gems.

To add gems to your path:

$HOME/.bashrc: add gem bin directory to your path
PATH="$(ruby -rubygems -e 'puts Gem.user_dir')/bin:$PATH"

ruby on rails

# gem install rails
# rails new testproject
# cd testproject
# bundle install

puma

puma is a fast web server for ruby on rails.

To enable puma in your project:

$HOME/testproject/Gemfile: add puma gem to your rails application
gem 'puma'

To pull in puma:

# bundle install
$HOME/testproject/config/puma.rb: puma configuration file
workers Integer(ENV['PUMA_WORKERS'] || 3)
threads Integer(ENV['MIN_THREADS']  || 1), Integer(ENV['MAX_THREADS'] || 16)

preload_app!

rackup      DefaultRackup
port        ENV['PORT']     || 3000
environment ENV['RACK_ENV'] || 'development'

on_worker_boot do
  # worker specific setup
  ActiveSupport.on_load(:active_record) do
    config = ActiveRecord::Base.configurations[Rails.env] ||
                Rails.application.config.database_configuration[Rails.env]
    config['pool'] = ENV['MAX_THREADS'] || 16
    ActiveRecord::Base.establish_connection(config)
  end
end

to start puma:

# bundle exec puma

or if you added gems bin dir to your path

# puma