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

<channel>
	<title>Helicon Tech Blog</title>
	<atom:link href="http://www.helicontech.com/articles/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.helicontech.com/articles</link>
	<description>Web Server Enhancements</description>
	<lastBuildDate>Fri, 03 Feb 2012 08:52:04 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Ruby on Rails on Windows in production</title>
		<link>http://www.helicontech.com/articles/ruby-on-rails-on-windows-in-production/</link>
		<comments>http://www.helicontech.com/articles/ruby-on-rails-on-windows-in-production/#comments</comments>
		<pubDate>Thu, 02 Feb 2012 12:49:01 +0000</pubDate>
		<dc:creator>Slov</dc:creator>
				<category><![CDATA[Helicon Zoo]]></category>
		<category><![CDATA[CodeProject]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://www.helicontech.com/articles/?p=731</guid>
		<description><![CDATA[More and more Windows-developers cast a glance at Ruby – dynamic high-level programming language. One of the reasons of this interest is a framework for web applications – Ruby on Rails. Developing with Rails is easy and fun. Due to &#8230; <a href="http://www.helicontech.com/articles/ruby-on-rails-on-windows-in-production/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>More and more Windows-developers cast a glance at Ruby – dynamic high-level programming language. One of the reasons of this interest is a framework for web applications – Ruby on Rails. Developing with Rails is easy and fun. Due to high dynamics of Ruby developers get a wide range of additional tools, and with rather few lines of code you can have rich functionality. This article is primarily aimed at rookie web-programmers and those who are thinking of sticking to Ruby on Rails. The following issues will be outlined below:</p>
<ul>
<li>Installing work environment</li>
<li>Writing a simple app</li>
<li>Deploying the app on the server</li>
</ul>
<p>As a resume you’ll see the results of the tests contrasting performance of Ruby-apps run (in different modes) on Windows and Ubuntu.<span id="more-731"></span></p>
<h2>Setting-up environment</h2>
<p>First, we need to download and install Web Platform Installer, run it, click Options and add the link to<em> Helicon Zoo Feed</em>: <a href="http://www.helicontech.com/zoo/feed/">http://www.helicontech.com/zoo/feed/</a> into the «Display additional scenarios» field.</p>
<p><img class="alignnone size-full wp-image-754" title="zoo-feed" src="http://www.helicontech.com/articles/wp-content/uploads/2012/02/zoo-feed.png" alt="" width="515" height="356" /></p>
<p>In result, WebPI will add Zoo tab with «Applications», «Packages», «Modules» and «Engines» sections.</p>
<p><img class="alignnone size-full wp-image-736" title="zoo-tab" src="http://www.helicontech.com/articles/wp-content/uploads/2012/02/zoo-tab.png" alt="" width="557" height="444" /></p>
<h2>Installing Ruby on Rails</h2>
<p>In Engines section you can choose engines to be installed including Ruby on Rails 3.1 and 2.3. Ruby version 1.8 and 1.9 are also available. By default Rails 3.x installs Ruby 1.9 as a dependency, while Rails 2 will install Ruby 1.8.</p>
<p>For convenience the Packages section offers <em>Ruby</em><em> </em><em>Hosting</em><em> </em><em>Package</em> which includes the following components:</p>
<ul>
<li>Ruby 1.8.7 andRuby 1.9.3;</li>
<li>Rails 2.3.11, 3.0.10 and 3.1;</li>
<li>Ruby DevKit (for assembling C-extensions);</li>
<li>Popular gems: mysql2, pg, sqlite3, mongo_mapper, tiny_tds, activerecord-sqlserver-adapter, devise, authlogic, jekyll, formtastic, will_paginate, Sinatra, ramaze, camping-omnibus, Thin, Goliath.</li>
</ul>
<p><img class="alignnone size-full wp-image-744" title="packages-tab" src="http://www.helicontech.com/articles/wp-content/uploads/2012/02/packages-tab.png" alt="" width="557" height="401" /></p>
<h2>Creating your first web-site</h2>
<p>A convenient way to create new web-app is using WebMatrix and IIS Express. On Zoo tab, under Packages section in WebPI you can find <em>WebMatrix</em><em> </em><em>Templates</em> package, offering different templates including the one for Ruby on Rails.</p>
<p>If you don’t yet have WebMatrix, it will be automatically installed with the <em>WebMatrix</em><em> </em><em>Templates</em> package. Keep in mind that downloading and installing all packages may take some time. Having templates installed run WebMatrix and on the main page select <em>Site </em><em>from</em><em> </em><em>template</em> and then <em>Rails</em><em> </em><em>Site</em>.</p>
<p><img class="alignnone size-full wp-image-752" title="wm-rails-site" src="http://www.helicontech.com/articles/wp-content/uploads/2012/02/wm-rails-site.png" alt="" width="552" height="481" /></p>
<p>After you created the Rails Site, follow the given URL or press Run to see the page with instructions.</p>
<p><img class="alignnone size-full wp-image-750" title="welcome-blank-project" src="http://www.helicontech.com/articles/wp-content/uploads/2012/02/welcome-blank-project.png" alt="" width="731" height="585" /></p>
<p>The template is designed for development of Rails 2.3, 3.0 or 3.1 applications. At the moment there’s no application under the site folder, only configuration files. Let’s create it using the command:</p>
<pre>rails new .</pre>
<p>If you don’t explicitly specify the Rails version to use, it will use the latest available one. As in our case we installed Ruby Hosting Package, which includes three Rails versions and the latest of them is 3.1, the app template will be created based on Rails 3.1.</p>
<p>If we now refresh the page, we’ll see standard Ruby on Rails welcome page:</p>
<p><img class="alignnone size-full wp-image-751" title="welcome-rails" src="http://www.helicontech.com/articles/wp-content/uploads/2012/02/welcome-rails.png" alt="" width="586" height="517" /></p>
<h2>Development environment</h2>
<p>For code editing you’ll need an editor or dev environment. If you prefer IDE with debugger and refactoring tools, consider one of the following options:</p>
<ul>
<li>Aptana (free, <a href="http://aptana.org/">http://aptana.org</a>)</li>
<li>NetBeans (free, <a href="http://netbeans.org/">http://netbeans.org</a>)</li>
<li>RubyMine (commercial, <a href="http://www.jetbrains.com/ruby/">http://www.jetbrains.com/ruby/</a>)</li>
</ul>
<p>Each of these offers a bunch of development and testing tools for Ruby apps and supports version control.</p>
<p>For those who will make do with simpler solutions there are:</p>
<ul>
<li>KomodoEdit (free, <a href="http://www.activestate.com/komodo-edit">http://www.activestate.com/komodo-edit</a>)</li>
<li>Redcar (free, <a href="http://redcareditor.com/">http://redcareditor.com/</a>)</li>
<li>SciTE (free, <a href="http://www.scintilla.org/SciTE.html">http://www.scintilla.org/SciTE.html</a>)</li>
<li>E TextEditor (commercial, <a href="http://e-texteditor.com/">http://e-texteditor.com/</a>)</li>
</ul>
<p>For our app we used Aptana:</p>
<p><img class="alignnone size-full wp-image-737" title="aptana" src="http://www.helicontech.com/articles/wp-content/uploads/2012/02/aptana.png" alt="" width="718" height="589" /></p>
<h2>MVC</h2>
<p>Ruby on Rails is based on the MVC architecture (model, view, controller). This approach has several advantages:</p>
<ul>
<li>Isolation of business logic from interface;</li>
<li>Less code repetition (DRY principle — don’t repeat yourself);</li>
<li>Relatively simple development hanks to strict code distribution based on purpose (e.g. the code for HTML form output is not mixed with the code for DB processing).</li>
</ul>
<p><strong><em>Model</em></strong> defines the database structure in terms of object-oriented programming. In Rails <em>model</em> is an ordinary class inheriting all necessary functions from ActiveRecord::Base class. Instance (object) of this class defines one line from the corresponding database. Thus, models conceal the peculiarities of interaction with particular DBMS from developer.</p>
<p><strong><em>View</em></strong> is the interface shown to users. On this stage developer creates templates which are transformed into HTML, CSS orJavaScript code.</p>
<p><strong><em>Controller</em></strong> connects model with view. It’s usually controller that contains the main logic. Essentially, controllers are Ruby classes. Each public method of controller is called action. If you have controller named “Home” and it contains the method named “index”, then running /home/index in browser will evoke “index” action.</p>
<p>When a request comes to the application, the routing mechanism (in config/routes.rb file) decides which controller cares about that type of requests. Aside from the URL a set of other conditions may be taken into consideration, e.g. you can assign different controllers for different browsers, for mobile clients etc.</p>
<p>So, having chosen the controller, it defines what action will process the request. At this point one can also apply numerous conditions. The action itself performs some calculations and DB-related operations. When the action is finished the <em>view</em> comes on the scene. The data from DB or some result are transmitted to the templates. Then the HTML page is generated from the templates (there are templates from CSS and JavaScript as well) and the response page in sent to the user.</p>
<h2>Writing the application</h2>
<p>The classic example of Rails app is the simplest blog. We won’t ignore this tradition. So, let’s delete the welcome file public/index.html and create controller “Home” with action “index” – this is going to be the blog main page. This is done with the following line run from app folder:</p>
<pre><code>rails g controller home index</code></pre>
<p>If we now request /home/index, we’ll get the page from the template created for “index” action.</p>
<p><img class="alignnone size-full wp-image-741" title="hello-index" src="http://www.helicontech.com/articles/wp-content/uploads/2012/02/hello-index.png" alt="" width="442" height="282" /></p>
<p>Afterwards, we’ll create a simple Post model which will define each blog entry in the DB. In Ruby code the model is a class and it is represented in DB as a table. Thus, the object of Post class is a line in the corresponding table in database.</p>
<p>To create model you can simply run “rails g model Post&#8230;” but let’s make use of a very handy tool – scaffolding. The “rails g scaffold” command creates not only the model class itself and tests for it, but also actions drafts and views templates for adding, editing and removing model objects. If we execute this</p>
<pre><code>rails g scaffold Post name:string title:string content:text</code></pre>
<p>we’ll get “Post”model in app\models\post.rb, “Posts” controller in app\controllers\posts_controller.rb with actions index, show, new, edit, update, create and destroy, plus a DB migration scenario in db\migrate. The command will also have created the headers for tests and HTML templates. Notice that we haven’t yet written a single line of code!</p>
<p>Next, we’ll run the command to create the database (if it’s not yet created) and the table “posts” with the fields “name”, “title” and“context”:</p>
<pre><code>rake db:migrate</code></pre>
<p>The command for database migration is applied for creating and editing database structure in accordance with our object model. It should be executed every time you make changes to the application model. All the magic of matching the DB structure with our model is done automatically and all the data stored in the database are retained.</p>
<p>FYI, in this example we use SQLite which is default for Rails. However Rails can work with many other DBMS hiding details of their cooperation from the user.</p>
<p>Actions of “Post” controller are accessible at /posts/ address.</p>
<p><img class="alignnone size-full wp-image-749" title="posts-controller" src="http://www.helicontech.com/articles/wp-content/uploads/2012/02/posts-controller.png" alt="" width="442" height="282" /></p>
<p>If you press “New post”, you’ll see the form:</p>
<p><img class="alignnone size-full wp-image-742" title="new-post" src="http://www.helicontech.com/articles/wp-content/uploads/2012/02/new-post.png" alt="" width="257" height="463" /></p>
<p>After filling all fields we get to the new post page:</p>
<p><img class="alignnone size-full wp-image-748" title="post-created" src="http://www.helicontech.com/articles/wp-content/uploads/2012/02/post-created.png" alt="" width="482" height="209" /></p>
<p>Note that there was still no code written. Now let’s do some editing. For instance, we may need to make post name and post title obligatory fields so that corresponding cells in the DB are always non-empty. Luckily, Rails provides very simple validation mechanism. We should just fix the model file as follows:</p>
<pre>class Post &lt; ActiveRecord::Base
      validates :name,  :presence =&gt; true
      validates :title, :presence =&gt; true,
                :length =&gt; { :minimum =&gt; 5 }
end</pre>
<p>In there we specify that “name”and“title” fields are obligatory and “title” should contain not less than 5 characters. No need to apply migration after this change as validators are not directly related to database; the check is performed on the level of Ruby code.</p>
<p>If you now leave the “name” field empty, you’ll get an error:</p>
<p><img class="alignnone size-full wp-image-743" title="new-post-error" src="http://www.helicontech.com/articles/wp-content/uploads/2012/02/new-post-error.png" alt="" width="463" height="547" /></p>
<p>Let’s make it a little more complicated and add the comments feature. We’ll create a “Comment” model with the following command:</p>
<pre>rails g model Comment commenter:string body:text post:references</pre>
<p>Pay attention to “post:references” parameter. It connects «comments» table with “posts” table.</p>
<p>Now refresh the database:</p>
<pre>rake db:migrate</pre>
<p>next, we’ll set up the relation “has many” for Post model:</p>
<pre>class Post &lt; ActiveRecord::Base
      validates :name,  :presence =&gt; true
      validates :title, :presence =&gt; true,
                :length =&gt; { :minimum =&gt; 5 }

      has_many :comments, :dependent =&gt; :destroy
end</pre>
<p>The code is intuitively clear. Each Post object may have a number of comments. “:dependent =&gt; :destroy” tells that when post is deleted all comments are deleted as well. As we didn&#8217;t use scaffolding this time to create a model for comments, we now need to generate corresponding controller:</p>
<pre>rails g controller Comments</pre>
<p>In <em>config\routes.rb</em> file replace “resources :posts do” with:</p>
<pre>resources :posts do
   resources :comments
end</pre>
<p>In this way we specify how the “comments” controller will be available. In our case it’s put into “posts”, so the links will look like <a href="http://localhost:41639/posts/1/comments/3">http://localhost:41639/posts/1/comments/3</a>.</p>
<p>Then we need to refresh the template <em>app\views\posts\show.html.erb</em> so that it will become possible to add comments. After:</p>
<pre>&lt;p&gt;
  &lt;b&gt;Content:&lt;/b&gt;
  &lt;%= @post.content %&gt;
&lt;/p&gt;</pre>
<p>add the following code:</p>
<pre>&lt;h2&gt;Comments&lt;/h2&gt;
&lt;% @post.comments.each do |comment| %&gt;
  &lt;p&gt;
    &lt;b&gt;Commenter:&lt;/b&gt;
    &lt;%= comment.commenter %&gt;
  &lt;/p&gt;
  &lt;p&gt;
    &lt;b&gt;Comment:&lt;/b&gt;
    &lt;%= comment.body %&gt;
  &lt;/p&gt;
  &lt;p&gt;
    &lt;%= link_to 'Destroy Comment', [comment.post, comment],
                :confirm =&gt; 'Are you sure?',
                :method =&gt; :delete %&gt;
  &lt;/p&gt;

&lt;% end %&gt;

&lt;h2&gt;Add a comment:&lt;/h2&gt;
&lt;%= form_for([@post, @post.comments.build]) do |f| %&gt;
  &lt;div class="field"&gt;
    &lt;%= f.label :commenter %&gt;&lt;br /&gt;
    &lt;%= f.text_field :commenter %&gt;
  &lt;/div&gt;
  &lt;div class="field"&gt;
    &lt;%= f.label :body %&gt;&lt;br /&gt;
    &lt;%= f.text_area :body %&gt;
  &lt;/div&gt;
  &lt;div class="actions"&gt;
    &lt;%= f.submit %&gt;
  &lt;/div&gt;
&lt;% end %&gt;</pre>
<p><img class="alignnone size-full wp-image-739" title="comments-form" src="http://www.helicontech.com/articles/wp-content/uploads/2012/02/comments-form.png" alt="" width="619" height="532" /></p>
<p>Finally, we’ll define the logic of controller operation in a<em>pp\controllers\comments_controller.rb</em></p>
<pre>class CommentsController &lt; ApplicationController
  def create
    @post = Post.find(params[:post_id])
    @comment = @post.comments.create(params[:comment])
    redirect_to post_path(@post)
  end

  def destroy
    @post = Post.find(params[:post_id])
    @comment = @post.comments.find(params[:id])
    @comment.destroy
    redirect_to post_path(@post)
  end
end</pre>
<p>And everything is ready for adding comments to the post:</p>
<p><img class="alignnone size-full wp-image-770" title="comments-form-with-comment" src="http://www.helicontech.com/articles/wp-content/uploads/2012/02/comments-form-with-comment.png" alt="" width="451" height="549" /></p>
<p>&nbsp;</p>
<p>The basic functionality is implemented. As the last step we’ll protect some of the actions, so that unwanted people don’t have access to them. The more comprehensive way is to use registration, sessions, cookies etc., but to stay simple we’ll take Basic authentication, the more so because in Rails we need only one line to enable it. Put the following in posts_controller.rb:</p>
<pre> http_basic_authenticate_with :name =&gt; "admin", :password =&gt; "123",
                              :except =&gt; [:index, :show]</pre>
<p>We have hard coded the login and password. “:except”parameter excludes “:index” and “:show” actions as they don’t need authentication.</p>
<p><img class="alignnone size-full wp-image-738" title="auth" src="http://www.helicontech.com/articles/wp-content/uploads/2012/02/auth.png" alt="" width="543" height="465" /></p>
<h2>Deploying on server</h2>
<p>So, we’ve created the application and now, logically, want publish it to Internet. For that purpose we’ll set up Windows server to work with Rails in production. We’ll have to repeat several steps from the beginning of the article which were used to install developmet environment:</p>
<ol>
<li>install Microsoft Web Platform Installer;</li>
<li>add Helicon Zoo feed;</li>
<li>install Ruby Hosting Package from Zoo repository.</li>
</ol>
<p>Before installation make sure WebPI is set up to install applications for IIS and not for IIS Express. After these three steps are completed the server is ready to host our application. For the moment the following server platforms are supported: Windows Server 2008 and 2008 R2, 32-and 64-bit versions.</p>
<p>So, first, we create an empty web-site via IIS manager or your hosting panel. Then upload your application to the server via FTP or WebDeploy. In case with WebDeploy the folders will be also given proper permissions automatically, if needed. You can also use Git or any other version control system and deployment system, but that falls beyond the scope of this article.</p>
<p>The application will be executed on Windows Server under IIS with the help of Helicon Zoo Module. This module was initially designed as a hosting solution, so all applications are isolated and do not interfere. The module with its default options works in automatic mode, creating one worker process by default, when the load is low and increasing the number of workers up to the number of CPU cores of the server providing maximal performance under heavy loads.</p>
<p>Helicon Zoo applies the concept of engines and applications. The engines section define what to run and how, on which protocol and port, what maximal number of workers are allowed and other global settings which are defined in applicationHost.config. Then, under the site you can create an application using specific engine and send all parameters necessary for this app’s operation to it. This concept allows for separation of hosting administrator duties from the clients’ burden (and client from client as well). You can learn more about Helicon Zoo Module and its settings here: <a href="http://www.helicontech.com/zoo/module.htm">http://www.helicontech.com/zoo/module.htm</a></p>
<p>Please pay attention to deploy.rb file in the root of the site and DEPLOY_FILE and DEPLOY_LOG parameters in web.config. Zoo executes deploy.rb upon each start of IIS application pool. This approach may appear especially helpful for those who don’t have administrator privileges on the server. As for deployment you’ll probably need to do “bundle install”or apply database migration, you can simply restart your application on the server and deploy.rb will be executed automatically. There is pre-defined deploy.rb file in the Ruby on Rails application template with most popular commands.</p>
<p>It’s worth mentioning that deploy.rb script is executed by the same Windows user that runs IIS application pool. As a rule this user has rather limited permissions that should be accounted for when you write your commands. As an example, ordinary “bundle install” command may lead to error because the user is not allowed to write directly into Ruby installation folder. Way out: save all gems under the site in a special folder “vendor/gems” by executing “bundle package” command in the application folder before sending it to the server. And in deploy.rb put the command “bundle install &#8211;local –path vendor/gems”.</p>
<p>The errors occurring for deploy-script may be logged in the file specified in DEPLOY_LOG environment variable.</p>
<p>The last issue to point out during deployment is RACK_ENV variable in web.config. In web.config created from WebMatrix template the RACK_ENV variable contains the value “development”. This enables Rails in the mode more suitable for development. When you put the application on the server, change the value to “production”. BTW, “production” is actually default.</p>
<h2>Performance tests</h2>
<p>Machine used as a server contained Core 2 Quad 2.4 Ghz, 8 Gb RAM, 1Gb LAN. For load generation we took more powerful PC and Apache Benchmark tool with a command “<em>ab.exe -n 100000 -c 100 –k</em>”. For Apache and Nginx servers we used Ubuntu 11.04 Server x64. IIS 7 tests were run on Windows Server 2008 R2. No virtual machined where used – bare hardware.</p>
<p>We’ve conducted three test scenarios:</p>
<ol>
<li>Rails had to output the current time in high resolution. The time was chosen to ensure the response doesn&#8217;t come from cache;</li>
<li>Rails read from MySQL database and;</li>
<li>Rails performed writing into MySQL  database.</li>
</ol>
<p>We performed tests with Ruby 1.9.3, Rails 3.1.1 and MySQL 5.1.54. in case of HTTP transport, Thin acted as a backend HTTP service. Neither Unicorn nor Passenger work for Windows. So, there were three configurations for testing: Windows + IIS 7.5 + Helicon Zoo + Thin, Ubuntu + Apache + Passanger, Ubuntu + Nginx + Thin.</p>
<p>Below are tests results (in requests per second):</p>
<p><img class="alignnone size-full wp-image-747" title="perf-time" src="http://www.helicontech.com/articles/wp-content/uploads/2012/02/perf-time.png" alt="" width="192" height="310" /> <img class="alignnone size-full wp-image-745" title="perf-db-read" src="http://www.helicontech.com/articles/wp-content/uploads/2012/02/perf-db-read.png" alt="" width="193" height="310" /> <img class="alignnone size-full wp-image-746" title="perf-db-write" src="http://www.helicontech.com/articles/wp-content/uploads/2012/02/perf-db-write.png" alt="" width="188" height="310" /></p>
<p>Here are more detailed ab graphs for the first test (time output):</p>
<p><img class="alignnone size-full wp-image-756" title="windows-zoo-time-data" src="http://www.helicontech.com/articles/wp-content/uploads/2012/02/windows-zoo-time-data.png" alt="" width="512" height="224" /></p>
<p><img class="alignnone size-full wp-image-757" title="ubundu-apache-passenger-time-data" src="http://www.helicontech.com/articles/wp-content/uploads/2012/02/ubundu-apache-passenger-time-data.png" alt="" width="512" height="224" /></p>
<p><img class="alignnone size-full wp-image-755" title="ubundu-nginx-time-data" src="http://www.helicontech.com/articles/wp-content/uploads/2012/02/ubundu-nginx-time-data.png" alt="" width="512" height="224" /></p>
<p><strong>Resume</strong></p>
<p>Ruby on Rails proved itself a perfect framework for quick and easy web development. Of course, Ruby is not the one and only. In the next articles we’ll shed some light on Goliath and Sinatra.</p>
<p>We would also like to underline that Windows is a mighty platform for both development with Ruby and running Ruby-apps in production. And if earlier the difference in Ruby performance on Linux and Windows was dramatic, now the performance, as well as convenience of Ruby on Rails for Windows has significantly improved to a degree that performance is no more a key criteria for choosing the platform.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.helicontech.com/articles/ruby-on-rails-on-windows-in-production/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Installing OSQA on Windows in production</title>
		<link>http://www.helicontech.com/articles/installing-osqa-on-windows-in-production/</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="489" height="254" /></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="490" height="350" /></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="489" height="424" /></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="490" height="407" /></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="490" height="336" /></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="490" height="350" /></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="490" height="688" /></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="490" height="336" /></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="740" height="545" /></p>
]]></content:encoded>
			<wfw:commentRss>http://www.helicontech.com/articles/installing-osqa-on-windows-in-production/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Installing Redmine on Windows in production</title>
		<link>http://www.helicontech.com/articles/installing-redmine-on-windows-in-production/</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>
]]></content:encoded>
			<wfw:commentRss>http://www.helicontech.com/articles/installing-redmine-on-windows-in-production/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Node.js on Windows (with performance tests)</title>
		<link>http://www.helicontech.com/articles/node-js-on-windows-with-performance-tests/</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>
]]></content:encoded>
			<wfw:commentRss>http://www.helicontech.com/articles/node-js-on-windows-with-performance-tests/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Running Django on Windows (with performance tests)</title>
		<link>http://www.helicontech.com/articles/running-django-on-windows-with-performance-tests/</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>
]]></content:encoded>
			<wfw:commentRss>http://www.helicontech.com/articles/running-django-on-windows-with-performance-tests/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Running Django, Rails and Mojolicious on Windows Server 2008 with IIS 7</title>
		<link>http://www.helicontech.com/articles/run-django-apps-on-iis/</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>
]]></content:encoded>
			<wfw:commentRss>http://www.helicontech.com/articles/run-django-apps-on-iis/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Сounting downloads from your site</title>
		<link>http://www.helicontech.com/articles/counting-downloads-from-your-site/</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>
]]></content:encoded>
			<wfw:commentRss>http://www.helicontech.com/articles/counting-downloads-from-your-site/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Make your websites work faster</title>
		<link>http://www.helicontech.com/articles/make-your-websites-work-faster/</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>
]]></content:encoded>
			<wfw:commentRss>http://www.helicontech.com/articles/make-your-websites-work-faster/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Exploding myths about mod_rewrite. Part 2.</title>
		<link>http://www.helicontech.com/articles/exploding-myths-about-mod_rewrite-part-2/</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>
]]></content:encoded>
			<wfw:commentRss>http://www.helicontech.com/articles/exploding-myths-about-mod_rewrite-part-2/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>IIS reverse proxy and load balancer with web admin panel</title>
		<link>http://www.helicontech.com/articles/web-interface-for-mod_proxy-load-balancer/</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>
]]></content:encoded>
			<wfw:commentRss>http://www.helicontech.com/articles/web-interface-for-mod_proxy-load-balancer/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

