Tag: web

Install merb from git

Posted by on 16-Sep-2008

Trying to install the development version of merb , i’ve got:

no such file to load -- extlib/tasks/release

Seems the extlib gem is too old for merb. Fix:

$ git clone git://github.com/sam/extlib.git
$ cd extlib
$ rake gem
$ sudo gem install pkg/extlib-0.9.4.gem

The rest of installation process:

$ sudo gem install sake erubis mime-types
$ sake -i http://merbivore.com/merb-dev.sake
$ mkdir ~/merb_src && cd ~/merb_src
$ sake merb:clone
$ sake merb:install:all

Your first application:

$ merb-gen app my_app --flat && cd my_app

Throttler Ramaze helper

Posted by on 14-Apr-2008

After reading Rails Plugin: Throttler I created a Throttler Ramaze Helper .

  • What is it for? ”…The throttling plugin monitors the load of your server and allows you to disable certain features of your app when the load is too high…”
  • How to use it?
    • Copy throttler.rb to /{ramaze_gem_dir}/lib/ramaze/helper/throttler.rb
    • In your controllers code:
      class MainController < Ramaze::Controller
        helper :throttler
      
        def index
            # (optional): override the threshold when calling throttled?()
            # unless throttled?(10.00) ...
            unless throttled?
               "Hello World"
            else
               "Overloaded: #{current_load}"
            end
        end
      
      protected
         # (optional) set another threshold value
         def threshold
            5.00
         end
      end
      

Thanks a lot to Kashia from #ramaze for the help.

Later I start thinking “Hm, maybe that one is better to be Rack middleware …”. Maybe next try…

Merb on Joyent Accelerator (part 1)

Posted by on 27-Dec-2007

The Accelerator including almost everything by default – Ruby, gems etc. Adding the Merb framework was without any problems. Some tips:

Pre-requirements:

$  sudo gem install mongrel json json_pure erubis mime-types rspec hpricot mocha \
                    rubigen haml markaby mailfactory Ruby2Ruby --no-rdoc --no-ri

Switching to merb trunk:

$ svn co http://svn.devjavu.com/merb/trunk merb
$ cd merb/
$ rake gem
$ sudo gem install pkg/merb-0.4.2.gem --no-rdoc --no-ri

Swithing to merb_helpers trunk (for better form helpers):

$ svn co http://svn.devjavu.com/merb/plugins/merb_helpers
$ cd merb_helpers/
$ rake gem
$ gem list
$ sudo gem install pkg/merb_helpers-0.4.1.gem --no-rdoc --no-ri

There was problems with the datamapper installation. The do_sqlite3 gem compilation was successful. For do_mysql gem one however I needed:

cd /opt/local/lib/ruby/gems/1.8/gems/do_mysql-0.2.2/ext/
make clean
ruby extconf.rb --with-mysql-include=/opt/local/include/mysql \
                --with-mysql-lib=/opt/local/lib/mysql
make
cd ../
rake gem
gem install pkg/do_mysql-0.2.2.gem \
    --no-rdoc --no-ri -- \
    --with-mysql-include=/opt/local/include/mysql \
    --with-mysql-lib=/opt/local/lib/mysql

My coworker Jeffrey Gelens was pretty excited about merb+datamapper combo. He even submitted some composite indexes patch to their repository.

Optimizing HTTP server performance on Linux

Posted by on 20-Nov-2007

via DebianHelp

…Disabling the TCP options reduces the overhead of each TCP packet and might help to get the last few percent of performance out of the server. Be aware that disabling these options most likely decreases performance for high-latency and lossy links.

net.ipv4.tcp_sack = 0
net.ipv4.tcp_timestamps = 0

Increasing the TCP send and receive buffers will increase the performance a lot if (and only if) you have a lot of large files to send.

net.ipv4.tcp_wmem = 4096 65536 524288
net.core.wmem_max = 1048576

If you have a lot of large file uploads, increasing the receive buffers will help.

net.ipv4.tcp_rmem = 4096 87380 524288
net.core.rmem_max = 1048576

Evented Mongrel and bbox2 blog

Posted by on 15-Aug-2007

On bbox2 i installed swiftiply gem . This changed the mongrel_rails command to use evented mongrel – mongrel, patched to use eventmachine tcp stack instead of the original pure ruby one.
In /etc/init.d/mongrel_cluster i’m starting all mongrel instances with:

