in

CodePrairie .NET

South Dakota .NET User Group

chrisortman

September 2007 - Posts

  • UriTemplate and extensions

    The UriTemplate is a new class in the .NET Framework 3.5

    It provides a nice convenient way to parse variables from Uri's such that

     

    UriTemplate temp = new UriTemplate("account/{accountid}");
    Uri requestUri = temp.BindByPosition(baseUri, id.ToString());

    Will give you http://localhost/account/100 Nice!

     

    However, should your template contain a file extension it will give you an exception saying that there are no variables in your template, NOT Nice!

    Posted Sep 07 2007, 09:01 AM by chrisortman with no comments
    Filed under:
  • Rails on Windows

    I really really would like to be able to use rails on windows (not just developing, but in production). My preference would be to use linux, however the powers that be resist non microsoft os's like its nobodys business.

    My first attempt is to use the new FastCGI for IIS. I figured this is my best bet since the more Microsoft technologies that I use, the easier this is to sell to my paycheck signers.

    Setup was pretty simple, I followed these instructions (site not coming up as I write this, worked yesterday though)
    The only issues I had were making sure permissions were setup on directory where my rails app was. To keep things simple I just gave Everyone modify rights to the whole folder.

    My sample rails app is small, it calls a com object that returns xml which I return using render :xml

    My first test is to create 4 threads and request the page from each

     

    require 'open-uri'
    NUM_THREADS = 4
    
    URL = ''
    
    threads = []
    NUM_THREADS.times do |num|
      t = Thread.new(num) do |count|
        begin    
          puts "Starting thread #{count}"
          resp = open(URL)
          puts "Finished thread #{count}"
        rescue OpenURI::HTTPError => err
          puts "Failed on #{count}"
          puts err.io.readlines
        end
      end
      threads << t
    end
    
    threads.each {|t| t.join }

    So far...umm not so good. Generally with 4 requests 1 maybe 2 will succeed with the rest giving me this error:

    500 Server Error
    Error 0x80070102
    The FastCGI process exceeded configured activity timeout

    The CPU is also pegged on the server when I do this.

    So my first step was to try to up the timer for FastCGI. I found this forum post so I added this to my fcgiext.ini file

    RequestTimeout=90
    ActivityTimeout=60

    I reran the tests (after restarting IIS) and was gretted with a Timeout::Error, so I tried setting the timeout like this in my test prog.

    Finally all threads complete, but with a timeout of 90 seconds passed to open uri 3 of the 4 threads hit the timeout and had to retry in order to complete.

    I didn't expect blazing performance, but yuck, this is silly. If I run the same tests but use webrick as the server on the machine all 4 threads get a nice quick result.

  • Getting profile data from ruby (using Powershell)

    Since I'm on windows I'm running this from powershell.

    ruby -r profile myprogram.rb 2> prof.log
    

    This will turn on ruby's profiling which writes to STDERR. the 2> catches that output and puts it into a file.

    Now after you run this there will be a bunch of noise in your prof.log file, so to remove it just do

    gc prof.log | where { $_ -notmatch "^At" } | where { $_ -notmatch "^\+"} > perf.log
    
     
  • Viewing server errors with open-uri

    I've been doing some testing using open-uri but when my server returned an http 500 all I got on the ruby side was an Open::HTTPError. In order to view the actual error page returned by the server I needed to do something like this:

     

    begin    
      resp = open(URL)
      puts "Finished"
    rescue OpenURI::HTTPError => err
      puts "Failed"
      puts err.io.readlines
    end
    Posted Sep 05 2007, 06:49 AM by chrisortman with no comments
    Filed under:
Powered by Community Server (Commercial Edition), by Telligent Systems