On Fri, 14 Jul 2006, Ben Johnson wrote:

> I have a server that is dedicated solely for running a single ruby 
> application. Is there a ruby configuration file that I can change to help 
> speed ruby up and take as much resources as it needs? Basically make sure 
> there is no memory limit, processing limit, and give it the highest priority 
> process as possible. Also is there anything else I can do to get the most 
> speed out of ruby?


Wow! You seem to hit some grumpy folks in the chatter spot. Even after
all that I'm not sure any of them actually read or answered your
question!

Ah well. I'll have a bash.

By Server, do you mean Web Server? ie. If you are doing a CGI script
that is getting hammered heavily you might want to try mod_ruby
  http://www.modruby.net/en/

The "take the resources it needs" bit probably has more to do with the
OS than with Ruby.


You didn't say which OS, so I'm going to assume Linuxy / Unixy type OS....

"man setrusage" may help there.

Say "help ulimit" for more info on that, and "man mlock" may be helpful
too.

The Ruby syscall function may be your friend here.

For "Highest priority", you need super user privileges to do that and the
"nice" or "renice" command.

Take care, don't make it too high otherwise it competes with vital
daemons.


I have been accumulating optimization hints and tips at...
   http://wiki.rubygarden.org/Ruby/page/show/RubyOptimization
Please contribute anything useful you find to that.

Here is a "worked example" of doing a syscall (not one you want here,
but at least shows the way...)
======================================================================
=begin rdoc

This is the kernel statfs64 structure definition only here for
documentation purposes.

__extension__ typedef unsigned long long int __u_quad_t;
__extension__ typedef __u_quad_t __fsblkcnt64_t;
__extension__ typedef __u_quad_t __fsfilcnt64_t;
__extension__ typedef struct { int __val[2]; } __fsid_t;

struct statfs64
   {
     int f_type;
     int f_bsize;
     __fsblkcnt64_t f_blocks;
     __fsblkcnt64_t f_bfree;
     __fsblkcnt64_t f_bavail;
     __fsfilcnt64_t f_files;
     __fsfilcnt64_t f_ffree;
     __fsid_t f_fsid;
     int f_namelen;
     int f_frsize;
     int f_spare[5];
   };

#define __NR_statfs64		268
#define __NR_fstatfs64		269

This is runs a little .c program to verify it all works... (Don't forget
this is all commented out for now..)

tmp = "/tmp/struct.c"
open(tmp, 'w') do |c|
   c.puts "
#define _GNU_SOURCE 1
#include <sys/syscall.h>
#include <sys/statfs.h>

struct statfs64 s;

"
end

puts `gcc -E  #{tmp}`

=end

require 'pp'

class StatFs64
   STRUCT_STATFS64 = [
                      [0, 'i', 'f_type'],
                      [0, 'i', 'f_bsize'],
                      [0, 'Q', 'f_blocks'],
                      [0, 'Q', 'f_bfree'],
                      [0, 'Q', 'f_bavail'],
                      [0, 'Q', 'f_files'],
                      [0, 'Q', 'f_ffree'],
                      [0, 'i', 'f_fsid0'],
                      [0, 'i', 'f_fsid1'],
                      [0, 'i', 'f_namelen'],
                      [0, 'i', 'f_frsize'],
                      [0, 'i', 'f_spare0'],
                      [0, 'i', 'f_spare1'],
                      [0, 'i', 'f_spare2'],
                      [0, 'i', 'f_spare3'],
                      [0, 'i', 'f_spare4'],
                     ]

   def syscall_pack( triplets)
     template = ''
     default = []
     triplets.each do |value, directive, name|
       default << value
       template += directive
     end
     default.pack( template)
   end

   def syscall_unpack( triplets, string)
     template = ''
     names = []
     triplets.each do |value, directive, name|
       names << name
       template += directive
     end

     result = {}
     values = string.unpack( template)
     names.each_with_index do |name,i|
       value = values[i]
       result[name] = value
     end

     result
   end

   def initialize( path)
     string = syscall_pack( STRUCT_STATFS64)
     result = syscall( 268, path, string.size, string)
     raise "Unexpected return value '#{result}'" unless
       result == 0

     @statfs64 = syscall_unpack( STRUCT_STATFS64, string)
   end

   # Returns number of free megabytes available
   def free_megabytes
     (@statfs64['f_bavail'] * @statfs64['f_bsize']) / (1024 * 1024.0)
   end

   # Returns number of free gigabytes available
   def free_gigabytes
     free_megabytes / 1024.0
   end

   attr_reader :statfs64
end

if $0 == __FILE__ then
   require 'test/unit'

   class TC_StatFs < Test::Unit::TestCase
     def test_statfs
       s = StatFs64.new( "/")
       puts "Free #{s.free_megabytes}mb"
       puts "Free #{s.free_gigabytes}gb"#
       puts s.statfs64.keys.sort.collect{|k| "#{k}=#{s.statfs64[k]}" }.join("\n")
     end
   end
end

======================================================================





John Carter                             Phone : (64)(3) 358 6639
Tait Electronics                        Fax   : (64)(3) 359 4632
PO Box 1645 Christchurch                Email : john.carter / tait.co.nz
New Zealand

Carter's Clarification of Murphy's Law.

"Things only ever go right so that they may go more spectacularly wrong later."

From this principle, all of life and physics may be deduced.