<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Helion-Prime Solutions blog &#187; ruby</title>
	<atom:link href="http://blogs.helion-prime.com/category/general-programming/ruby/feed" rel="self" type="application/rss+xml" />
	<link>http://blogs.helion-prime.com</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Mon, 10 May 2010 17:51:32 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Deployment of Ruby on Rails applications on OpenBSD</title>
		<link>http://blogs.helion-prime.com/2010/04/05/deployment-of-ruby-on-rails-applications-on-openbsd.html</link>
		<comments>http://blogs.helion-prime.com/2010/04/05/deployment-of-ruby-on-rails-applications-on-openbsd.html#comments</comments>
		<pubDate>Mon, 05 Apr 2010 12:35:56 +0000</pubDate>
		<dc:creator>alex.shapovalov</dc:creator>
				<category><![CDATA[openBSD]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[RoR]]></category>

		<guid isPermaLink="false">http://blogs.helion-prime.com/?p=768</guid>
		<description><![CDATA[Preamble
In this post I will define typical production environment on OpenBSD OS for deployment of Ruby on Rails applications.
There are few common things:
1. The Ruby on Rails framework doesn&#8217;t  support concurrent running in multiple threads within the same process, and so to scale it and fully utilize available hardware we need to execute application [...]]]></description>
			<content:encoded><![CDATA[<h2>Preamble</h2>
<p>In this post I will define typical production environment on OpenBSD OS for deployment of Ruby on Rails applications.</p>
<p>There are few common things:<br />
1. The Ruby on Rails framework doesn&#8217;t  support concurrent running in multiple threads within the same process, and so to scale it and fully utilize available hardware we need to execute application in several processes.<br />
2. We need load-balancer to spread incoming requests between application instances.<br />
3. We need separate web-server to serve static content.</p>
<h2>Overall configuration</h2>
<p>At first all incoming HTTP requests from a clients come to httpd web-server, it servers all static content, and send other requests to HAProxy.<br />
HAProxy receives requests and selects free Thin instance, forwards the request to it, receives a response and passes it back to httpd.</p>
<p>Following diagram should give you basic understanding about common work of components :<br />
<img class="alignnone size-full wp-image-779" title="deployment diagram" src="http://blogs.helion-prime.com/wp-content/uploads/2010/03/deployment_diagram.png" alt="deployment diagram" width="465" height="502" /></p>
<h2>OpenBSD Httpd – standard OpenBSD web-server</h2>
<p>I suggest OpenBSD standard web-server as you can find it as part of OpenBSD base installation, it checked for security issues and being updated as part of OpenBSD. We will use it to serve static content and don&#8217;t bother our Thin servers.</p>
<p>file: httpd.conf</p>
<div class="codecolorer-container apache mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br /></div></td><td><div class="apache codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #00007f;">BindAddress</span> SERVER_IP_ADDRESS<br />
<br />
<span style="color: #adadad; font-style: italic;"># Dynamic Shared Object (DSO) Support</span><br />
<span style="color: #adadad; font-style: italic;"># caching proxy</span><br />
<span style="color: #00007f;">LoadModule</span> proxy_module /usr/lib/apache/modules/libproxy.so<br />
<br />
<span style="color: #adadad; font-style: italic;"># allow Symbolic Links for root of our static content and all sub-directories</span><br />
<br />
<span style="color: #00007f;">Options</span> +<span style="color: #0000ff;">FollowSymLinks</span><br />
<span style="color: #00007f;">ServerAdmin</span> ADMIN_EMAIL<br />
<br />
<span style="color: #adadad; font-style: italic;"># path to root of our static content</span><br />
<span style="color: #00007f;">DocumentRoot</span> /var/www/railsdocs/RAILS_PROJECT/public<br />
<span style="color: #00007f;">ServerName</span> SERVER_NAME<br />
<span style="color: #00007f;">ServerAlias</span> www.SERVER_NAME<br />
<br />
<span style="color: #adadad; font-style: italic;"># directories that contain static content (they excluded from dispatching to HAProxy)</span><br />
<span style="color: #00007f;">ProxyPass</span> /images !<br />
<span style="color: #00007f;">ProxyPass</span> /stylesheets !<br />
<span style="color: #00007f;">ProxyPass</span> /javascripts !<br />
<span style="color: #00007f;">ProxyPass</span> /<span style="color: #ff0000;">500</span>.html !<br />
<span style="color: #00007f;">ProxyPass</span> /<span style="color: #ff0000;">503</span>.html !<br />
<br />
<span style="color: #adadad; font-style: italic;"># address where to send and from receive requests (HAProxy listens that address)</span><br />
<span style="color: #00007f;">ProxyPass</span> / http://127.0.0.1:<span style="color: #ff0000;">4000</span>/<br />
<span style="color: #00007f;">ProxyPassReverse</span> / http://127.0.0.1:<span style="color: #ff0000;">4000</span>/<br />
<br />
<span style="color: #adadad; font-style: italic;"># Disallows remote servers to be mapped into the space of the local server.</span><br />
<span style="color: #00007f;">ProxyRequests</span> <span style="color: #0000ff;">Off</span><br />
<br />
<span style="color: #adadad; font-style: italic;"># Don't use incoming Host HTTP request header for proxy request.</span><br />
<span style="color: #00007f;">ProxyPreserveHost</span> <span style="color: #0000ff;">Off</span><br />
<br />
<span style="color: #00007f;">ErrorLog</span> logs/SERVER_NAME-error_log<br />
<span style="color: #00007f;">CustomLog</span> logs/SERVER_NAME-access_log common</div></td></tr></tbody></table></div>
<p>see for configuration details: man httpd</p>
<p><strong>For OpenBSD 4.6/4.6 -Stable</strong><br />
It&#8217;s the hard part, OpenBSD4.6 has a bug in mod_proxy module so &#8216;!&#8217; directive doesn&#8217;t work.<br />
You have to edit following file:  /usr/src/usr.sbin/httpd/src/modules/proxy/mod_proxy.c</p>
<p>Find method: static int proxy_trans(request_rec *r)<br />
in that method after condition: if (len &gt; 0) {<br />
add 2 string:</p>
<div class="codecolorer-container c mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br /></div></td><td><div class="c codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>ent<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #202020;">real</span><span style="color: #009900;">&#91;</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #ff0000;">'!'</span> <span style="color: #339933;">&amp;&amp;</span> ent<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #202020;">real</span><span style="color: #009900;">&#91;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #ff0000;">'<span style="color: #006699; font-weight: bold;">\0</span>'</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #b1b100;">return</span> DECLINED<span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p>so final part of code:<br />
&#8230;</p>
<div class="codecolorer-container c mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br /></div></td><td><div class="c codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>len <span style="color: #339933;">&gt;</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>ent<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #202020;">real</span><span style="color: #009900;">&#91;</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #ff0000;">'!'</span> <span style="color: #339933;">&amp;&amp;</span> ent<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #202020;">real</span><span style="color: #009900;">&#91;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #ff0000;">'<span style="color: #006699; font-weight: bold;">\0</span>'</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #b1b100;">return</span> DECLINED<span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p>&#8230;</p>
<p>Then recompile your system, it&#8217;s common procedure for following -stable so you should already know it otherwise see for details for building instructions: <a href="http://www.openbsd.org/faq/faq5.html">http://www.openbsd.org/faq/faq5.html</a></p>
<h2>Thin – high performance ruby web server</h2>
<p>We need some Ruby web-server, and it seems that at this time Thin provides best performance.<br />
At least we see such results on Thin homepage: <a href="http://code.macournoyer.com/thin/">http://code.macournoyer.com/thin/</a></p>
<p>file: start.sh</p>
<div class="codecolorer-container bash mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br /></div></td><td><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666; font-style: italic;"># start work instances</span><br />
thin start <span style="color: #660033;">-C</span> thin-production.yml</div></td></tr></tbody></table></div>
<p>file: thin-production.yml</p>
<div class="codecolorer-container yaml mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br /></div></td><td><div class="yaml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">---<br />
<span style="">environment</span>: production<br />
<br />
<span style="">port</span>: <span style="">4001</span><br />
<span style="">address</span>: 127.0.0.1<br />
<span style="">daemonize</span>: true<br />
<span style="">servers</span>: <span style="">4</span><br />
<br />
<span style="">chdir</span>: /var/www/railsdocs/RAILS_PROJECT<br />
<span style="">pid</span>: tmp/pids/thin.pid<br />
<span style="">log</span>: log/thin.log<br />
<br />
<span style="">user</span>: myuser<br />
<span style="">group</span>: mygroup<br />
<br />
<span style="">require</span>: <span class="br0">&#91;</span><span class="br0">&#93;</span></div></td></tr></tbody></table></div>
<p>see for configuration details: <a href="http://code.macournoyer.com/thin/usage/">http://code.macournoyer.com/thin/usage/</a></p>
<h2>HAproxy &#8211; TCP/ HTTP load balancer</h2>
<p>As Rails doesn&#8217;t  support concurrent running each incoming request should be assigned to a separate process. HAProxy can be configured to send only one request at a time to every Thin server, it will always pick instance that is not busy with something.</p>
<p>It provides bunch of other useful things like:<br />
– route HTTP requests depending on statically assigned cookies ;<br />
– switch to backup servers in the event a main one fails ;<br />
– accept connections to special ports dedicated to service monitoring ;<br />
– add/modify/delete HTTP headers both ways ;<br />
– block requests matching a particular pattern ;<br />
for full documentation see: <a href="http://haproxy.1wt.eu/#docs">http://haproxy.1wt.eu/#docs</a></p>
<p>note:<br />
If someone thinks that we could use nginx for that purpose check following performance comparison of HAProxy and Nginx:<br />
<a href="http://affectioncode.wordpress.com/2008/06/28/another-comparison-of-haproxy-and-nginx/">http://affectioncode.wordpress.com/2008/06/28/another-comparison-of-haproxy-and-nginx/</a></p>
<p>file: haproxy.cfg</p>
<div class="codecolorer-container bash mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br /></div></td><td><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">defaults<br />
log &nbsp; &nbsp; global<br />
mode &nbsp; &nbsp;http<br />
<br />
<span style="color: #666666; font-style: italic;"># provides more detailed information about HTTP contents, such as the request and some cookies</span><br />
option &nbsp;httplog<br />
<span style="color: #666666; font-style: italic;"># do not to log any session which didn't transfer any data</span><br />
option &nbsp;dontlognull<br />
<span style="color: #666666; font-style: italic;"># allow the proxy to break their persistence and redistribute connections in case of failure</span><br />
option &nbsp;redispatch<br />
<br />
<span style="color: #666666; font-style: italic;"># the number of attempts to reconnect after a connection failure to a server</span><br />
retries <span style="color: #000000;">3</span><br />
<br />
<span style="color: #666666; font-style: italic;"># the time we accept to wait for a connection to establish on a server</span><br />
contimeout &nbsp; &nbsp; &nbsp;<span style="color: #000000;">100000</span><br />
<span style="color: #666666; font-style: italic;"># the time we accept to wait for data from the client, or for the client to accept data</span><br />
clitimeout &nbsp; &nbsp; &nbsp;<span style="color: #000000;">100000</span><br />
<span style="color: #666666; font-style: italic;"># the time we accept to wait for data from the server, or for the server to accept data</span><br />
srvtimeout &nbsp; &nbsp; &nbsp;<span style="color: #000000;">100000</span><br />
<br />
listen project_proxy 127.0.0.1:<span style="color: #000000;">4000</span><br />
balance roundrobin<br />
<br />
<span style="color: #666666; font-style: italic;"># creates an HTTP 'X-Forwarded-For' header which contains the client's IP address.</span><br />
<span style="color: #666666; font-style: italic;"># This is useful to let the final web server know what the client address was</span><br />
option forwardfor<br />
<br />
<span style="color: #666666; font-style: italic;"># using “maxconn 1″ improves performance with Rails.</span><br />
<span style="color: #666666; font-style: italic;"># As Rails instance can process only 1 request “maxconn 1″ force HAProxy to select next free instance</span><br />
<br />
server &nbsp;app1_1 127.0.0.1:<span style="color: #000000;">4001</span> check inter <span style="color: #000000;">60000</span> rise <span style="color: #000000;">2</span> fall <span style="color: #000000;">5</span> maxconn <span style="color: #000000;">1</span><br />
server &nbsp;app1_2 127.0.0.1:<span style="color: #000000;">4002</span> check inter <span style="color: #000000;">60000</span> rise <span style="color: #000000;">2</span> fall <span style="color: #000000;">5</span> maxconn <span style="color: #000000;">1</span><br />
server &nbsp;app1_3 127.0.0.1:<span style="color: #000000;">4003</span> check inter <span style="color: #000000;">60000</span> rise <span style="color: #000000;">2</span> fall <span style="color: #000000;">5</span> maxconn <span style="color: #000000;">1</span><br />
server &nbsp;app1_4 127.0.0.1:<span style="color: #000000;">4004</span> check inter <span style="color: #000000;">60000</span> rise <span style="color: #000000;">2</span> fall <span style="color: #000000;">5</span> maxconn <span style="color: #000000;">1</span><br />
<br />
<span style="color: #666666; font-style: italic;"># httpd web-server will handle it in case of 503, 504 errors due to it's static content</span><br />
errorloc &nbsp; &nbsp;<span style="color: #000000;">503</span> &nbsp;http:<span style="color: #000000; font-weight: bold;">//</span>DOMAIN_NAME<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">503</span>.html<br />
errorloc &nbsp; &nbsp;<span style="color: #000000;">504</span> &nbsp;http:<span style="color: #000000; font-weight: bold;">//</span>DOMAIN_NAME<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">504</span>.html<br />
<br />
<span style="color: #666666; font-style: italic;"># statistics page thru http://127.0.0.1:8080</span><br />
listen stats 127.0.0.1:<span style="color: #000000;">8080</span><br />
balance roundrobin<br />
mode http<br />
stats uri &nbsp; <span style="color: #000000; font-weight: bold;">/</span></div></td></tr></tbody></table></div>
<p>see for configuration details: <a href="http://haproxy.1wt.eu/#docs">http://haproxy.1wt.eu/#docs</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.helion-prime.com/2010/04/05/deployment-of-ruby-on-rails-applications-on-openbsd.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Tuning of Postgresql under OpenBSD</title>
		<link>http://blogs.helion-prime.com/2010/02/25/tuning-of-postgresql-under-openbsd.html</link>
		<comments>http://blogs.helion-prime.com/2010/02/25/tuning-of-postgresql-under-openbsd.html#comments</comments>
		<pubDate>Thu, 25 Feb 2010 15:04:00 +0000</pubDate>
		<dc:creator>alex.shapovalov</dc:creator>
				<category><![CDATA[openBSD]]></category>
		<category><![CDATA[rdbms]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[postgresql]]></category>
		<category><![CDATA[RoR]]></category>

		<guid isPermaLink="false">http://blogs.helion-prime.com/?p=664</guid>
		<description><![CDATA[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 [...]]]></description>
			<content:encoded><![CDATA[<h2>Preamble</h2>
<p>I assume that you already made your best with help of your favorite programming language<br />
and recommended postgresql performance tips: <a href="http://www.postgresql.org/docs/8.4/static/performance-tips.html">http://www.postgresql.org/docs/8.4/static/performance-tips.html</a></p>
<h2>Postgresql resources</h2>
<p>No doubt that standard postgresql configuration is far from modern production environments.<br />
Therefore you need to spend enough time with following sources.</p>
<p><strong>1. resource consumption documentation:</strong><br />
<a href="http://www.postgresql.org/docs/8.4/static/runtime-config-resource.html">http://www.postgresql.org/docs/8.4/static/runtime-config-resource.html</a></p>
<p>The most important parameters are:<br />
work_mem (integer)<br />
shared_buffers (integer)</p>
<p><strong>2. Query Planning documentation:</strong><br />
<a href="http://www.postgresql.org/docs/current/static/runtime-config-query.html">http://www.postgresql.org/docs/current/static/runtime-config-query.html</a></p>
<p>The most important parameters are:<br />
effective_cache_size (integer)<br />
random_page_cost (floating point)</p>
<h2>OpenBSD resources</h2>
<p>The default sizes in the GENERIC kernel are insignificant also and waiting for your tuning as well.<br />
Posgtresql doesn&#8217;t start without enough memory size so always know when you need to increase kern.shminfo.shmmax.</p>
<p><strong>Setting that we can change in /etc/sysctl.conf</strong><br />
the maximum number of System V IPC system-wide semaphore sets (and identifiers) which can exist at any given time:<br />
kern.seminfo.semmni</p>
<p>the maximum total individual System V IPC semaphores which can be assigned by applications:<br />
kern.seminfo.semmns</p>
<p>the amount of shared memory available in the system (bytes):<br />
kern.shminfo.shmmax</p>
<p>the maximum number of shared memory segments:<br />
sysctl kern.shminfo.shmseg</p>
<p>Full list of setting you can see with:<br />
# man sysctl</p>
<p><strong>OpenBSD kernel parameters</strong><br />
So, there are set of parameters that can be tuned only with kernel rebuild. </p>
<p>You should tune them only if system works unstable with default values and you have:<br />
kernel warnings: “uvm_mapent_alloc: out of static map entries”<br />
or panics like:  “panic: malloc: out of space in kmem_map”</p>
<p>NKMEMPAGES<br />
This option defines number of pages in kernel kmem_map structure.</p>
<p>MAX_KMAPENT<br />
It defines number of static entries in kernel kmem_map (kernel virtual memory).</p>
<p>They can be changed in:<br />
/usr/src/sys/arch/conf/GENERIC</p>
<p>As start you need to recheck  &#8216;Building the System from Source&#8217; part of OpenBSD documentation:<br />
<a href="http://openbsd.org/faq/faq5.htm">http://openbsd.org/faq/faq5.htm</a></p>
<p>Usually administrators select these parameters using set of tests on dedicated testing box where<br />
 they emulate load of  production servers.</p>
<h2>Example</h2>
<p>our test server: 1x Intel Quad core CPU, 2GB RAM<br />
software: Ruby on Rails application, postgresql DB, memcached.<br />
load: about 15.000 users/day, peak load: 10 users/sec.</p>
<p>postgresql_dir/data/postgresql.conf</p>
<div class="codecolorer-container bash mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br /></div></td><td><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666; font-style: italic;"># RESOURCE USAGE</span><br />
shared_buffers = 738MB<br />
max_prepared_transactions = <span style="color: #000000;">30</span><br />
work_mem = 16MB<br />
max_fsm_pages = <span style="color: #000000;">2000000</span><br />
<br />
<span style="color: #666666; font-style: italic;"># QUERY TUNING</span><br />
effective_cache_size = 512MB<br />
random_page_cost = <span style="color: #000000;">1.7</span></div></td></tr></tbody></table></div>
<p>/etc/sysctl.conf</p>
<div class="codecolorer-container bash mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br /></div></td><td><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">kern.seminfo.semmni = <span style="color: #000000;">256</span><br />
kern.seminfo.semmns = <span style="color: #000000;">2048</span><br />
kern.shminfo.shmmax = <span style="color: #000000;">805306368</span> &nbsp; &nbsp;<span style="color: #666666; font-style: italic;"># Shared memory segment size is 768M</span></div></td></tr></tbody></table></div>
<p>/usr/src/sys/arch/conf/GENERIC</p>
<div class="codecolorer-container bash mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br /></div></td><td><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666; font-style: italic;">## custom settings</span><br />
option MAX_KMAPENT = <span style="color: #000000;">3072</span><br />
option NKMEMPAGES = <span style="color: #000000;">32768</span></div></td></tr></tbody></table></div>
]]></content:encoded>
			<wfw:commentRss>http://blogs.helion-prime.com/2010/02/25/tuning-of-postgresql-under-openbsd.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Log rotation in Ruby on Rails applications</title>
		<link>http://blogs.helion-prime.com/2009/11/19/log-rotation-in-ruby-on-rails-applications.html</link>
		<comments>http://blogs.helion-prime.com/2009/11/19/log-rotation-in-ruby-on-rails-applications.html#comments</comments>
		<pubDate>Thu, 19 Nov 2009 12:30:04 +0000</pubDate>
		<dc:creator>alex.shapovalov</dc:creator>
				<category><![CDATA[ruby]]></category>
		<category><![CDATA[web-development]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[RoR]]></category>

		<guid isPermaLink="false">http://blogs.helion-prime.com/?p=623</guid>
		<description><![CDATA[preamble
Even on mid-size applications logs grow enormously fast, it&#8217;s a pity Rails doesn&#8217;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 [...]]]></description>
			<content:encoded><![CDATA[<h2>preamble</h2>
<p>Even on mid-size applications logs grow enormously fast, it&#8217;s a pity Rails doesn&#8217;t provide built-in functionality for that like Apache web-server does. Fortunately there is an easy and fast solution for that issue.</p>
<h2>1. Install cronolog</h2>
<p>“cronolog [<a href="http://cronolog.org/">http://cronolog.org/</a>] 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.”</p>
<p>For details, and list of parameters see: [<a href="http://cronolog.org/usage.html">http://cronolog.org/usage.html</a>]</p>
<p>On GNU/Linux Debian:</p>
<pre># apt-get install cronolog</pre>
<h2>2. Setup your Rails application</h2>
<p>Edit necessary environment file: like &#8216;config/environments/production.rb&#8217; file</p>
<div class="codecolorer-container ruby mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color:#008000; font-style:italic;"># system logger configuration</span><br />
<span style="color:#008000; font-style:italic;"># config.logger = SyslogLogger.new</span><br />
<br />
config.<span style="color:#9900CC;">logger</span> = <span style="color:#CC00FF; font-weight:bold;">Logger</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC00FF; font-weight:bold;">IO</span>.<span style="color:#9900CC;">popen</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;FULL_PATH_TO_CRONOLOG log/production.log.%Y%m%d&quot;</span>, <span style="color:#996600;">&quot;w&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
config.<span style="color:#9900CC;">logger</span>.<span style="color:#9900CC;">level</span> = <span style="color:#CC00FF; font-weight:bold;">Logger</span>::INFO</div></td></tr></tbody></table></div>
<p>That&#8217;s all, fast and easy .. Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.helion-prime.com/2009/11/19/log-rotation-in-ruby-on-rails-applications.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Easy image scaling for RoR developers</title>
		<link>http://blogs.helion-prime.com/2009/11/02/easy-image-scaling-for-ror-developers.html</link>
		<comments>http://blogs.helion-prime.com/2009/11/02/easy-image-scaling-for-ror-developers.html#comments</comments>
		<pubDate>Mon, 02 Nov 2009 16:21:40 +0000</pubDate>
		<dc:creator>alex.shapovalov</dc:creator>
				<category><![CDATA[ruby]]></category>
		<category><![CDATA[web-development]]></category>

		<guid isPermaLink="false">http://blogs.helion-prime.com/?p=588</guid>
		<description><![CDATA[We have common task: image scaling [http://en.wikipedia.org/wiki/Image_scaling], and correct understanding that: we can&#8217;t ask users to provide image of appropriate sizes, just use width and height CSS parameters for images, and thumbnail is always required feature.
Luckily we have ImageMagic library [http://www.imagemagick.org] and program interfaces for popular languages.
install RMagic gem
# gem install rmagick
add small code:
123456789101112131415161718192021222324252627282930require 'rubygems'
require [...]]]></description>
			<content:encoded><![CDATA[<p>We have common task: image scaling [<a href="http://en.wikipedia.org/wiki/Image_scaling">http://en.wikipedia.org/wiki/Image_scaling</a>], and correct understanding that: we can&#8217;t ask users to provide image of appropriate sizes, just use width and height CSS parameters for images, and thumbnail is always required feature.</p>
<p>Luckily we have ImageMagic library [<a href="http://www.imagemagick.org">http://www.imagemagick.org</a>] and program interfaces for popular languages.</p>
<p>install RMagic gem<br />
# gem install rmagick</p>
<p>add small code:</p>
<div class="codecolorer-container ruby mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'rubygems'</span><br />
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'RMagick'</span><br />
<br />
<span style="color:#9966CC; font-weight:bold;">class</span> ImageController <span style="color:#006600; font-weight:bold;">&lt;</span> ApplicationController<br />
<br />
<span style="color:#9966CC; font-weight:bold;">def</span> index<br />
<br />
&nbsp; <span style="color:#008000; font-style:italic;"># determine basic params</span><br />
&nbsp; w = params<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:w</span><span style="color:#006600; font-weight:bold;">&#93;</span><br />
&nbsp; h = params<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:h</span><span style="color:#006600; font-weight:bold;">&#93;</span><br />
&nbsp; path = params<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:path</span><span style="color:#006600; font-weight:bold;">&#93;</span><br />
<br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">if</span> !w.<span style="color:#9900CC;">to_s</span>.<span style="color:#9900CC;">empty</span>? <span style="color:#006600; font-weight:bold;">&amp;&amp;</span> !h.<span style="color:#9900CC;">to_s</span>.<span style="color:#9900CC;">empty</span>? <span style="color:#006600; font-weight:bold;">&amp;&amp;</span> <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">exists</span>?<span style="color:#006600; font-weight:bold;">&#40;</span>path<span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">begin</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; image = <span style="color:#6666ff; font-weight:bold;">Magick::Image</span>.<span style="color:#9900CC;">read</span><span style="color:#006600; font-weight:bold;">&#40;</span>path<span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">first</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; transformed_image = image.<span style="color:#9900CC;">resize_to_fill</span><span style="color:#006600; font-weight:bold;">&#40;</span>w.<span style="color:#9900CC;">to_i</span>, h.<span style="color:#9900CC;">to_i</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># send image</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; send_data<span style="color:#006600; font-weight:bold;">&#40;</span>transformed_image.<span style="color:#9900CC;">to_blob</span>, <span style="color:#ff3333; font-weight:bold;">:disposition</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'inline'</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color:#ff3333; font-weight:bold;">:type</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;image/#{image.format.downcase}&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
<br />
&nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">rescue</span> <span style="color:#CC00FF; font-weight:bold;">Exception</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> e<br />
&nbsp; &nbsp; &nbsp; &nbsp; Rails.<span style="color:#9900CC;">logger</span>.<span style="color:#9900CC;">error</span> e.<span style="color:#9900CC;">message</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; Rails.<span style="color:#9900CC;">logger</span>.<span style="color:#9900CC;">error</span> e.<span style="color:#9900CC;">backtrace</span>.<span style="color:#9900CC;">join</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;<span style="color:#000099;">\n</span>&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; render <span style="color:#ff3333; font-weight:bold;">:text</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;Error processing image #{type}/#{aliaz}&quot;</span>, <span style="color:#ff3333; font-weight:bold;">:code</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">404</span>, <span style="color:#ff3333; font-weight:bold;">:layout</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">false</span><br />
&nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
<span style="color:#9966CC; font-weight:bold;">end</span></div></td></tr></tbody></table></div>
<p>Here to re-size images we use &#8216;resize_to_fill&#8217; ImageMagic method:<br />
re-size the image to fit within the specified dimensions while retaining the aspect ratio of the original image, and if necessary, crop the image in the larger dimension.</p>
<p>Sure you understand that resizing takes time and so you should cache re-sized images.</p>
<p>For additional info look thru:<br />
[<a href="http://studio.imagemagick.org/RMagick/doc/">http://studio.imagemagick.org/RMagick/doc/</a>]</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.helion-prime.com/2009/11/02/easy-image-scaling-for-ror-developers.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Multi-domain applications in Ruby on Rails</title>
		<link>http://blogs.helion-prime.com/2009/09/03/multi-domain-applications-in-ruby-on-rails.html</link>
		<comments>http://blogs.helion-prime.com/2009/09/03/multi-domain-applications-in-ruby-on-rails.html#comments</comments>
		<pubDate>Thu, 03 Sep 2009 14:34:58 +0000</pubDate>
		<dc:creator>alex.shapovalov</dc:creator>
				<category><![CDATA[internet]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[web-development]]></category>

		<guid isPermaLink="false">http://blogs.helion-prime.com/?p=566</guid>
		<description><![CDATA[preamble
Ruby on Rails is a great framework that still luck some common features, among them: multi-domain support.
Here I will describe fast solution that doesn&#8217;t work for every browser and another one that do the work.
Ok, you did your homework and google something like &#8216;ruby on rails multi-domain&#8217;.
Very often provided solution:
edit environment.rb
1config.action_controller.session = &#123;:domain =&#62; '.mydomain.com'&#125;
With [...]]]></description>
			<content:encoded><![CDATA[<h2>preamble</h2>
<p>Ruby on Rails is a great framework that still luck some common features, among them: multi-domain support.<br />
Here I will describe fast solution that doesn&#8217;t work for every browser and another one that do the work.</p>
<p>Ok, you did your homework and google something like &#8216;ruby on rails multi-domain&#8217;.<br />
Very often provided solution:</p>
<p>edit environment.rb</p>
<div class="codecolorer-container ruby mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">config.<span style="color:#9900CC;">action_controller</span>.<span style="color:#9900CC;">session</span> = <span style="color:#006600; font-weight:bold;">&#123;</span>:domain <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'.mydomain.com'</span><span style="color:#006600; font-weight:bold;">&#125;</span></div></td></tr></tbody></table></div>
<p>With that parameter Rails always read cookies from same domain. In real some browsers forbid for applications to read cookies from other domain due to insecurity of that operation. And as Mozilla Firefox in set of browsers that forbid that we just need another solution.</p>
<p>Now it&#8217;s clear that we should implement necessary functionality other way. </p>
<h2>Here we go:</h2>
<h3>1. will store session ID in the database(by default Rails2 store it in cookies)</h3>
<p>environment.rb:</p>
<div class="codecolorer-container ruby mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">config.<span style="color:#9900CC;">action_controller</span>.<span style="color:#9900CC;">session_store</span> = <span style="color:#ff3333; font-weight:bold;">:active_record_store</span></div></td></tr></tbody></table></div>
<p>and then execute rake task that create necessary DB migration:</p>
<div class="codecolorer-container ruby mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">rake db:sessions:create</div></td></tr></tbody></table></div>
<p>Apply it with:  rake db:migrate.</p>
<h3>2. setup session parameters</h3>
<p>environment.rb:</p>
<div class="codecolorer-container ruby mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">&quot;rubygems&quot;</span><br />
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">&quot;active_support&quot;</span><br />
<br />
config.<span style="color:#9900CC;">action_controller</span>.<span style="color:#9900CC;">session</span> = <span style="color:#006600; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp;<span style="color:#ff3333; font-weight:bold;">:session_key</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'_myapp_session_id'</span>, &nbsp; &nbsp;<span style="color:#008000; font-style:italic;"># session identification key</span><br />
&nbsp; &nbsp;<span style="color:#ff3333; font-weight:bold;">:secret</span> &nbsp; &nbsp; &nbsp;<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'89sHslddfsd98klasdKd'</span>, <span style="color:#008000; font-style:italic;"># hash code of session generator(make it random and longer)</span><br />
&nbsp; &nbsp;<span style="color:#ff3333; font-weight:bold;">:cookie_only</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">false</span>,<br />
&nbsp; &nbsp;<span style="color:#ff3333; font-weight:bold;">:expire_after</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">1</span>.<span style="color:#9900CC;">week</span>, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color:#008000; font-style:italic;"># TTL (time to live)</span><br />
<span style="color:#006600; font-weight:bold;">&#125;</span></div></td></tr></tbody></table></div>
<h3>3. let&#8217;s create session creation handler</h3>
<p>application_controller.rb:</p>
<div class="codecolorer-container ruby mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">before_filter <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#006600; font-weight:bold;">|</span>controller<span style="color:#006600; font-weight:bold;">|</span><br />
&nbsp; &nbsp;opts = controller.<span style="color:#9900CC;">request</span>.<span style="color:#9900CC;">session_options</span><br />
&nbsp; &nbsp;key = opts<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:key</span><span style="color:#006600; font-weight:bold;">&#93;</span><br />
<br />
&nbsp; &nbsp;<span style="color:#008000; font-style:italic;"># use session ID if it's passed</span><br />
&nbsp; &nbsp;<span style="color:#9966CC; font-weight:bold;">if</span> controller.<span style="color:#9900CC;">params</span><span style="color:#006600; font-weight:bold;">&#91;</span>key<span style="color:#006600; font-weight:bold;">&#93;</span>&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># session initialization with old ID</span><br />
&nbsp; &nbsp; &nbsp; controller.<span style="color:#9900CC;">session</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:nothing</span><span style="color:#006600; font-weight:bold;">&#93;</span><br />
<br />
&nbsp; &nbsp; &nbsp; opts<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:id</span><span style="color:#006600; font-weight:bold;">&#93;</span> = controller.<span style="color:#9900CC;">params</span><span style="color:#006600; font-weight:bold;">&#91;</span>key<span style="color:#006600; font-weight:bold;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; controller.<span style="color:#9900CC;">request</span>.<span style="color:#9900CC;">session_options</span> = opts<br />
&nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># session initialization with new ID</span><br />
&nbsp; &nbsp; &nbsp; controller.<span style="color:#9900CC;">session</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:nothing</span><span style="color:#006600; font-weight:bold;">&#93;</span><br />
&nbsp; &nbsp;<span style="color:#9966CC; font-weight:bold;">end</span><br />
<span style="color:#006600; font-weight:bold;">&#125;</span></div></td></tr></tbody></table></div>
<h3>4. session pass</h3>
<p>We need to pass session ID as parameter when user change domain name, and within domain we still use cookie.</p>
<div class="codecolorer-container text mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">“#{request.session_options[:key]}” =&gt; request.session_options[:id]</div></td></tr></tbody></table></div>
<p>It&#8217;s wise to use session initialization before request.session_options[:id]  invocation due to Rails use lazy loading, and session can be uninitialized.<br />
Use something like: session[:nothing].</p>
<p>Pay attention that information that Rails get from cookie has bigger priority, and so if you have some parameter  in cookie Rails will use it firstly.</p>
<p><b>Note:</b><br />
An attacker can still steal you session ID by sniffing the network, or exploiting javascript, he/she gets the value from the cookie itself. If you care about security so much just use HTTPS.</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.helion-prime.com/2009/09/03/multi-domain-applications-in-ruby-on-rails.html/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
