Software dev, tech, mind hacks and the occasional personal bit

Category: Ruby / Rails Page 5 of 7

Wedding Registries for the Pommies

Update: I closed down this site in 2013, and let the domain lapse. In 2023, a zombie version was set up by parties unknown at the same domain, using my pages scraped from the wayback machine. This site does not work, and is not run by me despite having my name on it. I am attempting to have it closed down.

Your Wedding Presents now shows all money amounts in pounds, if you say you are from the United Kingdom. God Save the Queen!

JRuby on Rails with GoldSpike – Scaling for more users

The default configuration for running JRuby on Rails using GoldSpike only allows 4 instances of the JRuby runtime. This means that if there are more than 4 simultaneous requests from clients, the web server will respond with a server overloaded error. The easiest way to see what’s going on is to take a look at the ‘createObjectPool’ method of RailsServlet.

With a dedicated production server with 1gig of memory, it is possible to allow a lot more JRuby runtimes, and hence allow for more simultaneous users. A little load testing on a fairly small app suggested that 20 instances of JRuby runtime would fit comfortably under the 1gig ceiling and not overload the processor.

An easy way to change the max number of runtimes is to edit ‘web.xml’ in a JRuby application’s WEB-INF directory. Parameter is set as follows:

  <context-param>
    <param-name>jruby.pool.maxActive</param-name>
    <param-value>20</param-value>
  </context-param>

It is also worth checking with the web server configuration to ensure that the web server allows more threads than the number of JRuby runtimes specified in ‘web.xml’.

YourWeddingPresents.com (wedding registry site) now live!

Update: I closed down this site in 2013, and let the domain lapse. In 2023, a zombie version was set up by parties unknown at the same domain, using my pages scraped from the wayback machine. This site does not work, and is not run by me despite having my name on it. I am attempting to have it closed down.

I’m really pleased to announce that YourWeddingPresents.com (a free, independent, wedding registry site) is now live!

When my sister was getting married, she had a lot of trouble finding a good free wedding registry that was not tied to any particular shop. I developed the wedding registry site to fill this gap, and also to improve my web programming skills. I’ve tried to design Your Wedding Presents to be really quick to sign up and easy to use. Please tell me if there are any problems with the site, or ways the site could be made better.

On the technical side, I developed Your Wedding Presents using Ruby on Rails. It is running on an Apache load-balanced Mongrel cluster and data is stored in MySQL. It is hosted on Rails Playground.

JRuby, Rails and Statics

Say you wanted to store some information across different calls to your JRuby/Rails application on the server side. You could use a database, or memcached. However, what if you just want to do something very simple like a basic cache, and you don’t have a database for your application? Memcached seems like overkill, and would complicate your deployment considerably. So, what about just using statics?

Well, you can’t do it in Ruby, as the Rails integration servlet spawns multiple instances of the JRuby interpreter.

Ruby code in a page view:

<h1>Ruby global number</h1>
<% $i ||= 0 %>
<% $i += 1 %>
<%= $i %>

<h1>Ruby obj id</h1>
<% $o ||= Object.new %>
<%= $o.object_id %>

Results between multiple refreshes of the page:

Ruby global number
1 
Ruby obj id
244 

Ruby global number
1 
Ruby obj id
256 

Ruby global number
2 
Ruby obj id
244 

Ruby global number
2 
Ruby obj id
256 

Our requests seem to be switching between two instances of the Ruby interpreter.

However, we *can* do it in Java. My clever, Java-literate colleagues explained that Java application servers and servlet containers use a single instance of the JVM, but have a class loader for each application. The class loader stores class information and static values. This means that within one application, the static values will be maintained between requests, but a different application on the same server will have its own set of unrelated static values (similar to AppDomains in .NET).

If we add a call to a static method in Java that increments an integer and returns it, our view looks like this:

<h1>Ruby global number</h1>
<% $i ||= 0 %>
<% $i += 1 %>
<%= $i %>

<h1>Ruby obj id</h1>
<% $o ||= Object.new %>
<%= $o.object_id %>

<h1>Java incrementing static integer</h1>
<%= TestClass.incrementAndReturnNumber() %>

Our results now look a lot more useful. The Java static integer is getting incremented each call to the view:

Ruby global number
1 
Ruby obj id
244 
Java number
1 

Ruby global number
1 
Ruby obj id
256 
Java number
2 

Ruby global number
2 
Ruby obj id
244 
Java number
3 

Ruby global number
2 
Ruby obj id
256 
Java number
4 

From this little experiment, Java statics seem like a possible way to go for storing temporary data on the server side (eg, a cache implemented as a singleton) for JRuby / Rails. Another option may be to use the ServletContext from the JRuby Rails integration servlet – probably an area worth investigating.

BarCamp Sydney this Saturday

It is BarCamp in Sydney this Saturday. I haven’t been to one of these unconference style events before, but I’ve heard good things about it from my colleagues. I’m quite excited to go along and see what it is like.

If you’re in Sydney and interested in stopping by, details are as follows:

When: Sat 25th August 2007 from about 9am
Where: University of Technology, Sydney (Jones St entrance)
More details…