env EVENT=1 mongrel_cluster_ctl start ...

And because only testing is boring ;) I deployed restolog also to bbox2 . Now it’s available on both bbox and bbox2:

So now there is a “real world” application running on nginx+evented mongrel cluster. In fact the current post is done via bbox2 :)

The backend is the same database, so there will be no duplicated etc. posts.

I wanted to do the benchmarks again but ab seems buggy – it’s hang after sending 900 requests ( -c 100 -n 1000 ). Searching the internet gave me that: ab hang .
Hm, maybe will try httperf.

nginx-0.5.24, server executable upgrade "on the fly"

Posted by on 07-Jun-2007

There is a new version of the nginx web server – nginx-0.5.24 . Too many upgrades recently :( From the changelog:

Bugfix: a part of response body may be passed uncompressed if gzip was used; bug appeared in 0.5.23.

I have a small ugly shell script for upgrading:

#!/bin/sh
VER=0.5.24
if [ ! -d ~/Work/nginx-${VER} ]; then
  cd ~/Work
  wget http://sysoev.ru/nginx/nginx-${VER}.tar.gz && \
  tar xvzf nginx-${VER}.tar.gz
fi
if [ -d ~/Work/nginx-${VER} ]; then
  cd ~/Work/nginx-${VER} && ./configure --prefix=/opt/nginx \
     --with-openssl=/usr/lib/ --with-sha1=/usr/lib \
     --with-http_realip_module --with-http_ssl_module && make
fi

The interesting part is after the installation – upgrade the server executable “on the fly” , without restarting:

% cd ~/Work/nginx-0.5.24
% sudo make install
% sudo kill -USR2 `cat /opt/nginx/logs/nginx.pid`
% tail -f /opt/nginx/logs/error.log
2007/06/07 14:27:23 [notice] 4382#0: signal 12 (SIGUSR2) received, changing binary
2007/06/07 14:27:23 [notice] 4382#0: changing binary
2007/06/07 14:27:23 [notice] 4382#0: start new binary process 6500
2007/06/07 14:27:23 [notice] 6500#0: using inherited sockets from "6;7;"
2007/06/07 14:27:23 [notice] 6500#0: using the "epoll" event method
2007/06/07 14:27:23 [notice] 6500#0: nginx/0.5.24

Well done software = happy sysadmin = happy users :)

Erlang gen_tcp:listen options

Posted by on 09-May-2007

{active, Boolean}

…If the active option is true, which is the default, everything received from the socket will be sent as messages to the receiving process. If the active option is set to false (passive mode), the process must explicitly receive incoming data by calling gen_tcp:recv/N or gen_udp:recv/N (depending on the type of socket). If the active option is set to once (active once), one data message from the socket will be sent to the process. To receive one more message, setopts/2 must be called again with the {active,once} option…

Note: Active mode provides no flow control; a fast sender could easily overflow the receiver with incoming messages. Use active mode only if your high-level protocol provides its own flow control (for instance, acknowledging received messages) or the amount of data exchanged is small.

{keepalive, Boolean} – powered by© Comet ;)

(TCP/IP sockets) Enables periodic transmission on a connected socket, when no other data is being exchanged. If the other end does not respond, the connection is considered broken and an error message will be sent to the controlling process. Default disabled.

{reuseaddr, Boolean}

Allows or disallows local reuse of port numbers. By default, reuse is disallowed.

So the default listening socket options are (overwrite only the differences if needed):

[{active, true},
 {keepalive, false},
 {packet, 0},
 {reuseaddr, false}].

Search Erlang-related information

Posted by on 08-Feb-2007

Started Google Co-op powered Erlang-related Search Engine . Enjoy

Update 09-Feb-2007: Also some tinyurl for the search machine

Lingr API

Posted by on 29-Jan-2007

…The Lingr API is a simple, HTTP-based REST protocol that enables anyone to interact with, extend, and mashup Lingr in whatever wacky way they want….

…Using the Ruby Lingr API toolkit , a Ruby programmer can be up and talking to our API in just a few minutes time…

Even a small Ruby Botkit is included. :)

See also:

Mongrel HTTP Server

Posted by on 29-Jan-2007

A small fast HTTP server written in (mostly) Ruby that can be used to host web frameworks directly with HTTP rather than FastCGI or SCGI.

Examples already working with Camping .

See also: Mongrel RDoc pages