helion-prime
home about us blogs contacts

Posts Tagged ‘RoR’

Tuning of Postgresql under OpenBSD

Thursday, February 25th, 2010

Preamble

I assume that you already made your best with help of your favorite programming language
and recommended postgresql performance tips: http://www.postgresql.org/docs/8.4/static/performance-tips.html

Postgresql resources

No doubt that standard postgresql configuration is far from modern production environments.
Therefore you need to spend enough time with following sources.

1. resource consumption documentation:
http://www.postgresql.org/docs/8.4/static/runtime-config-resource.html

The most important parameters are:
work_mem (integer)
shared_buffers (integer)

2. Query Planning documentation:
http://www.postgresql.org/docs/current/static/runtime-config-query.html

The most important parameters are:
effective_cache_size (integer)
random_page_cost (floating point)

OpenBSD resources

The default sizes in the GENERIC kernel are insignificant also and waiting for your tuning as well.
Posgtresql doesn’t start without enough memory size so always know when you need to increase kern.shminfo.shmmax.

Setting that we can change in /etc/sysctl.conf
the maximum number of System V IPC system-wide semaphore sets (and identifiers) which can exist at any given time:
kern.seminfo.semmni

the maximum total individual System V IPC semaphores which can be assigned by applications:
kern.seminfo.semmns

the amount of shared memory available in the system (bytes):
kern.shminfo.shmmax

the maximum number of shared memory segments:
sysctl kern.shminfo.shmseg

Full list of setting you can see with:
# man sysctl

OpenBSD kernel parameters
So, there are set of parameters that can be tuned only with kernel rebuild.

You should tune them only if system works unstable with default values and you have:
kernel warnings: “uvm_mapent_alloc: out of static map entries”
or panics like: “panic: malloc: out of space in kmem_map”

NKMEMPAGES
This option defines number of pages in kernel kmem_map structure.

MAX_KMAPENT
It defines number of static entries in kernel kmem_map (kernel virtual memory).

They can be changed in:
/usr/src/sys/arch/conf/GENERIC

As start you need to recheck ‘Building the System from Source’ part of OpenBSD documentation:
http://openbsd.org/faq/faq5.htm

Usually administrators select these parameters using set of tests on dedicated testing box where
they emulate load of production servers.

Example

our test server: 1x Intel Quad core CPU, 2GB RAM
software: Ruby on Rails application, postgresql DB, memcached.
load: about 15.000 users/day, peak load: 10 users/sec.

postgresql_dir/data/postgresql.conf

1
2
3
4
5
6
7
8
9
# RESOURCE USAGE
shared_buffers = 738MB
max_prepared_transactions = 30
work_mem = 16MB
max_fsm_pages = 2000000

# QUERY TUNING
effective_cache_size = 512MB
random_page_cost = 1.7

/etc/sysctl.conf

1
2
3
kern.seminfo.semmni = 256
kern.seminfo.semmns = 2048
kern.shminfo.shmmax = 805306368    # Shared memory segment size is 768M

/usr/src/sys/arch/conf/GENERIC

1
2
3
## custom settings
option MAX_KMAPENT = 3072
option NKMEMPAGES = 32768

Log rotation in Ruby on Rails applications

Thursday, November 19th, 2009

preamble

Even on mid-size applications logs grow enormously fast, it’s a pity Rails doesn’t provide built-in functionality for that like Apache web-server does. Fortunately there is an easy and fast solution for that issue.

1. Install cronolog

“cronolog [http://cronolog.org/] is a simple filter program that reads log file entries from standard input and writes each entry to the output file specified by a filename template and the current date and time.”

For details, and list of parameters see: [http://cronolog.org/usage.html]

On GNU/Linux Debian:

# apt-get install cronolog

2. Setup your Rails application

Edit necessary environment file: like ‘config/environments/production.rb’ file

1
2
3
4
5
# system logger configuration
# config.logger = SyslogLogger.new

config.logger = Logger.new(IO.popen("FULL_PATH_TO_CRONOLOG log/production.log.%Y%m%d", "w"))
config.logger.level = Logger::INFO

That’s all, fast and easy .. Enjoy!

RubyConf2008 conference

Tuesday, January 6th, 2009

If you are real Ruby follower you surely know about RubyConf2008 conference that was held in November 2008, or perhaps you even participated. If you still miss all the fun you can go thru whole list of videos from that conference on [http://rubyconf2008.confreaks.com/].

Or at least you can watch videos I’ve selected for busiest men:


name: Reasons behind Ruby
duration: 31 minutes
description: introductory speech from Yukihiro Matsumoto, father of Ruby where he speaks about Ruby, its future, and community in general without any technical stuff.
URL: [http://rubyconf2008.confreaks.com/matzs-keynote.html]


name: Fork Ruby
duration: 48 minutes
description: speech from Dave Thomas that helped write Agile Manifesto, and Programming Ruby: A Pragmatic Programmer’s Guide. He share thoughts about possible ideas for Ruby language and its development.
URL: [http://rubyconf2008.confreaks.com/keynote.html]


name: Ruby 1.9: What to Expect
duration: 50 minutes
description: Dave Thomas and David Black author of popular book Ruby for Rails, Ruby core contributor and the creator and maintainer of RCRchive show to us differences between Rubys with 2 irb windows step by step.
URL: [http://rubyconf2008.confreaks.com/ruby-19-what-to-expect.html]


name: Recovering from Enterprise
duration: 45 minutes
description: Comparison between Ruby and Java worlds from Ruby, and Ruby on Rails contributer Jamis Buck. He describe fundamental differences between Java and Ruby and his mistakes, and ways to avoid them. Also provide ideas how to write in real Ruby and not in Java with Ruby syntax.
URL: [http://rubyconf2008.confreaks.com/recovering-from-enterprise.html]





Next conference will be held on 13-14 March of 2009 in Salt Lake City.
See details on official site: [http://mtnwestrubyconf.org/]


©2010 Helion-Prime Solutions Ltd.
Custom Software Development Agile Company.