<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Helicon Tech Blog</title>
	
	<link>http://www.helicontech.com/articles</link>
	<description>Web Server Enhancements</description>
	<lastBuildDate>Thu, 05 Jan 2012 13:23:40 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/HeliconTechBlog" /><feedburner:info uri="helicontechblog" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>Installing OSQA on Windows in production</title>
		<link>http://feedproxy.google.com/~r/HeliconTechBlog/~3/ArZLRSGGs6E/</link>
		<comments>http://www.helicontech.com/articles/installing-osqa-on-windows-in-production/#comments</comments>
		<pubDate>Thu, 05 Jan 2012 13:23:00 +0000</pubDate>
		<dc:creator>Slov</dc:creator>
				<category><![CDATA[Helicon Zoo]]></category>
		<category><![CDATA[CodeProject]]></category>

		<guid isPermaLink="false">http://www.helicontech.com/articles/?p=711</guid>
		<description><![CDATA[This is a very simple step by step guide to install OSQA on Windows server in production. This guide is applicable to IIS 7+ based servers, which include Windows Server 2008, 2008 R2, Windows Vista and Windows 7. Latter two &#8230; <a href="http://www.helicontech.com/articles/installing-osqa-on-windows-in-production/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>This is a very simple step by step guide to install OSQA on Windows server in production. This guide is applicable to IIS 7+ based servers, which include Windows Server 2008, 2008 R2, Windows Vista and Windows 7. Latter two should not be used for production solutions though. Please follow these steps:<span id="more-711"></span></p>
<h3>1. Download <a href="http://www.microsoft.com/web/downloads/platform.aspx">Microsoft Web Platform Installer</a>, and install it.</h3>
<h3 id="">2. Run Web Platform Installer and click “Options”.</h3>
<p>&nbsp;</p>
<p><img class="alignnone size-full wp-image-713" title="01-webpi" src="http://www.helicontech.com/articles/wp-content/uploads/2012/01/01-webpi.png" alt="" width="698" height="363" /></p>
<h3>3. Add Helicon Zoo feed into “Display additional scenarios” field: <a href="http://www.helicontech.com/zoo/feed">http://www.helicontech.com/zoo/feed</a> Select “IIS” as a target web server.</h3>
<p>&nbsp;</p>
<p><img class="alignnone size-full wp-image-714" title="02-webpi-options" src="http://www.helicontech.com/articles/wp-content/uploads/2012/01/02-webpi-options.png" alt="" width="700" height="500" /></p>
<p>&nbsp;</p>
<p>A new tab named “Zoo” should appear on the main page of Platform Installer.</p>
<h3>4. Go to Zoo → Applications and add OSQA, then click install.</h3>
<p>&nbsp;</p>
<p><img class="alignnone size-full wp-image-715" title="03-webpi-zoo-apps-osqa" src="http://www.helicontech.com/articles/wp-content/uploads/2012/01/03-webpi-zoo-apps-osqa.png" alt="" width="698" height="606" /></p>
<p>&nbsp;</p>
<h3>5. Accept license agreements</h3>
<p>&nbsp;</p>
<p><img class="alignnone size-full wp-image-716" title="04-webpi-accept" src="http://www.helicontech.com/articles/wp-content/uploads/2012/01/04-webpi-accept.png" alt="" width="700" height="582" /></p>
<p>&nbsp;</p>
<p>Web Paltfrom Installer will start downloading and installing required components, which include Python 2.7.2, Django 1.3, Helicon Zoo Module, MySQL and OSQA itself.</p>
<p>&nbsp;</p>
<p><img class="alignnone size-full wp-image-717" title="05-webpi-downloading" src="http://www.helicontech.com/articles/wp-content/uploads/2012/01/05-webpi-downloading.png" alt="" width="700" height="480" /></p>
<p>&nbsp;</p>
<h3>6.  Setup new web-site dialog will appear. Fill it with your site specific values.</h3>
<p>&nbsp;</p>
<p><img class="alignnone size-full wp-image-718" title="06-webpi-new-site" src="http://www.helicontech.com/articles/wp-content/uploads/2012/01/06-webpi-new-site.png" alt="" width="700" height="500" /></p>
<p>&nbsp;</p>
<h3>7.  Database dialog will open. Fill it to create new or use existing MySQL database.</h3>
<p>&nbsp;</p>
<p><img class="alignnone size-full wp-image-719" title="07-webpi-install-options" src="http://www.helicontech.com/articles/wp-content/uploads/2012/01/07-webpi-install-options.png" alt="" width="700" height="983" /></p>
<p>&nbsp;</p>
<p>Default administrator user name for MySQL is &#8216;root&#8217; and default password is empty.</p>
<p>Installation will configure database and run migration scripts, you can now launch web site by clicking on a link:</p>
<p>&nbsp;</p>
<p><img class="alignnone size-full wp-image-720" title="08-webpi-osqa-installed" src="http://www.helicontech.com/articles/wp-content/uploads/2012/01/08-webpi-osqa-installed.png" alt="" width="700" height="480" /></p>
<p>&nbsp;</p>
<p>Congratulations! You have finished installation and may start using OSQA on your Windows server with Microsoft IIS in production:</p>
<p>&nbsp;</p>
<p><img class="alignnone size-full wp-image-712" title="09-osqa-initial-page" src="http://www.helicontech.com/articles/wp-content/uploads/2012/01/09-osqa-initial-page.png" alt="" width="1057" height="778" /></p>
<img src="http://feeds.feedburner.com/~r/HeliconTechBlog/~4/ArZLRSGGs6E" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.helicontech.com/articles/installing-osqa-on-windows-in-production/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.helicontech.com/articles/installing-osqa-on-windows-in-production/</feedburner:origLink></item>
		<item>
		<title>Installing Redmine on Windows in production</title>
		<link>http://feedproxy.google.com/~r/HeliconTechBlog/~3/Q1M1pVDj3wg/</link>
		<comments>http://www.helicontech.com/articles/installing-redmine-on-windows-in-production/#comments</comments>
		<pubDate>Tue, 03 Jan 2012 15:33:30 +0000</pubDate>
		<dc:creator>Slov</dc:creator>
				<category><![CDATA[Helicon Zoo]]></category>
		<category><![CDATA[CodeProject]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[zoo]]></category>

		<guid isPermaLink="false">http://www.helicontech.com/articles/?p=693</guid>
		<description><![CDATA[This is a very simple step by step guide to install Redmine on Windows server in production. This guide is applicable to IIS 7+ based servers, which include Windows Server 2008, 2008 R2, Windows Vista and Windows 7. Latter two &#8230; <a href="http://www.helicontech.com/articles/installing-redmine-on-windows-in-production/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>This is a very simple step by step guide to install Redmine on Windows server in production. This guide is applicable to IIS 7+ based servers, which include Windows Server 2008, 2008 R2, Windows Vista and Windows 7. Latter two should not be used for production solutions. Please follow these steps:<span id="more-693"></span></p>
<h3>1. Download <a href="http://www.microsoft.com/web/downloads/platform.aspx">Microsoft Web Platform Installer</a>, and install it.</h3>
<h3>2. Run Web Platform Installer and click “Options”.</h3>
<p>&nbsp;</p>
<p><img class="alignnone size-full wp-image-698" title="click-options" src="http://www.helicontech.com/articles/wp-content/uploads/2012/01/click-options.png" alt="" width="695" height="499" /></p>
<p>&nbsp;</p>
<h3>3. Add Helicon Zoo feed into &#8220;Display additional scenarios&#8221; field: <a href="http://www.helicontech.com/zoo/feed">http://www.helicontech.com/zoo/feed</a> Select &#8220;IIS&#8221; as a target web server.</h3>
<p>&nbsp;</p>
<p><img class="alignnone size-full wp-image-697" title="add-feed" src="http://www.helicontech.com/articles/wp-content/uploads/2012/01/add-feed.png" alt="" width="700" height="480" /></p>
<p>&nbsp;</p>
<p>A new tab named &#8220;Zoo&#8221; should appear on the main page of Platform Installer.</p>
<h3>4. Go to Zoo → Applications and add Redmine, then click install.</h3>
<p>&nbsp;</p>
<p><img class="alignnone size-full wp-image-699" title="install-redmine" src="http://www.helicontech.com/articles/wp-content/uploads/2012/01/install-redmine.png" alt="" width="695" height="622" /></p>
<p>&nbsp;</p>
<p>This will automatically download and install all required components, including Ruby 1.8.7, Rails 2.3, Helicon Zoo Module and Redmine itself.</p>
<h3>5. Setup new web-site dialog will appear. Fill it with your server specific values.</h3>
<p>&nbsp;</p>
<p><img class="alignnone size-full wp-image-696" title="site-setup" src="http://www.helicontech.com/articles/wp-content/uploads/2012/01/site-setup.png" alt="" width="700" height="508" /></p>
<p>&nbsp;</p>
<h3>6. Go to the /admin/ folder on this web-site. Use login “admin” and password “admin” to enter Redmine Administration panel.</h3>
<p>&nbsp;</p>
<p><img class="alignnone size-full wp-image-700" title="redmine-administration" src="http://www.helicontech.com/articles/wp-content/uploads/2012/01/redmine-administration.png" alt="" width="943" height="576" /></p>
<h2>Custom database</h2>
<p>Redmine supports multiple database engines. By default SQLite is installed, however there are example configuration files for MySQL and PostgreSQL within “config” folder of Redmine application. If you wish to use MySQL, for an instance, take “database.yml.mysql” file; name it as “database.yml” and alter according to your MySQL database settings. Then restart IIS application which contains your Redmine application. All required database migrations will be executed automatically by deploy.rb script.</p>
<p>That&#8217;s it, enjoy!</p>
<p>&nbsp;</p>
<img src="http://feeds.feedburner.com/~r/HeliconTechBlog/~4/Q1M1pVDj3wg" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.helicontech.com/articles/installing-redmine-on-windows-in-production/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://www.helicontech.com/articles/installing-redmine-on-windows-in-production/</feedburner:origLink></item>
		<item>
		<title>Node.js on Windows (with performance tests)</title>
		<link>http://feedproxy.google.com/~r/HeliconTechBlog/~3/2GOhieD1LNc/</link>
		<comments>http://www.helicontech.com/articles/node-js-on-windows-with-performance-tests/#comments</comments>
		<pubDate>Tue, 06 Dec 2011 15:10:15 +0000</pubDate>
		<dc:creator>Slov</dc:creator>
				<category><![CDATA[Helicon Zoo]]></category>
		<category><![CDATA[CodeProject]]></category>
		<category><![CDATA[node.js]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[zoo]]></category>

		<guid isPermaLink="false">http://www.helicontech.com/articles/?p=609</guid>
		<description><![CDATA[In this article we are going to address basic question which might occur in minds of green web-programmers and those who is going to dive into Node.js learning, namely: how to install Node.js developer environment of your PC; how to &#8230; <a href="http://www.helicontech.com/articles/node-js-on-windows-with-performance-tests/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><img class="alignnone size-full wp-image-626" title="node_plus_win" src="http://www.helicontech.com/articles/wp-content/uploads/2011/11/node_plus_win.png" alt="" width="750" height="170" /></p>
<p>In this article we are going to address basic question which might occur in minds of green web-programmers and those who is going to dive into Node.js learning, namely:</p>
<ul>
<li>how to install Node.js developer environment of your PC;</li>
<li>how to code;</li>
<li>how to debug;</li>
<li>how to deploy what you’ve done on remote server.</li>
</ul>
<p>And the performance tests at the end of the article will try answer a reasonable question “Why would I need to learn Node.js.”<br />
So, let’s start&#8230;<br />
<span id="more-609"></span></p>
<p>Node.js is an event-oriented Javascript-based framework for development of web applications. The core concept is that nothing gets blocked during code execution &#8211; operations waiting for data transfer, data input, connection establishment or anything else are not present. Everything is based on events, which occur at the moment synchronous operations are waiting for. This sometimes leads to dramatic—dozens of times—performance boost in comparison with old sync systems. With the release of version 0.6.0 of November 2011 Node.js assembly for Windows in announced stable.</p>
<h2 dir="ltr">Installing working environment</h2>
<p>To begin it’s necessary to <a href="http://www.microsoft.com/web/downloads/platform.aspx">download and install Web Platform Installer</a>, run it, click Options and put Helicon Zoo Feed link <a href="http://www.helicontech.com/zoo/feed/">http://www.helicontech.com/zoo/feed/</a> into “Display additional scenarios” field:</p>
<p>&nbsp;</p>
<p><img class="alignnone size-full wp-image-622" title="image08" src="http://www.helicontech.com/articles/wp-content/uploads/2011/11/image08.png" alt="" width="550" height="377" /></p>
<p>&nbsp;</p>
<p>This adds Zoo tab in Web Platform Installer:</p>
<p>&nbsp;</p>
<p><img class="alignnone size-full wp-image-623" title="image09" src="http://www.helicontech.com/articles/wp-content/uploads/2011/11/image09.png" alt="" width="500" height="381" /></p>
<p>&nbsp;</p>
<h3>Installing Node.js</h3>
<p>Under <span style="text-decoration: underline;">Zoo -&gt; Engines</span> there’s a list of all available web engines, including Node.js. However, we recommend opting for Node.js Package which incorporates not only Node.js itself but also several highly useful modules. So, got to <span style="text-decoration: underline;">Zoo -&gt; Packages -&gt; Node.js Hosting Package</span> and do Add, Install.</p>
<p>&nbsp;</p>
<p><img class="alignnone size-full wp-image-625" title="image11" src="http://www.helicontech.com/articles/wp-content/uploads/2011/11/image11.png" alt="" width="500" height="282" /></p>
<p>&nbsp;</p>
<p>To see all currently supported web frameworks and applications visit <a href="http://www.helicontech.com/zoo/gallery/">Helicon Zoo Gallery</a>. After you agree to the license agreements, it starts downloading and installing IIS (if not yet there), Helicon Zoo Module and node.exe for Windows.</p>
<p>An important system component is Node Package Manager (npm) used for installation of additional modules. Starting from version 0.6.5 of Node.js Node Package Manager declared stable and now is included into Node.js Hosting Package.</p>
<h3>Installing WebMatrix templates</h3>
<p>Now Node.js is installed and to start doing applications for it it’s reasonable to use WebMatrix templates. These templates simplify creation of blank draft apps which might be used for further development.<br />
To install them follow: <span style="text-decoration: underline;">Zoo -&gt; Packages -&gt; WebMatrix Templates</span></p>
<p>&nbsp;</p>
<p><img class="alignnone size-full wp-image-624" title="image10" src="http://www.helicontech.com/articles/wp-content/uploads/2011/11/image10.png" alt="" width="500" height="271" /></p>
<p>&nbsp;</p>
<p>If you don’t have WebMatrix &#8211; not to worry &#8211; it will be downloaded and installed automatically together with installation of templates. After the installation run WebMatrix and choose «Site from Template»:</p>
<p>&nbsp;</p>
<p><img class="alignnone size-full wp-image-617" title="image03" src="http://www.helicontech.com/articles/wp-content/uploads/2011/11/image03.png" alt="" width="500" height="422" /></p>
<p>&nbsp;</p>
<p>As you can see, Node.js is not the only framework favoring from WebMatrix templates.</p>
<p>If you follow the URL of the newly created Node.js Site or press Run, you get common «Hello, World!» page.</p>
<p>&nbsp;</p>
<p><img class="alignnone size-full wp-image-618" title="image04" src="http://www.helicontech.com/articles/wp-content/uploads/2011/11/image04.png" alt="" width="600" height="239" /></p>
<p>&nbsp;</p>
<p>By default the new site includes <a href="http://expressjs.com/">framework express</a> for easy web-apps creation. The framework and its dependencies reside in node_modules folder under the site root which is good for deployment of the app on remote server.</p>
<p>The folder &#8220;<em>public</em>&#8221; is used to store static files. Any file put into this folder will be processed directly by IIS as static, not evoking Node.js. This is especially important to avoid accidental execution of client *.js files on the server.</p>
<p><em>web.config</em> file contains URL Rewrite rules for static content. Initially every request is checked against the content of public folder (i.e. whether it’s static). This is beneficial for some web apps which mix static and dynamic resources in one folder (often root). If your app is not doing so, you can delete Microsoft URL Rewrite rules from web.config and refer to static files by explicitly specifying public folder.</p>
<p>Additionally, web.config includes configuration directives required for launch of Node.js and Helicon Zoo Module on that site.</p>
<h2>Composing the first app</h2>
<p>One of the advantages of Node.js is that JavaScript is a popular language widely used in web development. It means you won’t have problems choosing the editor. Free WebMatrix editor is ok to start with.</p>
<p>To illustrate capabilities of asynchronous web frameworks most write a chat. So, the most known demo-app for Node.js is a chat <a href="http://chat.nodejs.org/">http://chat.nodejs.org/</a>, its <a href="http://github.com/ry/node_chat/tree/master">source code is available</a> for examination.</p>
<p>We’ve also decided to make a chat &#8211; very primitive one &#8211; with no users, no sessions, no scrolls and message editing. It can only transmit asynchronous messages to show how long-polling works.</p>
<p>We’ll make use of previously-created Node.js Site. We need to edit server.js and index.html.</p>
<p>&nbsp;</p>
<p><img class="alignnone size-full wp-image-619" title="image05" src="http://www.helicontech.com/articles/wp-content/uploads/2011/11/image05.png" alt="" width="700" height="632" /></p>
<p>&nbsp;</p>
<p>Here’s the source code for server.js:</p>
<pre><code>var express = require('express');
var callbacks = [];

// Sends messages to clients
function appendMessage(message){
  var resp = {messages: [message]};
  while (callbacks.length &gt; 0) {
    callbacks.shift()(resp);
  }
}

// Creation of express server
var app = module.exports = express.createServer();
app.use(express.bodyParser());

// Simply respond with index.html
app.get('/', function(req, res){
    res.sendfile('index.html');
});

// Process messages from client
app.post('/send', function(req, res){
  var message = {
    nickname: req.param('nickname', 'Anonymous'),
    text: req.param('text', '')
  };
  appendMessage(message);
  res.json({status: 'ok'});
});

// Wait for new messages
app.get('/recv', function(req, res){
  callbacks.push(function(message){
    res.json(message);
  });
});

// Listen to the port
app.listen(process.env.PORT);</code></pre>
<p>and index.html</p>
<pre><code>&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Node.js Zoo Chat&lt;/title&gt;
&lt;script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6/jquery.min.js" type="text/javascript"&gt;&lt;/script&gt;
&lt;script type="text/javascript"&gt;

// Initialization after page load
$(document).ready(function(){
  $('form#send').submit(onSend);
  longPoll();
  $('#nickname').focus();
});

// Send message on pressing Submit
function onSend(eventData){
  eventData.preventDefault();
  var msgArr = $(this).serializeArray();
  var message = {
    nickname : msgArr[0].value,
    text : msgArr[1].value
  };
  $.post('/send', message, function (data){
    $('#text').val('').focus();
  },
  'json');
}

// Called when new message is available
function longPoll(data){
  if (data &amp;&amp; data.messages) {
    for (var i = 0; i &lt; data.messages.length; i++) {
      var message = data.messages[i];
      $('&lt;p&gt;&lt;b&gt;'+message.nickname+':&lt;/b&gt;&lt;span&gt;'+message.text+'&lt;/span&gt;&lt;/p&gt;').hide().prependTo('#messages').slideDown();
    }
  }

  // message processed, wait for new messages
  $.ajax({
    cache: false,
    type: "GET",
    url: "/recv",
    success: function(data){
       longPoll(data);
    }
  });
}
&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;h1&gt;Node.js Zoo Chat&lt;/h1&gt;
&lt;form action="/send" method="post" id="send"&gt;
    &lt;label for="nickname"&gt;Nickname:&lt;/label&gt; &lt;input name="nickname" size="10" id="nickname" /&gt;
    &lt;label for="text"&gt;Message:&lt;/label&gt; &lt;input name="text" size="40" id="text" /&gt;
    &lt;input type="submit"&gt;
&lt;/form&gt;
&lt;div id="messages"&gt;&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;</code></pre>
<p>To apply changes press Restart and then Run:</p>
<p>&nbsp;</p>
<p><img class="alignnone size-full wp-image-620" title="image06" src="http://www.helicontech.com/articles/wp-content/uploads/2011/11/image06.png" alt="" width="700" height="583" /></p>
<p>&nbsp;</p>
<p>Now we can make sure the chat works by running it in two browsers:</p>
<p><img class="alignnone size-full wp-image-621" title="image07" src="http://www.helicontech.com/articles/wp-content/uploads/2011/11/image07.png" alt="" width="700" height="482" /></p>
<h3>Installing modules</h3>
<p>The flexibility and usability of each web framework may probably be defined by availability of extra modules and applicability of third-party technologies. At present Node Package Manager declared stable for Windows, so you ca use it safely for modules installations. NPM is included in Node.js Hosting Package and we have plans to include it into Node.js engine installation itself very soon &#8211; just as new Node.js MSI installer will be applicable to use in Helicon Zoo repository. And there’s one trick to remember &#8211; by default npm installs modules to node_modules folder under the folder it was invoked from. This is good for further application deployment on remote server as all required modules are included into application folder itself. Thus, to install module for site, go to the site root and execute:</p>
<pre>C:\&gt;cd "C:\My Web Sites\Node.js Site"

C:\My Web Sites\Node.js Site&gt;C:\node\npm.cmd install mongodb

npm WARN nodeunit@0.5.1 package.json: bugs['web'] should probably be bugs['url']
&gt; mongodb@0.9.7-1.4 install C:\My Web Sites\Node.js\node_modules\mongodb
&gt; node install.js
================================================================================
=                                                                              =
=  To install with C++ bson parser do &lt;npm install mongodb --mongodb:native&gt;   =
=                                                                              =
================================================================================
mongodb@0.9.7-1.4 ./node_modules/mongodb</pre>
<p>Another thing worth mentioning is that no all existing modules work for Windows. E.g. the perfect <a href="https://github.com/0ctave/node-sync">node-sync</a> library won’t work for Windows. This library helps avoid monstrous callbacks paradigm without losing Node.js asynchronous nature, but it relies on <a href="https://github.com/laverdet/node-fibers">node-fibers</a>, which do not work on Windows. Hopes are that in future fibers will be implemented directly into Node.js.</p>
<p>Nevertheless, most modules are fully operational on Windows.</p>
<h3 dir="ltr">CoffeeScript</h3>
<p>If you start working on a more or less complex Node.js project, sooner or later you’ll come to a conclusion that JavaScript is not that friendly. Tons of braces, loads of unnecessary constructions &#8211; all that stuff doesn’t add to code readability and makes code management more complicated. Luckily, you are not the first one to notice that, so the problem is already solved. There are many derivative languages based on JavaScript or extending it. Here’s a short list FYI: <a href="http://altjs.org/">http://altjs.org/</a></p>
<p>We take CoffeeScript as the trendiest for now. Code written with CoffeeScript is simple and easy to read. This code is then compiled into original JavaScript and executed. Moreover, JavaScript code may be converted into CoffeeScript. For example, server.js script from our chat in CoffeeScript becomes this:</p>
<pre><code class="no-highlight">express = require("express")
callbacks = []

// Sends messages to clients
appendMessage = (message) -&gt;
  resp = messages: [ message ]
  callbacks.shift() resp  while callbacks.length &gt; 0

// Creation of express server
app = module.exports = express.createServer()
app.use express.bodyParser()

// Simply respond with index.html
app.get "/", (req, res) -&gt;
  res.sendfile "index.html"

// Process messages from client
app.post "/send", (req, res) -&gt;
  message =
    nickname: req.param("nickname", "Anonymous")
    text: req.param("text", "")

  appendMessage message
  res.json status: "ok"

// Wait for new messages
app.get "/recv", (req, res) -&gt;
  callbacks.push (message) -&gt;
    res.json message

// Listen to the port
app.listen process.env.PORT</code></pre>
<p>Learn more about CoffeeScript: <a href="http://jashkenas.github.com/coffee-script/">http://jashkenas.github.com/coffee-script/</a><br />
To install CoffeeScript run: C:\node\npm.cmd install coffe-script</p>
<h2 dir="ltr">Debugging Node.js-apps</h2>
<p>There’s a good tool for Node.js apps debugging — <a href="https://github.com/dannycoates/node-inspector">node-inspector</a>. It is already included into node_modules folder in template of Node.js-site. node-inspector works as follows:</p>
<ul>
<li>application to be debugged in run in debug-mode (execute node.exe with &#8211;debug or &#8211;debug-brk parameter);</li>
<li>node-inspector, being also a web-app, is launched;</li>
<li>these 2 apps communicate via WebSocket protocol to share debug information;</li>
<li>page with the application being debugged is opened in browser;</li>
<li>webkit-compatible browser opens node-inspector interface with debug info; its interface resembles that of Web Inspector in Google Chrome or Safari.</li>
</ul>
<p>In root folder of template-based node.js-site there’s start_debug.cmd file which runs debugging for current app and opens pages in the browser for debugging.</p>
<p>&nbsp;</p>
<p><img class="alignnone size-full wp-image-616" title="image02" src="http://www.helicontech.com/articles/wp-content/uploads/2011/11/image02.png" alt="" width="600" height="477" /></p>
<p>&nbsp;</p>
<p>This is how debugger looks in the browser:</p>
<p>&nbsp;</p>
<p><img class="alignnone size-full wp-image-614" title="image00" src="http://www.helicontech.com/articles/wp-content/uploads/2011/11/image00.png" alt="" width="700" height="500" /></p>
<p>&nbsp;</p>
<h2 dir="ltr">Deploying on server</h2>
<p>Now we have an app and want to put in online. What we need is a server, and now putting together Windows server and Node.js is easy as never before. We only need to go through several steps we did at the beginning of the article (which we used to deploy working environment). Namely: install Microsoft Web Platform Installer, add Helicon Zoo feed into it and set up Node.js Hosting Package from Zoo repository. Done &#8211; server is ready to run our app. Server platforms supported include Windows 2008 and 2008 R2, x86 and x64.</p>
<p>What needs to be done next is create blank web-site on the server using IIS or hosting panel (if we are creating our own hosting) and copy the app into the site with FTP or WebDeploy. In case of WebDeploy all necessary permissions for the folders will be assigned. One can also use Git or any other version control system, but that goes beyond the scope of this article.</p>
<p>Initially, Helicon Zoo Module was being developed for configuration of hosting solutions. And all applications within Zoo are separate and do not interfere. The module itself with default settings operates in automatic mode creating one worker process, when the load is low, or bearing new workers (up to the number of processor cores) to ensure maximum performance when the load goes up.</p>
<p>Helicon Zoo adopts the concept of engines and applications. Engines define what to run and how, using which protocol and port, min and max number of workers allowed and other general settings, which are specified globally in applicationHost.config. Then under the site you can create an application relying on a particular engine and pass all parameters required for its flawless operation. This helps isolate hosting administrator work from clients and clients from each other.</p>
<h2 dir="ltr">Node.js performance testing</h2>
<p>Testing server characteristics: Core 2 Quad 2.4 GHz, 8 Gb RAM, 1Gb LAN. For load generation we used more powerful machine and Apache Benchmark command «ab.exe -n 100000 -c 100 –k». To test Apache and Nginx we took Ubuntu 11.04 Server x64. IIS 7 tests ran on Windows Server 2008 R2. Nothing virtual — 100% hardware.</p>
<p>We’ve conducted 3 tests. In the first one Node.js was supposed to output current time in high resolution. Time was chosen to be sure responses didn’t come from cache. Second test implied reading from MySQL database, third one — writing to DB.</p>
<p>Here are the results (values on the graph mean requests per second):</p>
<p><img class="alignnone size-full wp-image-635" title="time_test_eng" src="http://www.helicontech.com/articles/wp-content/uploads/2011/11/time_test_eng.png" alt="" width="289" height="330" /><img class="alignnone size-full wp-image-634" title="read_test_eng" src="http://www.helicontech.com/articles/wp-content/uploads/2011/11/read_test_eng.png" alt="" width="289" height="330" /><img class="alignnone size-full wp-image-633" title="write_test_eng" src="http://www.helicontech.com/articles/wp-content/uploads/2011/11/write_test_eng.png" alt="" width="289" height="330" /></p>
<p>Impressive, isn’t it? Time to explain what these tests measure. It’s not entirely correct to call them performance tests as we do not compare different processors. While processor may have performance, web server measurement unit is quite the contrary — how much processor time it takes to process one request.</p>
<p>The first test measures raw expenses on request processing for each web-server and their ability to use processor resources. There’s no way this or that set of technologies can respond faster on this processor. Nginx on Windows was far behind on this test because on this system Nginx opens new connection to back-end upon each request. While Apache on Windows surprised with connection pooling and true threads.</p>
<p>The second and third test show how web-server expenses grow with the “weight” of request. However, they are influenced by a number of other factors, such as performance of file system, DB drivers and the DB itself. Out of curiosity we’ve tested the joint Windows + Zoo + MongoDB to see the difference with MySQL. And it gave 6793 rps for reading and 2906 rps for writing. Writing speed is truly amazing.</p>
<p>Another interesting fact is that software and hardware used in these tests is absolutely the same as in Django tests in <a href="http://www.helicontech.com/articles/running-django-on-windows-with-performance-tests/">this article</a>. So their results may be compared. Undoubtedly Node.js scripts are much more light-weight, we didn’t use templates, ORM etc,, but anyway it’s worth thinking about.</p>
<p>Responding to readers’ requests we are posting detailed ab graphs. We’ve re-done the first test with simple time output, ‘case it most verbosely depicts web server operation. Config files and js scripts being tested may be downloaded from <a href="http://www.helicontech.com/zoo/media/nodejs-test-configuration.zip">here</a>. There are only includes, everything else left by default. Horizontal axis shows requests, vertical one — response time in milliseconds.</p>
<p>Windows, IIS7 + Zoo, “time output”:</p>
<p><img class="alignnone size-full wp-image-613" title="windows-zoo-time-data" src="http://www.helicontech.com/articles/wp-content/uploads/2011/11/windows-zoo-time-data.png" alt="" width="640" height="280" /></p>
<p>Ubuntu, Apache, “time output”:</p>
<p><img class="alignnone size-full wp-image-627" title="ubundu-apache-time-data" src="http://www.helicontech.com/articles/wp-content/uploads/2011/11/ubundu-apache-time-data.png" alt="" width="640" height="280" /></p>
<p>Ubuntu, Nginx, “time output”:</p>
<p><a href="http://www.helicontech.com/articles/wp-content/uploads/2011/11/ubundu-nginx-time-data.png"><img class="alignnone size-full wp-image-628" title="ubundu-nginx-time-data" src="http://www.helicontech.com/articles/wp-content/uploads/2011/11/ubundu-nginx-time-data.png" alt="" width="640" height="280" /></a></p>
<p>&nbsp;</p>
<h2 dir="ltr">Summing up</h2>
<p>I believe that Node.js is a rather promising trend. It boasts great performance and flexibility. What is especially pleasing is that it’s equally good on both Unix and Windows and uses relevant technological solutions for each system which the tests vividly prove.</p>
<p>Support of Erlang and Java in Helicon Zoo is on the way. It will be of interest to compare performance of these technologies as well. For now Node.js is an unquestionable leader in performance among supported frameworks.</p>
<img src="http://feeds.feedburner.com/~r/HeliconTechBlog/~4/2GOhieD1LNc" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.helicontech.com/articles/node-js-on-windows-with-performance-tests/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.helicontech.com/articles/node-js-on-windows-with-performance-tests/</feedburner:origLink></item>
		<item>
		<title>Running Django on Windows (with performance tests)</title>
		<link>http://feedproxy.google.com/~r/HeliconTechBlog/~3/Z0Gj8E2WZnM/</link>
		<comments>http://www.helicontech.com/articles/running-django-on-windows-with-performance-tests/#comments</comments>
		<pubDate>Tue, 20 Sep 2011 14:39:36 +0000</pubDate>
		<dc:creator>Slov</dc:creator>
				<category><![CDATA[Helicon Zoo]]></category>
		<category><![CDATA[CodeProject]]></category>
		<category><![CDATA[django]]></category>
		<category><![CDATA[fastcgi]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[zoo]]></category>

		<guid isPermaLink="false">http://www.helicontech.com/articles/?p=554</guid>
		<description><![CDATA[Django is a trendy Python-based framework for web applications. Its ever-growing popularity owes to availability of quick development tools, inbuilt administrative interface and high operation speed. Unfortunately, until now there was no easy tried-and-true way to deploy and run Django-apps &#8230; <a href="http://www.helicontech.com/articles/running-django-on-windows-with-performance-tests/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Django is a trendy Python-based framework for web applications. Its ever-growing popularity owes to availability of quick development tools, inbuilt administrative interface and high operation speed. Unfortunately, until now there was no easy tried-and-true way to deploy and run Django-apps on IIS web-server.</p>
<p>Introducing Helicon Zoo – a repository of popular web-frameworks for Microsoft IIS. It bases on Microsoft Web Platform Installer (WebPI) technology to deploy apps. WebPI also handles different dependencies and takes care of installation of necessary components, such as Python, Django, various database drivers and modules. And, of course, Helicon Zoo itself which sticks it all to MS IIS 7.<span id="more-554"></span></p>
<h2>How to use</h2>
<p>Web development process implies use of two relatively independent environments – development and production. Helicon Zoo may be used in production as well as on developer’s machine, or in both places. In either case the sequence of actions might be:</p>
<p>To start, you need to download Web Platform Installer from Microsoft website (<a href="http://www.microsoft.com/web/downloads/platform.aspx">http://www.microsoft.com/web/downloads/platform.aspx</a>) and install it. WebPI already includes wide range of frameworks and applications for IIS like PHP, ASP.NET, WordPress, Drupal, phpBB. To launch Helicon Zoo add new feed to WebPI:</p>
<ul>
<li>Run WebPI and click Options<br />
<a href="http://www.helicontech.com/articles/wp-content/uploads/2011/09/image001.png"><img class="alignnone size-full wp-image-558" title="image001" src="http://www.helicontech.com/articles/wp-content/uploads/2011/09/image001.png" alt="" width="500" height="210" /></a></li>
<li>In «Display additional scenarios» box put <a href="http://www.helicontech.com/zoo/feed">http://www.helicontech.com/zoo/feed</a> and click Add feed<br />
<a href="http://www.helicontech.com/articles/wp-content/uploads/2011/09/image003.png"><img class="alignnone size-full wp-image-559" title="image003" src="http://www.helicontech.com/articles/wp-content/uploads/2011/09/image003.png" alt="" width="500" height="194" /></a></li>
</ul>
<p>If you now go to Zoo, Applications (in WebPI interface) you’ll find some new apps: Blank Django Project, Blank Rails Project, Blank Perl Project, Blank Mojolicious Project:</p>
<p><a href="http://www.helicontech.com/articles/wp-content/uploads/2011/09/image005.png"><img class="alignnone size-full wp-image-560" title="image005" src="http://www.helicontech.com/articles/wp-content/uploads/2011/09/image005.png" alt="" width="500" height="298" /></a></p>
<p>Blank Django Project is the simplest “Hello, World!” app used to set up all dependencies needed for Django-app to run and empty Django-project itself. For installation press “Add” and “Install”; then you’ll be shown the list of dependencies:</p>
<p><a href="http://www.helicontech.com/articles/wp-content/uploads/2011/09/image007.png"><img class="alignnone size-full wp-image-561" title="image007" src="http://www.helicontech.com/articles/wp-content/uploads/2011/09/image007.png" alt="" width="500" height="501" /></a></p>
<p>To accept licenses and start downloading and installing the project press “I Accept”. When done, the newly-installed project can be run by clicking “Launch application in browser”:</p>
<p><a href="http://www.helicontech.com/articles/wp-content/uploads/2011/09/image009.png"><img class="alignnone size-full wp-image-562" title="image009" src="http://www.helicontech.com/articles/wp-content/uploads/2011/09/image009.png" alt="" width="500" height="283" /></a></p>
<p>This screen symbolizes that Python, Django and the rest of things needed to run the apps were successfully installed on your PC. Now, if it’s a dev environment, you can start creating based on this empty “Hello World” app. After you make some changes to the app, you may upload it to production server with all files, folders, necessarily web.config, and if Blank Django Project was previously installed on the server (regardless on the destination folder as only its dependencies matter), the app is going to work. Every time you upload changes to the server restart Application Pool. This is needed for Django (and Rails) only, other frameworks probably won’t need it. Upon restart automatic data migration will occur &#8211; <em>manage.py syncdb</em>. Owing to this fact solution may be used on shared hostings where the user can’t access console.</p>
<h2>Using WebMatrix</h2>
<p>Another way to go is to use WebMatrix for development. Instead of installing &#8220;Blank Django Project&#8221; go to Zoo-&gt;Packages and install &#8220;WebMatrix Templates&#8221; and &#8220;Python Hosting Package&#8221;.</p>
<p><a href="http://www.helicontech.com/articles/wp-content/uploads/2011/09/WebPI-Zoo-Webmatrix-Templates.png"><img class="alignnone size-full wp-image-589" title="WebPI-Zoo-Webmatrix-Templates" src="http://www.helicontech.com/articles/wp-content/uploads/2011/09/WebPI-Zoo-Webmatrix-Templates.png" alt="" width="500" height="285" /></a></p>
<p>After that run WebMatrix and create new application from template. You will be proposed number of templates to choose from. Please select &#8220;Django site&#8221; and create it.</p>
<p><a href="http://www.helicontech.com/articles/wp-content/uploads/2011/09/WebMatrix-Django-Template.png"><img class="alignnone size-full wp-image-590" title="WebMatrix-Django-Template" src="http://www.helicontech.com/articles/wp-content/uploads/2011/09/WebMatrix-Django-Template.png" alt="" width="480" height="390" /></a></p>
<p>Then to deploy your web site to a remote IIS server &#8220;Python Hosting Package&#8221; has to be installed on this server to run Django applications.</p>
<h2>Under the hood</h2>
<p>Helicon Zoo core is represented by native IIS module acting as a bridge between IIS web-server and frameworks using Ruby, Python, Perl etc. the module makes use of FastCGI protocol which is recognized as quick and accurate means for interaction between web-apps and web-server. This interaction is asynchronous and uses I/O  Completion Port technology. For transport Zoo uses either named pipes or TCP-sockets. Web-servers supported include IIS 7, IIS 7.5 and IIS Express.</p>
<p>Basic Helicon Zoo configuration is stored in &lt;heliconZooServer&gt; section of applicationHost.config. This section includes descriptions of all FastCGI-drivers to be operated via Zoo. Here’s an example of driver description for running Python wsgi-apps (Django-apps in particular), zoofcgi.py is a worker written in Python that provides transport through named pipes:</p>
<pre><code>
&lt;engine name="python.2.7.pipe"
     fullPath="c:\python27\python.exe"
     arguments="-O %SystemDrive%\Zoo\Workers\python\zoofcgi.py"
     transport="pipe" /&gt;
</code></pre>
<h3>Web.config</h3>
<p>Responsible for configuration of web apps working through Zoo is web.config file. Following is the example configuration of Django-app to work in 32-bit pool:</p>
<pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
 &lt;configuration&gt;
  &lt;system.webServer&gt;
   &lt;heliconZoo&gt;
    &lt;application name="django.project.x86" &gt;
     &lt;environmentVariables&gt;
      &lt;add name="PYTHONPATH" value="%APPL_PHYSICAL_PATH%;%PYTHONPATH%" /&gt;
      &lt;add name="DJANGO_SETTINGS_MODULE" value="settings" /&gt;
          &lt;add name="DEPLOY_FILE" value="deploy.py" /&gt;
          &lt;add name="DEPLOY_LOG" value="log\deploy.log" /&gt;
     &lt;/environmentVariables&gt;
    &lt;/application&gt;
   &lt;/heliconZoo&gt;
   &lt;handlers&gt;
     &lt;add name="django.project.x86"
                scriptProcessor="python.2.7.pipe"  path="*" verb="*"
                modules="HeliconZoo_x86" preCondition="bitness32"
                resourceType="Unspecified" requireAccess="Script" /&gt;
    &lt;/handlers&gt;
  &lt;/system.webServer&gt;
 &lt;/configuration&gt;</code></pre>
<p>Some important comments on the above config:</p>
<ul>
<li><code>scriptProcess="python.2.7.pipe"</code> is a reference to FastCGI-drived defined in applicationHost.config;</li>
<li>PYTHONPATH environment variable contains a path where Python looks for its modules; in or case we are adding a path to our Django-app into PYTHONPATH;</li>
<li><code>DJANGO_SETTINGS_MODULE</code> environment variable storing the path to Python configuration file settings.py for Django-app, e.g. ‘mysite.settings’</li>
<li> ‘DEPLOY_FILE’ environment variable contains the path to the file within the app which will be run before the first request to the app after restart of IIS-app. This file may be used for DB synchronization, for example: ‘manage.py syncdb –noinput’;</li>
<li> ‘DEPLOY_LOG’ environment variable contains the path to the file within the app which is the destination for debugging info generated by DEPLOY_FILE command. The folder containing this file must be granted Write permissions for the user running this IIS-app (usually it’s IIS_IUSRS group).</li>
</ul>
<h3>Static content</h3>
<p>Django framework is not suitable for fast and safe processing of static files (images, scripts, css). Statics must be processed directly by web-server. To do so all static files must be stacked in one folder and Django request handler for this folder is then switched off like this:</p>
<pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
 &lt;configuration&gt;
  &lt;system.webServer&gt;
   &lt;handlers&gt;
    &lt;remove name="django.project.x86" /&gt;
   &lt;/handlers&gt;
  &lt;/system.webServer&gt;
 &lt;/configuration&gt;</code></pre>
<h3>Sample Django-project for IIS 7</h3>
<p>Let’s have a Django-project consisting of 3 apps:</p>
<ul>
<li>site — the site itself with templates, statics, urls.py nad settings.py</li>
<li>blog</li>
<li>store</li>
</ul>
<p>Static files located in site/media are available in the /media/ virtual folder (i.e. MEDIA_URL=&#8217;/media/&#8217;)</p>
<p>Having installed Blank Django Project in the root of the site and having copied our django-project, we’ll get the following structure:</p>
<p><a href="http://www.helicontech.com/articles/wp-content/uploads/2011/09/image011.png"><img class="alignnone size-full wp-image-563" title="image011" src="http://www.helicontech.com/articles/wp-content/uploads/2011/09/image011.png" alt="" width="500" height="378" /></a></p>
<p>/media/ is a virtual folder pointing at site/media; Zoo module is switched off for this folder as mentioned above. PYTHONPATH in root web.config points at site root and DJANGO_SETTINGS_MODULE is set to ‘site.settings’:</p>
<pre><code>...
  &lt;heliconZoo&gt;
    &lt;application name="django.project.x86" &gt;
     &lt;environmentVariables&gt;
      &lt;add name="PYTHONPATH" value="%APPL_PHYSICAL_PATH%" /&gt;
      &lt;add name="DJANGO_SETTINGS_MODULE" value="site.settings" /&gt;
     &lt;/environmentVariables&gt;
    &lt;/application&gt;
   &lt;/heliconZoo&gt;
...</code></pre>
<h2>Performance</h2>
<p>And now performance test for dessert. Testing machine acting as server was Core 2 Quad 2.4 GHz, 8 Gb RAM, Gigabit LAN. To generate load we used more powerful PC with Apache Benchmark. To measure Apache and Nginx performance Ubunthu 11.04 Server x64 was used. IIS 7 tests ran on Windows Server 2008 R2. No virtual machines – only bare hardware. As transport on Nginx we used the most advanced uwsgi, as well as wsgi and fast_cgi for comparison. On IIS 7 we’ve also compared with PyISAPIе.</p>
<p>There where two Django scripts created as testing pages. The first one outputs current time in high resolution; this is done to ensure pages are not taken from cache. The second one does the same but previously saves the result into database. It’s all done using templates in order to apply real Django infrastructure; DB used is MySQL. All settings were left default as the task was to test the most common configurations. Here are results (in requests per second):</p>
<p><a href="http://www.helicontech.com/articles/wp-content/uploads/2011/09/image13.png"><img class="alignnone size-full wp-image-579" title="image13" src="http://www.helicontech.com/articles/wp-content/uploads/2011/09/image13.png" alt="" width="377" height="310" /></a></p>
<p>No surprises here as Python performance on Windows may be slower than Ubunthu version. Taking this into consideration Helicon Zoo transport performance should be really high. Uwsgi is ahead probably due to closer integration with Django.</p>
<p><a href="http://www.helicontech.com/articles/wp-content/uploads/2011/09/image14.png"><img class="alignnone size-full wp-image-578" title="image14" src="http://www.helicontech.com/articles/wp-content/uploads/2011/09/image14.png" alt="" width="371" height="306" /></a></p>
<p>The results for the second script are not that smooth. Why Nginx + fcgi + MySQL showed only 175 requests per second remains unknown. MySQL on Windows score is also frustrating, although on shared hosting the problem might not be that critical. The thing is that performance drops due to internal MySQL locks, while the server is not even loaded for 20% while generating these 104 requests per seocnd. It’s reasonable to assume that by increasing number of sites on the server and consequently the number of DBs, if they do not interlock with each other, the total server performance will be acceptable.</p>
<p>Thus we decided to add MS SQL Express into the tests. The result was easy to explain with Python and its database driver being the bottleneck, though in general the picture is quite promising. Unfortunately PyISAPIe was unable to work with MS SQL Express and was excluded from tests.</p>
<p>It is worth to mention the ability of IIS 7 to handle great number of connections. IIS 7 + Helicon Zoo easily held thousands of concurrent connections, we simply didn’t have testing powers to generate enough connections to trigger any problems in this test. Ubuntu with default settings started throwing connection failures when the number of connections increased. Moreover, Apache appeared to be greedy for memory. During the test with the number of connections going up Apache swallowed about 3 GB in 20 seconds.</p>
<h2>Resume</h2>
<p>Suggested solution proved stable and efficient. It will perfectly fit development environment as well as production. Advantageous is possibility of using Helicon Zoo by different Windows shared hosting providers to offer Django services to their clients. Hope is that with the growth number of Django servers on Windows Python developers will pay more attention to code debugging and optimization for Windows platform. And the army of existing Windows-developers can also contribute to current open-source projects.</p>
<img src="http://feeds.feedburner.com/~r/HeliconTechBlog/~4/Z0Gj8E2WZnM" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.helicontech.com/articles/running-django-on-windows-with-performance-tests/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		<feedburner:origLink>http://www.helicontech.com/articles/running-django-on-windows-with-performance-tests/</feedburner:origLink></item>
		<item>
		<title>Running Django, Rails and Mojolicious on Windows Server 2008 with IIS 7</title>
		<link>http://feedproxy.google.com/~r/HeliconTechBlog/~3/UrbQqAYz8Fs/</link>
		<comments>http://www.helicontech.com/articles/run-django-apps-on-iis/#comments</comments>
		<pubDate>Fri, 24 Jun 2011 14:06:17 +0000</pubDate>
		<dc:creator>ruslan</dc:creator>
				<category><![CDATA[Helicon Zoo]]></category>
		<category><![CDATA[django]]></category>
		<category><![CDATA[fastcgi]]></category>
		<category><![CDATA[zoo]]></category>

		<guid isPermaLink="false">http://www.helicontech.com/articles/?p=497</guid>
		<description><![CDATA[Recently released  Helicon Zoo is a repository of popular web frameworks for Microsoft IIS. It makes installing and running Django, Ruby on Rails and Mojolicious on Windows Servers a piece of cake. How it works Helicon Zoo utilizes Microsoft Web &#8230; <a href="http://www.helicontech.com/articles/run-django-apps-on-iis/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Recently released  <a href="http://www.helicontech.com/zoo/">Helicon Zoo</a> is a repository of popular web frameworks for Microsoft IIS. It makes installing and running Django, Ruby on Rails and Mojolicious on Windows Servers a piece of cake.</p>
<p><span id="more-497"></span></p>
<h2>How it works</h2>
<p>Helicon Zoo utilizes Microsoft Web Platform Installer (WebPI) to make installation of web frameworks and all required dependencies easy and smooth. At first, you need to download and install WebPI from Microsoft web site <a href="http://www.microsoft.com/web/downloads/platform.aspx">here</a>. This is a great tool that is already packed with many ASP.NET and PHP applications and dependencies to install a whole technology stack on your server. And the greatest thing about WebPI is that it can be extended by adding custom repositories. So copy this link -<a title="Helicon Zoo Feed" href="http://www.helicontech.com/zoo/feed/"> <strong>http://www.helicontech.com/zoo/feed/</strong></a>, open WebPI options</p>
<p><img class="alignnone" title="Web Platform Installer, click Options" src="http://www.helicontech.com/zoo/images/zoo-01-webpi-options.png" alt="" width="500" height="210" /></p>
<p>put it into the <em>Display additional scenarios</em> field and click <strong>Add feed</strong>.</p>
<p><img class="alignnone" title="Web Platform Installer Options, add Helicon Zoo feed" src="http://www.helicontech.com/zoo/images/zoo-02-webpi-add-feed.png" alt="" width="500" height="194" /></p>
<p>Now if you select <strong>Applications</strong>, <strong>Tools</strong> at the bottom of the list, you will find new applications: <em>Blank Django Project</em>, <em>Blank Rails Project</em>, <em>Blank Perl Project</em>, <em>Blank Mojolicious Project</em></p>
<p><img class="alignnone" title="Web Platform Installer applications" src="http://www.helicontech.com/zoo/images/zoo-03-webpi-apps.png" alt="" width="500" height="251" /></p>
<p>These are all empty &#8220;Hello World!&#8221; applications used to install all required dependencies which you can stuff with your code later.</p>
<p>So let&#8217;s choose Blank Django Project, click <strong>Add</strong> and <strong>Install</strong>.  This will create new IIS application with pre-defined configuration. After download and installation are completed you can use <em>Launch application in browser</em> link:</p>
<p><a href="http://www.helicontech.com/articles/wp-content/uploads/2011/06/BlankDjangoProject.png"><img class="alignnone size-full wp-image-498" title="Blank Django Project" src="http://www.helicontech.com/articles/wp-content/uploads/2011/06/BlankDjangoProject.png" alt="" width="500" height="283" /></a></p>
<h2>What&#8217;s inside</h2>
<p>The core of Helicon Zoo is a native IIS 7 (or IIS Express) module that provides FastCGI support. This module differs from Microsoft FCGI module generally developed to provide PHP support for IIS. <em>Helicon Zoo Module</em> is built using super capacitive asynchronous  <em>I/O Completion Port</em> technology. It supports Pipe and TCP transports and additional level of configuration to run many different FastCGI-enabled frameworks. These includes <strong>flup</strong> tor Python, <strong>Rack</strong> for Ruby on Rails, <strong>FCGI</strong> and <strong>Plack</strong> for Perl and Mojolicious.</p>
<p>The core configuration of Helicon Zoo Module is located in the <code>&lt;heliconZooServer&gt;</code> section of applicationHost.config file. This section defines all FastCGI engines that will work with Zoo. Here is an example of Django FastCGI engine definition using pipe transport; zoofcgi.py is our Python worker with pipe transport support:</p>
<pre><code>&lt;engine name="python.2.7.pipe"
    fullPath="c:\python27\python.exe"
    arguments="-O %SystemDrive%\Zoo\Workers\python\zoofcgi.py"
    transport="pipe" /&gt;</code></pre>
<h2>How to deploy Django projects</h2>
<p>Helicon Zoo offers simple way to deploy your Django applications on the server or test machine. First you install Blank Django Project in desired location using Web Platform Installer, then you overwrite this project content with your project files and set up deployment into this forlder. Blank Django Project installs all required dependencies on target machine and puts web.config (the only file needed for your application) in the root directory of application.</p>
<h3>Web.config</h3>
<p>Configuration of Zoo-powered applications is done with web.config file. Here is an example of such file to configure Django application for 32-bit.</p>
<pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;configuration&gt;
 &lt;system.webServer&gt;
  &lt;heliconZoo&gt;
   &lt;application name="django.project.x86" &gt;
    &lt;environmentVariables&gt;
     &lt;add name="PYTHONPATH" value="%APPL_PHYSICAL_PATH%;%PYTHONPATH%" /&gt;
     &lt;add name="DJANGO_SETTINGS_MODULE" value="settings" /&gt;
    &lt;/environmentVariables&gt;
   &lt;/application&gt;
  &lt;/heliconZoo&gt;
  &lt;handlers&gt;
   &lt;add name="django.project.x86"
       scriptProcessor="python.2.7.pipe"  path="*" verb="*"
       modules="HeliconZoo_x86" preCondition="bitness32"
       resourceType="Unspecified" requireAccess="Script" /&gt;
  &lt;/handlers&gt;
 &lt;/system.webServer&gt;
&lt;/configuration&gt;</code></pre>
<p>Several important things are defined here:</p>
<ul>
<li><code>scriptProcess="python.2.7.pipe"</code> — a reference to FastCGI engine defined in the applicationHost.config;</li>
<li>environment variable <code>PYTHONPATH</code> — a path where Python will check to load modules.  Here path to this IIS application is appended to allow Python to load additional modules directly from the directory of your application without installing them globally in the system.</li>
<li>environment variable <code>DJANGO_SETTINGS_MODULE</code> — a Python path to the configuration file settings.py of your Django project, for example &#8216;mysite.settings&#8217;.</li>
</ul>
<h3>Static content</h3>
<p>It is recommended to serve static content omitting Django to save processor time and increase performance. You can easily do this by putting all static files into a directory with the following web.config in it. This will disable Django module in directory:</p>
<pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;configuration&gt;
 &lt;system.webServer&gt;
  &lt;handlers&gt;
   &lt;remove name="django.project.x86" /&gt;
  &lt;/handlers&gt;
 &lt;/system.webServer&gt;
&lt;/configuration&gt;</code></pre>
<h2>Django configuration example</h2>
<p>Let&#8217;s assume our Django project consists of three applications:</p>
<ul>
<li><code>site</code> — a site itself with pages templates, static files, urls.py and settings.py;</li>
<li><code>blog</code>;</li>
<li><code>store</code>.</li>
</ul>
<p>Static files are located in site/media and are available as /media/ virtual directory (i.e. <code>MEDIA_URL='/media/'</code>).</p>
<p>After we install Blank Django Project in the root of web site and copy our Django application project in it we will have the following directory structure:</p>
<p><span style="font-size: small;"><span style="line-height: 24px;"><a href="http://www.helicontech.com/articles/wp-content/uploads/2011/06/django-powered-site.png"><img class="alignnone size-full wp-image-503" title="Django Powered Site on IIS" src="http://www.helicontech.com/articles/wp-content/uploads/2011/06/django-powered-site.png" alt="" width="500" height="378" /></a></span></span></p>
<p><code>/media/</code> — is a virtual directory which is mapped to <code>site/media</code> and Django is disabled there using web.config file example above. In the root web.config <code>PYTHONPATH</code> points to the site root directory and <code>DJANGO_SETTINGS_MODULE</code> is set to <code>site.settings</code>:</p>
<pre><code class="xml"> ...
 &lt;heliconZoo&gt;
   &lt;application name="django.project.x86" &gt;
    &lt;environmentVariables&gt;
     &lt;add name="PYTHONPATH" value="%APPL_PHYSICAL_PATH%" /&gt;
     &lt;add name="DJANGO_SETTINGS_MODULE" value="site.settings" /&gt;
    &lt;/environmentVariables&gt;
   &lt;/application&gt;
  &lt;/heliconZoo&gt;
...</code></pre>
<p>That&#8217;s all!<br />
Sincerely, Helicon Tech team.</p>
<img src="http://feeds.feedburner.com/~r/HeliconTechBlog/~4/UrbQqAYz8Fs" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.helicontech.com/articles/run-django-apps-on-iis/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		<feedburner:origLink>http://www.helicontech.com/articles/run-django-apps-on-iis/</feedburner:origLink></item>
		<item>
		<title>Сounting downloads from your site</title>
		<link>http://feedproxy.google.com/~r/HeliconTechBlog/~3/jyvHm1-dHLU/</link>
		<comments>http://www.helicontech.com/articles/counting-downloads-from-your-site/#comments</comments>
		<pubDate>Mon, 21 Feb 2011 13:48:35 +0000</pubDate>
		<dc:creator>ruslan</dc:creator>
				<category><![CDATA[Helicon Ape]]></category>
		<category><![CDATA[CodeProject]]></category>
		<category><![CDATA[mod_dbd]]></category>
		<category><![CDATA[mod_env]]></category>
		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://www.helicontech.com/articles/?p=456</guid>
		<description><![CDATA[If you have some downloadable content on your site (installation packages), you&#8217;ll probably want to monitor the statistics of downloads. But the popular Google Analytics system cannot count that as it is working only inside html-pages. Another option is analyzing &#8230; <a href="http://www.helicontech.com/articles/counting-downloads-from-your-site/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>If you have some downloadable content on your site (installation packages), you&#8217;ll probably want to monitor the statistics of downloads. But the popular Google Analytics system cannot count that as it is working only inside html-pages. Another option is analyzing server logs, but that&#8217;s something you&#8217;ll probably choose last of all&#8230; That&#8217;s why we are offering rather a simple way of counting downloads with <a href="http://www.helicontech.com/ape/">Helicon Ape</a>.</p>
<p><span id="more-456"></span></p>
<p>The steps to be accomplished are:</p>
<ul>
<li>create a table in the database to store the download counters for the products;</li>
<li>create an .htaccess in Helicon Ape which will make records into the table upon each download with the help of <a href="http://www.helicontech.com/ape/doc/mod_dbd.htm">mod_dbd module</a>;</li>
<li>create a simple aspx-page to show downloads statictics.</li>
</ul>
<h2>Preconditions</h2>
<p>In the root of your site you have a <strong>downloads</strong> folder containing files for download (e.g., AudioCoder.msi, AudioDecoder.msi, AdditionalCodes.zip).<br />
You have Helicon Ape installed on your Windows Server 2008 (IIS7).<br />
You have SQL Server that will store the DB with downloads statistics.</p>
<h2>Table for storing statistics</h2>
<p>Run Microsoft SQL Server Management Studio and connect to your SQL server.</p>
<p><a href="http://www.helicontech.com/articles/wp-content/uploads/2011/02/sql01.png"><img class="alignnone size-full wp-image-459" title="SQL Server Management Studio login window" src="http://www.helicontech.com/articles/wp-content/uploads/2011/02/sql01.png" alt="SQL Server Management Studio login window" width="345" height="271" /></a></p>
<p>Right click on &#8216;Databases&#8217;, select &#8216;Create Database&#8217;, enter database name (for example &#8216;DownloadsCounter&#8217;) and click &#8216;OK&#8217;.</p>
<p><a href="http://www.helicontech.com/articles/wp-content/uploads/2011/02/sql02.png"><img class="alignnone size-medium wp-image-465" title="Database creation" src="http://www.helicontech.com/articles/wp-content/uploads/2011/02/sql02-300x232.png" alt="Database creation" width="300" height="232" /></a></p>
<p>Now we&#8217;ll create the table itself:<br />
Unfold the <em>DownloadsCounter</em> in Object Explorer, right click on &#8216;Tables&#8217; and select &#8216;New Table&#8230;&#8217;. Name the table &#8216;Downloads&#8217; and add 4 fields: <strong>id (int)</strong>, <strong>moment (datetime)</strong>, <strong>filename (nvarchar(50))</strong> and <strong>ipaddress (nvarchar(50))</strong> as shown on the pic below. You can find sql script to create table in attached <a href="http://www.helicontech.com/articles/wp-content/uploads/2011/02/DownloadsCounterExample.zip">DownloadsCounterExample.zip</a>.</p>
<p><a href="http://www.helicontech.com/articles/wp-content/uploads/2011/02/sql03.png"><img class="alignnone size-medium wp-image-466" title="Table creation" src="http://www.helicontech.com/articles/wp-content/uploads/2011/02/sql03-300x219.png" alt="Table creation" width="300" height="219" /></a></p>
<p>Done with the table!</p>
<h2>mod_dbd configuration</h2>
<p>Start Helicon Ape Manager, select your site from the tree and click on &#8216;downloads&#8217; folder. Now write the following config in .htaccess on the right.</p>
<p><a href="http://www.helicontech.com/articles/wp-content/uploads/2011/02/ape01.png"><img class="alignnone size-medium wp-image-467" title="Helicon Ape Manager" src="http://www.helicontech.com/articles/wp-content/uploads/2011/02/ape01-300x221.png" alt="Helicon Ape Manager" width="300" height="221" /></a></p>
<p>The config instructs mod_dbd to connect to DB, catches data from request (filename and client ip-address) and writes them into the DB.</p>
<pre><code># Helicon Ape version 3.0.0.59

# Connection settings
DBDriver mssql
DBDParams "Data Source=db2003\MSSQLSERVER2008;Initial Catalog=DownloadsCounter;\
           User ID=sa;Password=123123"

# Save Filename (for .msi &amp; .zip files only)
SetEnvIfNoCase REQUEST_URI ^/downloads/(.+\.(?:msi|zip))$ FileNameENV=$1
SetEnvIfNoCase REMOTE_ADDR ^(.*)$ IpAddrENV=$1

# Sql query to save download event
DBDPrepareSQL "INSERT INTO DownloadsCounter.dbo.Downloads\
    (moment, filename, ipaddress)\
    VALUES (\
        GETDATE(),\
        '%{FileNameENV}e',\
        '%{IpAddrENV}e'\
    )\
" InsertDownload

# Execute sql query if request uri is .msi or .zip file
SetEnvIf request_uri \.(?:msi|zip)$ dbd_execute=InsertDownload

# limit access to statistics page to localhost only
&lt;Files stat.aspx&gt;
Order Deny,Allow
Deny from all
Allow from ::1 127.0.0.1 localhost
&lt;/Files&gt;</code></pre>
<p>Save your .htaccess and try to download something from the browser. If you now throw a glimpse at the &#8216;downloads&#8217; table in SQL Server Management Studio, you&#8217;ll see the records appearing in it:</p>
<p><a href="http://www.helicontech.com/articles/wp-content/uploads/2011/02/sql04.png"><img class="alignnone size-medium wp-image-468" title="Table" src="http://www.helicontech.com/articles/wp-content/uploads/2011/02/sql04-300x126.png" alt="Table" width="300" height="126" /></a></p>
<h2>How it works?</h2>
<p>Helicon Ape module is processing all requests coming to /downloads/ folder. If .zip or .msi file is requested, Ape memorizes the filename (FileNameENV) and client IP (IpAddrEnv), from which the file was requested, and inserts these data into the table by means of SQL query.</p>
<h2>Statistics viewer</h2>
<p>The archive attached to the article includes <em>stat.aspx</em> which does a very simple task—shows records from &#8216;downloads&#8217; table.</p>
<p><a href="http://www.helicontech.com/articles/wp-content/uploads/2011/02/stat01.png"><img class="alignnone size-medium wp-image-469" title="stat01" src="http://www.helicontech.com/articles/wp-content/uploads/2011/02/stat01-300x154.png" alt="" width="300" height="154" /></a></p>
<p>Of course, that&#8217;s not the sort of viewer you need, as it must be capable of showing statistics by days, months, products etc. But designing a real-life solution is beyond the scope of this article, so feel free to advance <em>stat.aspx</em> by yourself.</p>
<h2>Resulting archive</h2>
<p>Below is the archive DownloadsCounterExample.zip containing all files from this article. To do some testing just unzip it into the root of your site and replace the database password from &#8217;123123&#8242; to the one you have in both .htaccess and web.config.</p>
<p><a href="http://www.helicontech.com/articles/wp-content/uploads/2011/02/DownloadsCounterExample.zip">DownloadsCounterExample.zip</a></p>
<h2>Why is this option better?</h2>
<p>As we already noticed, Google Analytics and like services are based on JavaScript working on the page. They know nothing about static content and other files loaded from the server.</p>
<p>Another option (yet another extreme) is server logs. They are not always accessible, not always enabled, besides, they require writing of special parsers or analyzers. Moreover, server logs do not provide live (current moment) info. Usually log file is created daily so their analysis is only possible at the beginning of the next day.</p>
<h2>Summing up</h2>
<p>The method explained above is a quick and effortless way to screw downloads counter to your site using Helicon Ape mod_dbd. The example is easily expendable, e.g. you can add more fields to the table to save Referer, User-Agent, etc., or develop a customizable statistics viewer.</p>
<p>We&#8217;ve just given you the basement, now it&#8217;s time for you to build a house.</p>
<p><em>Best regards,<br />
Ruslan—Helicon Tech Team</em></p>
<img src="http://feeds.feedburner.com/~r/HeliconTechBlog/~4/jyvHm1-dHLU" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.helicontech.com/articles/counting-downloads-from-your-site/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://www.helicontech.com/articles/counting-downloads-from-your-site/</feedburner:origLink></item>
		<item>
		<title>Make your websites work faster</title>
		<link>http://feedproxy.google.com/~r/HeliconTechBlog/~3/su3KNOnZu0U/</link>
		<comments>http://www.helicontech.com/articles/make-your-websites-work-faster/#comments</comments>
		<pubDate>Thu, 27 Jan 2011 11:25:44 +0000</pubDate>
		<dc:creator>ruslan</dc:creator>
				<category><![CDATA[Helicon Ape]]></category>
		<category><![CDATA[caching]]></category>
		<category><![CDATA[CodeProject]]></category>
		<category><![CDATA[mod_cache]]></category>
		<category><![CDATA[mod_expires]]></category>
		<category><![CDATA[mod_gzip]]></category>
		<category><![CDATA[performance]]></category>

		<guid isPermaLink="false">http://www.helicontech.com/articles/?p=375</guid>
		<description><![CDATA[In April 2010 Google announced, that speed of a web site will be considered as an aspect of web search ranking. This means that web site creators and webmasters need to optimize their websites. What is the best way to do &#8230; <a href="http://www.helicontech.com/articles/make-your-websites-work-faster/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>In April 2010 Google announced, that <a href="http://googlewebmastercentral.blogspot.com/2010/04/using-site-speed-in-web-search-ranking.html">speed of a web site will be considered as an aspect of web search ranking</a>. This means that web site creators and webmasters need to optimize their websites. What is the best way to do that? What if web developers are out of reach? What if changing the code is not an option?  We can offer several simple and fast solutions for improving your web site performance using <a href="http://www.helicontech.com/ape/">Helicon Ape</a>. To start with you need to <a href="http://www.helicontech.com/download-ape.htm">download</a> Helicon Ape and install it on your Windows server. Native Helicon Ape Manager allows you to change your web server setting using .htaccess text files.  <span id="more-375"></span> General simple advices:</p>
<h2>1. Cache statics</h2>
<p>Caching static content (pictures, css files, javascript files) on the client&#8217;s side (in browser) means that having received static file once browser saves it in cache and doesn&#8217;t make a request to the server next time the html-document is requested. File will be taken from cache. Both sides win: client sends less requests, web site is working faster and server processes less requests.  For instance, ordinary WordPress post page has over a dozen links to the static files (css files, pictures, scripts). Time spent on downloading these files exceeds time spent on downloading the post itself. Once having caching enabled the static content will be downloaded only once. While moving to the next page the only thing that will be downloaded is page itself. All static files will be taken from cache.  In order to make browser cache static content, http-response must contain specific headers: Expires and Cache-Control. Those headers are set by <a href="http://www.helicontech.com/ape/doc/mod_expires.htm">mod_expires</a> and <a href="http://www.helicontech.com/ape/doc/mod_headers.htm">mod_headers</a> modules.  For enabling caching, create .htacces file with the following content inside the static folder:</p>
<pre><code>ExpiresActive On
Header set Cache-Control public
ExpiresByType image/.+  "access 15 days"
ExpiresByType text/css  "access 5 days"
ExpiresByType application/x-javascript "access 5 days"
ExpiresByType application/javascript "access 5 days"</code></pre>
<p>In case there&#8217;s no such directory for static content and files are spread across folders of web site, than if you create following .htacces in the root of the site it will cache all static content on the web site by file extension:</p>
<pre><code>&lt;Files ~ \.(gif|png|jpg|css|js)&gt;
ExpiresActive On
Header set Cache-Control public
ExpiresByType image/.+  "access 15 days"
ExpiresByType text/css  "access 5 days"
ExpiresByType application/x-javascript "access 5 days"
ExpiresByType application/javascript "access 5 days"
&lt;/Files&gt;</code></pre>
<p>This configuration makes server send http-responses to clients with information that pictures are to be cached for 15 days and scripts and css-files for 5 days.</p>
<h2>2. Compress responses on the run</h2>
<p>In order to save some time on loading the content, you can compress it. All modern browsers are able to receive comressed gzip-traffic. Text files (html-files, css-files, scripts, json-data) can be easily compressed and allow you to save 20-90% of traffic. Same time, music and video files can hardly be compressed as they have already be sized with special codecs.  Here&#8217;s an example of <a href="http://www.helicontech.com/ape/doc/mod_gzip.htm">enabling gzip-compression</a>. Add the following line in .htaccess in the root of web site:</p>
<pre><code>SetEnvIf (mime text/.*) or (mime application/x-javascript) gzip=9</code></pre>
<p>As you can see, this configuration is quite simple. It&#8217;s enough to have all text documents (html, css files) and javascript-files compressed before going to the client&#8217;s side. It is worth saying, that server compresses responses only for those browsers, that support compressing. Browser informs server about its features through the headers of html-request.</p>
<h2>3. Cache dynamic responses at server side</h2>
<p>Often large amount of requests, addressed to database server, hinder the web site performance. For example, blog&#8217;s main page shows recent entries, recent comments, navigation menu, category list and tags. Those are several complicated requests to database. In case that information does not change often or the relevance is not vital, html-responses need to be cached without hesitation. You can choose to cache the blog&#8217;s main page once in 5-10 minutes. But that would be enough to improve main page performance in browser.  Practically, application developer must decide what pages need to be cached and for how long. Also he needs to bring into life caching mechanism &#8220;out of the box&#8221; . Unfortunatelly, that doesn&#8217;t happen most of the time. Likely, <a href="http://www.helicontech.com/ape/doc/mod_cache.htm">mod_cache</a> in Helicon Ape will simply and easily allow you to enable caching at server side.  mod_cache supports two types of cache: <a href="http://www.helicontech.com/ape/doc/mod_disk_cache.htm">disk cache</a> and <a href="http://www.helicontech.com/ape/doc/mod_mem_cache.htm">memory cache</a>. First type saves caches data on the drive, and the second one does on memory. Memory caching is more preferable. If your server doesn&#8217;t have enough RAM, use disk cache.  For example, to cache site&#8217;s homepage, we need to add the following lines in .htaccess in the root:</p>
<pre><code>Header set Cache-Control public,max-age=600
SetEnvIf request_uri ^/$ cache-enable=mem</code></pre>
<p>This configuration enforces caching of site&#8217;s homepage request for 10 min (600sec). Response are cached in memory.  <strong>Be careful!</strong> You need to enable caching carefully. For example, pages that need authentificaton mustn&#8217;t be cached as they contain private data and need to provide different information for different users. In any cases, caching must be taking application logic into account.  We&#8217;ve reviewed three simple steps for increasing the speed of your web site. Besides tangible speed-boost, which you will notice at once, the acceleration must well enhance your rating in search engine results.  <a href="http://www.helicontech.com/articles/wp-content/uploads/2011/01/fast-website.png"><img class="alignnone size-large wp-image-361" title="Website speed up graph" src="http://www.helicontech.com/articles/wp-content/uploads/2011/01/fast-website-1024x260.png" alt="Website speed up graph" width="640" height="162" /></a> You can see performance graph of <a href="http://www.helicontech.com">www.helicontech.com</a> made using Google Webmaster tools after a simple optimization.  So equip your site with these tricks and enjoy dual benefit!</p>
<img src="http://feeds.feedburner.com/~r/HeliconTechBlog/~4/su3KNOnZu0U" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.helicontech.com/articles/make-your-websites-work-faster/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://www.helicontech.com/articles/make-your-websites-work-faster/</feedburner:origLink></item>
		<item>
		<title>Exploding myths about mod_rewrite. Part 2.</title>
		<link>http://feedproxy.google.com/~r/HeliconTechBlog/~3/z7iPneZNYnQ/</link>
		<comments>http://www.helicontech.com/articles/exploding-myths-about-mod_rewrite-part-2/#comments</comments>
		<pubDate>Mon, 01 Nov 2010 13:34:55 +0000</pubDate>
		<dc:creator>Anton</dc:creator>
				<category><![CDATA[ISAPI_Rewrite]]></category>
		<category><![CDATA[CodeProject]]></category>
		<category><![CDATA[mod_rewrite]]></category>

		<guid isPermaLink="false">http://www.helicontech.com/articles/?p=312</guid>
		<description><![CDATA[This article is the anticipated sequel of “Exploding myths about mod_rewrite. Part 1” published more than a year ago. In this two-volume work (which may well become a three-volume one soon) we try to thoroughly explain each tiny issue/option of &#8230; <a href="http://www.helicontech.com/articles/exploding-myths-about-mod_rewrite-part-2/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>This article is the anticipated sequel of <a href="http://www.helicontech.com/articles/exploding-myths-about-mod_rewrite-part-i/" target="_blank">“Exploding myths about mod_rewrite. Part 1”</a> published more than a year ago. In this two-volume work (which may well become a three-volume one soon) we try to thoroughly explain each tiny issue/option of Helicon Ape <a href="http://www.helicontech.com/ape/doc/mod_rewrite.htm" target="_blank">mod_rewrite</a> (also true for Apache) to give you all the knowledge necessary to master it in its full. Part 2 devotes itself to contexts processing order.<br />
So, let’s start the story…</p>
<p><span id="more-312"></span></p>
<h3>Request processing contexts</h3>
<p>In the simplest case there are only two request processing contexts:</p>
<ol>
<li>server context (httpd.conf), and</li>
<li>“root folder” context (.htaccess)</li>
</ol>
<p>Server context is executed first and after that, if further processing is allowed (no redirect or proxy happened), root folder config is processed (if present).</p>
<p><a href="http://www.helicontech.com/articles/wp-content/uploads/2010/10/5.png"><img class="alignleft size-full wp-image-314" title="server config" src="http://www.helicontech.com/articles/wp-content/uploads/2010/10/5.png" alt="server-wide directive" width="571" height="375" /></a><br />
<em>Picture 1. Server-wide configuration (httpd.conf)</em></p>
<p><a href="http://www.helicontech.com/articles/wp-content/uploads/2010/10/4.png"><img class="alignleft size-full wp-image-315" title="htaccess config" src="http://www.helicontech.com/articles/wp-content/uploads/2010/10/4.png" alt="per-site directive" width="571" height="375" /></a><br />
<em>Picture 2. Per-site configuration (.htaccess)</em></p>
<p><a href="http://www.helicontech.com/articles/wp-content/uploads/2010/10/conf-htaccess.png"><img class="alignleft size-full wp-image-322" title="conf-htaccess" src="http://www.helicontech.com/articles/wp-content/uploads/2010/10/conf-htaccess.png" alt="" width="658" height="599" /></a><br />
<em>Picture 3. Processing order for the configs on Pictures 1 and 2</em></p>
<p>***<br />
Now let’s make it more complicated—we’ll have the rules in the root folder and in Directory1. The processing order then becomes:</p>
<ol>
<li>/.htaccess
<pre><code>DirectiveA</code></pre>
</li>
<li>/Directory1/.htaccess
<pre><code>DirectiveB</code></pre>
</li>
</ol>
<p><a href="http://www.helicontech.com/articles/wp-content/uploads/2010/10/conf-htaccess-dir.png"><img class="alignleft size-full wp-image-323" title="conf-htaccess-dir" src="http://www.helicontech.com/articles/wp-content/uploads/2010/10/conf-htaccess-dir.png" alt="" width="646" height="581" /></a><br />
<em>Picture 4. Processing order in case of several .htaccess files</em></p>
<p>For the request to <strong>http://localhost/index.html</strong> only the first context is applied, while for <strong>http://localhost/Directory1/index.html</strong> (and other requests to deeper subfolders) the merged context 1+2 is executed. In our case it’s:</p>
<pre><code>DirectiveA
DirectiveB</code></pre>
<p>Thus, the child context complements and refines the parent one (but not the server one). This is true for nearly all Apache/Ape modules <strong>EXCEPT</strong> <a href="http://www.helicontech.com/ape/doc/mod_rewrite.htm" target="_blank">mod_rewrite</a>. It’s one of a kind and behaves differently.</p>
<h3>mod_rewrite behavior</h3>
<p>Historically, or for convenience purposes, mod_rewrite contexts do not complement but <strong>COMPLETELY OVERRIDE</strong> each other. So, if we have two configs</p>
<ol>
<li>/.htaccess
<pre><code>RewriteRule a b</code></pre>
</li>
<li>/Directory1/.htaccess
<pre><code>RewriteRule b с</code></pre>
</li>
</ol>
<p>the resulting config to be applied to the request will be</p>
<pre><code>RewriteRule b c</code></pre>
<p>and NOT</p>
<pre><code>RewriteRule a b
RewriteRule b с</code></pre>
<p>which may be unobvious for newbies.</p>
<blockquote><p><strong>For experts!</strong> mod_rewrite has an option allowing to change this behavior and inherit the parent rules:</p>
<ol>
<li>/.htaccess
<pre><code>RewriteRule a b</code></pre>
</li>
<li>/Directory1/.htaccess
<pre><code># inherit parent rules
RewriteOptions inherit
RewriteRule b с</code></pre>
</li>
</ol>
<p>makes up the following merged config:</p>
<pre><code>RewriteRule b с
# parent rules are appended to the end of the merged config!
RewriteRule a b</code></pre>
</blockquote>
<h3>&lt;Directory&gt; section</h3>
<p>&lt;Directory&gt; section is equivalent in meaning to writing rules in the .htaccess located inside this directory. The only difference is that &lt;Directory&gt; lives in httpd.conf.<br />
If there are both &lt;Directory&gt; section and .htaccess for the same directory, they are merged; if the directives inside them interfere, the .htaccess directives are preferred.<br />
<a href="http://www.helicontech.com/articles/wp-content/uploads/2010/10/htaccess-directory.png"><img class="alignleft size-full wp-image-324" title="htaccess-directory" src="http://www.helicontech.com/articles/wp-content/uploads/2010/10/htaccess-directory.png" alt="" width="646" height="581" /></a><br />
<em>Picture 5. Processing order when there are both .htaccess and &lt;Directory&gt; for the same location</em></p>
<p>Let’s see how the configs are merged for the request to <strong>http://localhost/Directory1/Directory2/index.html</strong> if each directory has both &lt;Directory&gt; section and corresponding .htaccess file.<br />
<a href="http://www.helicontech.com/articles/wp-content/uploads/2010/10/many-directories.png"><img class="alignleft size-full wp-image-325" title="many-directories" src="http://www.helicontech.com/articles/wp-content/uploads/2010/10/many-directories.png" alt="" width="647" height="658" /></a><br />
<em>Picture 6. Processing order when there are several .htaccess files and several &lt;Directory&gt; sections which are applicable for the same request</em></p>
<p><strong>httpd.conf</strong></p>
<pre><code>&lt;Directory C:/inetpub/wwwroot/&gt;
DirectiveDirectoryA
&lt;/Directory&gt;

&lt;Directory C:/inetpub/wwwroot/Directory1/&gt;
DirectiveDirectoryB
&lt;/Directory&gt;

&lt;Directory C:/inetpub/wwwroot/Directory1/Directory2/&gt;
DirectiveDirectoryС
&lt;/Directory&gt;</code></pre>
<p><strong>/.htaccess</strong></p>
<pre><code>DirectiveA</code></pre>
<p><strong>/Directory1/.htaccess</strong></p>
<pre><code>DirectiveB</code></pre>
<p><strong>/Directory1/Directory2/.htaccess</strong></p>
<pre><code>DirectiveC</code></pre>
<p>The following logics is applied to form the merged config:</p>
<ol>
<li>First to execute is httpd.conf except for tagged sections:<br />
&lt;Directory&gt;<br />
&lt;DirectoryMatch&gt;<br />
&lt;Files&gt;<br />
&lt;FilesMatch&gt;<br />
&lt;Location&gt;<br />
&lt;LocationMatch&gt;<br />
&lt;VirtualHost&gt;</li>
<li>Distributed config is built up from the following parts:<br />
a.	empty context is created;<br />
b.	requested URL is divided into parts like:<br />
/<br />
/Directory1/<br />
/Directory1/Directory2/<br />
c.	physical path is defined for each virtual directory:<br />
/  &#8212;&gt; C:/inetpub/wwwroot/<br />
/Directory1/ &#8212;&gt; C:/inetpub/wwwroot/ Directory1/<br />
/Directory1/Directory2/&#8212;&gt; C:/inetpub/wwwroot/ Directory1/ Directory2/<br />
d. corresponding   section is found for each path;<br />
e. corresponding .htaccess  is found for each path</li>
</ol>
<p>The resulting sequence of directives will be:</p>
<pre><code>DirectiveDirectoryA
DirectiveA
DirectiveDirectoryB
DirectiveB
DirectiveDirectoryC
DirectiveC</code></pre>
<p>Usually directives&#8217; order is not so important, but not in case with mod_rewrite; that’s why understanding the principles of configs merging may dramatically reduce development and debugging times.</p>
<blockquote><p><strong>Note!</strong> &lt;DirectoryMatch&gt; sections are applied not to all parts of the request (see above) but only to the deepest part, and all matches are searched for, for example, if there are two sections:</p>
<pre><code>&lt;DirectoryMatch C:/inetpub/wwwroot/Directory1/Directory*/&gt;</code></pre>
<p>and</p>
<pre><code>&lt;DirectoryMatch C:/inetpub/wwwroot/Directory1/*/&gt;</code></pre>
<p>then both of them get into the merged config.</p></blockquote>
<h3>&lt;VirtualHost&gt; directive</h3>
<p>One should remember that everything written inside server context is applied to all requests and for all sites. Sometimes it may be necessary to limit the scope of directive to one or several sites and that’s the case to use &lt;VirtualHost&gt; section.<br />
&lt;VirtualHost&gt; can reside <strong>in httpd.conf only</strong>. It is merged with server config, i.e. complements it. In case of both .htaccess and &lt;VirtualHost&gt; section for the specific location, the latter has higher priority and can reject server settings for the specific site (in our case <em>localhost</em>).</p>
<pre><code>#httpd.conf
ServerDirective
&lt;VirtualHost localhost&gt;
VirtualHostDirectiveA
&lt;/VirtualHost&gt;</code></pre>
<p><strong>Note!</strong> mod_rewrite offers another way to restrict scope for the rules to specific host – RewriteCond %{HTTP_HOST}.<br />
The difference is that RewriteCond %{HTTP_HOST} must appear before each RewriteRule, while &lt;VirtualHost localhost&gt; groups all rules for <em>localhost</em> together and affects all of them. Compare:</p>
<pre><code>RewriteCond %{HTTP_HOST} localhost
RewriteRule . index.php  [L]
RewriteCond %{HTTP_HOST} localhost
RewriteRule about$ about.php  [L]</code></pre>
<p>and</p>
<pre><code>&lt;VirtualHost localhost&gt;
RewriteRule . index.php  [L]
RewriteRule about$ about.php  [L]
&lt;/VirtualHost&gt;</code></pre>
<p>On the other hand, the limitation of &lt;VirtualHost&gt; is that it can’t be used in .htaccess.<br />
<a href="http://www.helicontech.com/articles/wp-content/uploads/2010/10/virtualhost.png"><img class="alignleft size-full wp-image-326" title="virtualhost" src="http://www.helicontech.com/articles/wp-content/uploads/2010/10/virtualhost.png" alt="" width="646" height="605" /></a><br />
<em>Picture 7. Processing order when &lt;VirtualHost&gt; section is present in httpd.conf</em></p>
<blockquote><p><strong>Note!</strong> &lt;VirtualHost&gt; sections are <strong>NOT</strong> merged together – if there are several &lt;VirtualHost&gt;s matching the request, the one with the best match is applied. E.g.:</p>
<pre><code>&lt;VirtualHost localhost&gt;
&lt;VirtualHost localhost:80&gt;
&lt;VirtualHost *&gt;</code></pre>
<p>For request to <em><strong>localhost:80/page.html</strong></em> the second line will be executed, whereas for <em><strong>localhost/page.html</strong></em> the first one will fire.</p></blockquote>
<p>If &lt;Directory&gt; section is specified inside &lt;VirtualHost&gt; (which is possible), the processing order is as follows: &lt;Directory&gt; section of the main server config is accounted first, then &lt;Directory&gt; inside &lt;VirtualHost&gt; and after all – .htaccess.</p>
<p>Thus, the use of &lt;Directory&gt; section outside &lt;VirtualHost&gt; will lead to application of its (&lt;Directory&gt;) rules to all sites (in case they use this shared folder).<br />
<a href="http://www.helicontech.com/articles/wp-content/uploads/2010/10/directory-in-virtualhost.png"><img class="alignleft size-full wp-image-327" title="directory-in-virtualhost" src="http://www.helicontech.com/articles/wp-content/uploads/2010/10/directory-in-virtualhost.png" alt="" width="646" height="611" /></a><br />
<em>Picture 8. Processing order when there are &lt;VirtualHost&gt; and &lt;Directory&gt; sections as well as .htaccess</em></p>
<h3>&lt;Files&gt; and &lt;FilesMatch&gt; sections</h3>
<p>These two behave similar to &lt;DirectoryMatch&gt; but are used for file names, not for the full path.<br />
E.g., for <em>http://localhost/Directory1/index.html#top</em> they will find the correspondence in file system <em>C:\inetpub\wwwroot\Directory1\<strong>index.html</strong></em> and will merge all &lt;FilesMatch&gt; sections valid for this file name (e.g. &lt;FilesMatch *.html&gt; and &lt;FilesMatch index.*&gt; will be merged).<br />
<strong>Note!</strong> &lt;Files&gt; and &lt;FilesMatch&gt; may reside in .htaccess as well!</p>
<h3>&lt;Location&gt; and &lt;LocationMatch&gt; sections</h3>
<p>Are applied to the corresponding virtual path, which for <em>http://localhost/Directory1/index.html#top</em> is <strong>/Directory1/index.html</strong>.</p>
<h3>Summary</h3>
<p>Let’s now put it all together. Here’s the final sequence of sections:</p>
<ol>
<li>httpd.conf &lt;Directory&gt;</li>
<li>httpd.conf &lt;VirtualHost&gt;&lt;Directory&gt;</li>
<li>.htaccess</li>
<li>.htaccess &lt;Files&gt;</li>
<li>httpd.conf &lt;DirectoryMatch&gt;</li>
<li>httpd.conf &lt;VirtualHost&gt;&lt;DirectoryMatch&gt;</li>
<li>httpd.conf &lt;Files&gt;</li>
<li>httpd.conf &lt;FilesMatch&gt;</li>
<li>httpd.conf &lt;VirtualHost&gt;&lt;Files&gt;</li>
<li>httpd.conf &lt;VirtualHost&gt;&lt;FilesMatch&gt;</li>
<li>httpd.conf &lt;Location&gt;</li>
<li>httpd.conf &lt;LocationMatch&gt;</li>
<li>httpd.conf &lt;VirtualHost&gt;&lt;Location&gt;</li>
<li>httpd.conf &lt;VirtualHost&gt;&lt;LocationMatch&gt;</li>
</ol>
<p>***<br />
Seems every aspect of configs processing has been covered. We understand that this article may look somewhat sophisticated, but we are sure there are enthusiasts who’ll find it helpful.</p>
<img src="http://feeds.feedburner.com/~r/HeliconTechBlog/~4/z7iPneZNYnQ" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.helicontech.com/articles/exploding-myths-about-mod_rewrite-part-2/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		<feedburner:origLink>http://www.helicontech.com/articles/exploding-myths-about-mod_rewrite-part-2/</feedburner:origLink></item>
		<item>
		<title>IIS reverse proxy and load balancer with web admin panel</title>
		<link>http://feedproxy.google.com/~r/HeliconTechBlog/~3/T1rL5YM-hZQ/</link>
		<comments>http://www.helicontech.com/articles/web-interface-for-mod_proxy-load-balancer/#comments</comments>
		<pubDate>Tue, 28 Sep 2010 15:35:59 +0000</pubDate>
		<dc:creator>ruslan</dc:creator>
				<category><![CDATA[Helicon Ape]]></category>
		<category><![CDATA[CodeProject]]></category>
		<category><![CDATA[load balancer]]></category>
		<category><![CDATA[mod_proxy]]></category>
		<category><![CDATA[performance]]></category>

		<guid isPermaLink="false">http://www.helicontech.com/articles/?p=297</guid>
		<description><![CDATA[Since build 3.0.0.50 Helicon Ape offers a web interface for the load balancer. Web interface illustrates the current state of load balancers and their nodes. The following info is shown for the balancer nodes: Worker URL; Route: name of balancer &#8230; <a href="http://www.helicontech.com/articles/web-interface-for-mod_proxy-load-balancer/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Since build 3.0.0.50 Helicon Ape offers a web interface for the load balancer.</p>
<p><span id="more-297"></span></p>
<p>Web interface illustrates the current state of load balancers and their nodes.</p>
<p><img class="alignnone size-full wp-image-307" title="load balancer web interface" src="http://www.helicontech.com/articles/wp-content/uploads/2010/09/lbwebui.png" alt="load balancer web interface" width="600" height="401" /></p>
<p>The following info is shown for the balancer nodes:</p>
<ul>
<li>Worker URL;</li>
<li>Route: name of balancer member;</li>
<li>RouteRedir: name of the node to redirect requests to in case of inaccessibility;</li>
<li>Factor: mamber relative weight;</li>
<li>Status: state of member;</li>
<li>Elected: how many times the node was chosen to process request, i.e. practically the number of processed requests;</li>
<li>Transmitted: number of bytes sent to the node;</li>
<li>Received: number of bytes received from the node;</li>
<li>EMA ResponseTime: exponential moving average of response time</li>
<li>Status TTL: period of time for which the node is excluded from the balancing process due to inaccessibility.</li>
</ul>
<p>Here&#8217;s how you can set this handler to enjoy all this stuff:</p>
<pre><code class="apache">&lt;Location /balancer-manager/&gt;
  SetHandler balancer-manager
  Order allow,deny
  Allow from 127.0.0.7 ::1 localhost
&lt;/Location&gt;</code></pre>
<p>Please pay attention that the URL to which the handler is mapped must be secured from unauthorized access. For instance, the access must be granted for local machine only (see example above) or basic/digest authorization must be enabled.</p>
<p>Feel free to try our web interface for the load balancer to facilitate control and get comprehensible statistics for any node and any balancer.</p>
<p><em>Best wishes,<br />
Ruslan &#8211; Helicon Tech Team</em></p>
<img src="http://feeds.feedburner.com/~r/HeliconTechBlog/~4/T1rL5YM-hZQ" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.helicontech.com/articles/web-interface-for-mod_proxy-load-balancer/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://www.helicontech.com/articles/web-interface-for-mod_proxy-load-balancer/</feedburner:origLink></item>
		<item>
		<title>Load balancing with Helicon Ape mod_proxy</title>
		<link>http://feedproxy.google.com/~r/HeliconTechBlog/~3/1zL5FozxLTs/</link>
		<comments>http://www.helicontech.com/articles/load-balancing-with-helicon-ape-mod_proxy/#comments</comments>
		<pubDate>Mon, 27 Sep 2010 10:27:28 +0000</pubDate>
		<dc:creator>ruslan</dc:creator>
				<category><![CDATA[Helicon Ape]]></category>
		<category><![CDATA[load balancer]]></category>
		<category><![CDATA[mod_proxy]]></category>

		<guid isPermaLink="false">http://www.helicontech.com/articles/?p=262</guid>
		<description><![CDATA[Helicon Ape mod_proxy module provides simple way to configure load balancer. This article is giving explicit instructions of how to configure and test such load balancer. Goal Create simple cluster in which one front-end server (www.site.com), accessible via Internet, proxies &#8230; <a href="http://www.helicontech.com/articles/load-balancing-with-helicon-ape-mod_proxy/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Helicon Ape mod_proxy module provides simple way to configure load balancer. This article is giving explicit instructions of how to configure and test such load balancer.</p>
<p><span id="more-262"></span></p>
<h3>Goal</h3>
<p>Create simple cluster in which one front-end server (www.site.com), accessible via Internet, proxies some application operation in an intranet (not accessible via Internet).</p>
<p><a href="http://www.helicontech.com/articles/wp-content/uploads/2010/09/load-balancing1.png"><img class="alignnone size-full wp-image-280" title="load balancer with Helicon Ape mod_proxy" src="http://www.helicontech.com/articles/wp-content/uploads/2010/09/load-balancing1.png" alt="load balancer with Helicon Ape mod_proxy" width="600" height="384" /></a></p>
<p>To improve stability (resistance to failures) and speed the application will run on internal servers (app1.site.com &amp; app2.site.com) which will distribute requests between themselves. In case one server is down (scheduled maintenance, upgrade, breakdown), all requests will be directed to another server.</p>
<p>Requests between the servers are distributed based on the response time value. I.e. the quicker back-end returns responses (better copes with the load), the more requests it will get.</p>
<p>The application uses sessions, so if the request contains the cookie with session id, this request must be assigned to the back-end which initiated this session. The cookie is of the following format <code>[session_data]![backend_id]</code>.</p>
<p>Static content is also shared between two internal servers (static1.site.com &amp; static2.site.com) so they need to distribute it among themselves as well.</p>
<h3>Configuration</h3>
<p>Here&#8217;s the sample configuration of the balancer described above:</p>
<pre><code class="apache">&lt;VirtualHost www.site.com&gt;

# route all requests starts with /static/ to static balancer
ProxyPass /static/ balancer://static-balancer/
&lt;Proxy balancer://static-balancer/&gt;
  # describe static balancer members
  BalancerMember http://static1.site.com/media/
  BalancerMember http://static2.site.com/media/
&lt;/Proxy&gt;
# enable reversing of response redirects
ProxyPassReverse /static/ http://static1.site.com/media/
ProxyPassReverse /static/ http://static2.site.com/media/

# route all other requests to application balancer
ProxyPass / balancer://app-balancer/ stickysession=sessionid routeregex=!(.*)$
&lt;Proxy balancer://app-balancer/&gt;
  # describe application balancer members
  BalancerMember http://app1.site.com/ route=app1
  BalancerMember http://app2.site.com/ route=app2
&lt;/Proxy&gt;
# enable reversing of response redirects
ProxyPassReverse / http://app1.site.com/
ProxyPassReverse / http://app1.site.com/
# enable reversing of domain in Set-Cookie headers
ProxyPassReverseCookieDomain app1.site.com www.site.com
ProxyPassReverseCookieDomain app2.site.com www.site.com

&lt;/VirtualHost&gt;
</code></pre>
<h3>What was that?</h3>
<p>And here&#8217;s the explanation of the code above.</p>
<pre><code>&lt;VirtualHost www.site.com&gt; ... &lt;/VirtualHost&gt;</code></pre>
<p>section conditions that all directives inside it are applied only to the requests to www.site.com. This is especially important when the server manges several sites.</p>
<pre><code class="apache">ProxyPass /static/ balancer://static-balancer/</code></pre>
<p>directive tells mod_proxy that all requests beginning with <code>/static/</code> must be proxied via <em>static-balancer</em> balancer.</p>
<pre><code>&lt;Proxy balancer://static-balancer/&gt; ... &lt;/Proxy&gt;</code></pre>
<p>section stores directives for <em>static-balancer</em>, members of this balancer in particular.</p>
<pre><code>BalancerMember http://static1.site.com/media/</code></pre>
<p>directives define balancer members: their working URL and load factor.</p>
<pre><code>ProxyPassReverse /static/ http://static1.site.com/media/</code></pre>
<p>directives are needed to reverse proxy the redirects coming from the back-ends. All redirects with URLs like  <code>http://static1.site.com/media/[path]</code> will be substituted with <code>http://www.site.com/static/[path]</code>.</p>
<p>These were the rules for static content balancer. Now let&#8217;s look at the balancer for the application itself.</p>
<pre><code>ProxyPass / balancer://app-balancer/ stickysession=sessionid routeregex=^(.*)$</code></pre>
<p>directive tells mod_proxy that all other requests must be proxied through  <em>app-balancer</em> balancer. As the rule for /static/ folder is above, it will be applied earlier.</p>
<p>The balancing must be relative to back-end response time (default <code>lbmethod=byresponsetime</code>), i.e. the back-end with faster response time will get more requests with probability reverse-proportional to the response time. Response time for each back-end is averaged according to <a href="http://en.wikipedia.org/wiki/Exponential_smoothing#The_exponential_moving_average">exponential moving average</a> algorythm.</p>
<p><code>stickysession=sessionid</code> parameter defines the name of the cookie storing the session id, and <code>routeregex=!(.*)$</code> defines the regular expression to match the request route in the cookie value. In our case it&#8217;s everything after the exclamation mark (&#8216;!&#8217;).</p>
<pre><code>BalancerMember http://app1.site.com/ route=app1</code></pre>
<p>directives define <em>app-balancer</em> members. <code>route=app1</code> assignes the name to this node (route) which will be used to direct requests with corresponding sticky session.</p>
<p><code>ProxyPassReverse</code> and <code>ProxyPassReverseCookieDomain</code> directives serve to reverse proxy redirects (Location header) and domains in cookies (Set-Cookie header).</p>
<h3>Other types of load balancers</h3>
<p>The method of load balancing is defined by <code>lbmethod</code> parameter of <code>ProxyPass</code> directive and may be one of the following:</p>
<ul>
<li><code>byrequests</code> to perform weighted request counting;</li>
<li><code>bytraffic</code> to perform weighted traffic byte count balancing;</li>
<li><code>random</code> to perform weighted random balancing;</li>
<li><code>byresponsetime</code> to perform weighted response time balancing.</li>
</ul>
<h3>Nodes accessibility</h3>
<p>The node is considered inaccessible if the balancer cannot connect to it. In such case the balancer marks it as <code>IN_ERROR</code> and excludes from the balancing process. In our situation it means that if app1.site.com is not accessible (e.g. due to upgrade), then the balancer will route all requests to app2.site.com.  <code>statusttl</code> parameter of <code>BalancerMember</code> directive defines the period of time in seconds after which it&#8217;ll retry to establish connection to this node. The default is 300 secs.</p>
<p>You can learn more about mod_proxy directives and features from <a href="http://www.helicontech.com/ape/doc/mod_proxy.htm">mod_proxy manual</a>.</p>
<p>Best wishes,<br />
Helicon Tech Team</p>
<img src="http://feeds.feedburner.com/~r/HeliconTechBlog/~4/1zL5FozxLTs" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.helicontech.com/articles/load-balancing-with-helicon-ape-mod_proxy/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.helicontech.com/articles/load-balancing-with-helicon-ape-mod_proxy/</feedburner:origLink></item>
	</channel>
</rss>