One of the novel aspects of BarCamp is that all participants are encouraged to present or start a discussion around something that interests them. For my part, depending on what people are interested in, I was thinking of one of the following:

  • new stuff in the .net space (C# 3.0, .NET 3.5, LINQ, WPF, WCF, etc) and showing some demos
  • giving a bit of a Ruby/JRuby introduction with help from Ola’s JavaBin slides
  • or, if people are keen, a discussion around JRuby vs C# 3 vs Java vs ?? and their stacks for different situations and problems
    • By the way, the conference is free, and it is not too late to sign up 🙂
      Hope to see you there!

Slides from ‘Learning to live with the static-typing fascist and the dynamic-typing fan-boy in your enterprise…’

Here’s the slides from Jim‘s and my recent presentation at Tech Ed 07 on the Gold Coast and in Auckland:

LearningToLiveWithTheStaticTypingFascistAndTheDynamicTypingFanboy-TechEd07.pptx (Powerpoint 2007)

LearningToLiveWithTheStaticTypingFascistAndTheDynamicTypingFanboy-TechEd07.ppt (Powerpoint 2003)

You may also be interested in having a read of the abstract.

TechEd 07 – Some interesting snippets

Silverlight

  • Silverlight runs on MAC and PC.
  • There is now a CLR for the Mac.
  • Microsoft is not currently planning to provide Silverlight for any unix platform (although there is MoonLight).
  • Silverlight 1.0 is basically a media player. It has hooks for javascript etc and some might say it has similar functionality to the Flash movie player.
  • Silverlight 1.1 has the real programming API. All further Silverlight references are to 1.1.
  • Silverlight will do a (currently undefined) simplified subset of WPF.
  • Silverlight gives acess to DOM in the browser.
  • Currently, the alpha allows 1mb local storage per page. In future, the storage is probably going to be shared across a domain rather than on a page by page basis.
  • Silverlight provides the capability to open a file on disk for read to allow for file uploads etc.
  • Interop between JavaScript and hosted Silverlight app is quite easy.
  • Silverlight looks a bit fiddly to set up, requiring javascript and sometimes xaml bootstrap – but being improved.

Software Factories

  • Allow solution and project structures to be auto-generated based on wizards.
  • Can provide code snippets and some (often template-based) code auto-generation.
  • Comes with documentation in help files and some context specific stuff.
  • Can include GUI designers that generate code.
  • People can develop their own domain specific factories.

DSLs
Currently, Microsoft’s take on DSLs is GUI editors, not written language or code. At the Software Factories talk, a GUI tool in Visual Studio for drawing your business entities and relationships was billed as a DSL.

Windows Workflow Foundation (WF)

  • Activity based with GUI designer for connecting and composing activities.
  • Custom activities and compositions can be developed and inherit from base classes.
  • Single threaded and mainly queue based, with some events sprinkled through.
  • Activities can reference data from other activities using a mechanism vaguely like data binding.
  • Hosted in the CLR, so can be part of a console app, ASP.NET, WinForms etc.
  • Handles pickling and reconstitution of long running activities.
  • Base Activity classes provide virtual hooks. Eg, ‘Execute’ for doing the work, ‘Cancel’, and ‘Compensate’ for handling rollback scenarios.

New in the Enterprise Library 3.1

  • Validation Application Block: provides simple, attribute based property validation. Easy integration with standard ErrorProvider on WinForms and WebForms and WPF is possible. Looks ok but somewhat basic – don’t think it supports warnings for example. It has GUI tool support and also capability to specify related objects which need to be validated.
  • Policy Injection Application Block: provides aspect oriented programming (AOP) style coding using attributes. All new AOP objects need to be created using the block’s object factory. Looks useful – there is out of the box support for validation, caching and logging in AOP fashion.

 

Tech Ed Talks

Jim Webber and I will be co-presenting at Tech Ed Australia and Tech Ed New Zealand this year. Here’s the low down:

Learning to live with the static-typing fascist and the dynamic-typing fan-boy in your enterprise…

Gold Coast
Thursday 9 Aug
5pm – 6:15pm

Auckland
Tuesday 14 Aug
2:20pm – 3:35pm

“What’s best for your enterprise? Is it the ‘glue that never sets’ and flexibility of dynamic languages like Ruby, or the tried and true, hard and fast rules and tool support of static languages like C# 3.0? Are there different trade-offs for green field development and integration?

And more importantly, which is best, the Mac or PC?

In a dynamic, and combative presentation, Jim and James will let their alter-egos run amok and answer these questions from the perspective of a seasoned enterprise architect and a l33t hax0r. By the end of this session you will understand the interplays between the two personality types, have had a few laughs, and picked up a few tips on how to use both technology
sets in harmony in your enterprise. “

Hope to see you there!

Adding a New Rails Project under Subversion

I generally use Subversion for source control when given the choice. In day to day usage, I like to use Tortoise SVN as it gives you a GUI with tick boxes for files to check in. However, it’s handy to use the command line tool for project setup and automation.

Often, there is a subversion repository already set up and running on another machine. In this situation, I generally:

  1. Check out the repository at the top level into a temporary directory through Tortoise, add a new directory ([appname]) for the new project, and check it in.
  2. Generate the new rails app (rails [appname]).
  3. Check out [appname] from the repository into the local directory [appname] which contains the Rails project.
  4. Add and check in all files through Tortoise.
  5. Run the following commands from the command line to remove logs and tmp from the repository:
svn remove log/*

svn commit -m "removing all log files from subversion"

svn propset svn:ignore "*.log" log/svn update log/

svn commit -m "Ignoring all files in /log/ ending in .log"

svn remove tmp/*

svn propset svn:ignore "*" tmp/

svn update tmp/svn 

svn commit -m "Ignoring all files in /tmp/"

There’s more Rails/Subversion info to be found on the Rails wiki.

The Castle Project – Rails for .NET

The Castle Project is an interesting open source alternative to ASP.NET / ADO.NET. Among other things, the Castle Project provides a Rails-like development framework for .NET. It has an ActiveRecord implementation built on top of NHibernate, a very Rails-like MVC setup called MonoRail, and uses NVelocity for template style views. It’s worth checking out. This screencast gives a bit of an overview.

There’s tough competition around the corner though, with Orcas already in beta, providing XAML, LINQ and O-R mapping.

Page 5 of 7

Powered by WordPress & Theme by Anders Norén