Batch Processing with NHibernate
July 17th, 2008
I have a project where I need to process every night large amounts of data. Basically I have to fetch a lot of objects and related collections from the DB using NHibernate, operate on them, and then do some updates. This process usually takes about 2-3 hours.
Today I discovered a way to brutally increase the application speed. I noticed that the application started fast, but would gradually become slower. I didn't know why, so I tried to free already used objects and splitting the process into several separate instances. This helped only a little. I'm doing something like this (we use a facade on top of NHibernate, so: different types, but the same concepts/names):
-
public static void Operate()
-
{
-
using( IPersistanceSession
-
session = GetNHibernateSession(MasterSession) ) {
-
-
IList list = GetALotOfObjects();
-
foreach( object obj in list ) {
-
Operate(session, obj);
-
}
-
-
}
-
}
This code is very slow. Some time ago, I had to go into NHibernate source code to understand how I could use sessions with ASP.NET, and I noticed that NHibernate uses a lot of internal objects. Well, on this case, I am fetching a lot of objects that have no relation with each other, so, I guessed I could clear the session from time to time... And adding a clear, boosted the speed considerably:
-
public static void Operate()
-
{
-
using( IPersistanceSession
-
session = GetNHibernateSession(MasterSession) ) {
-
-
session.Clear();
-
-
IList list = GetALotOfObjects();
-
foreach( object obj in list ) {
-
session.Clear();
-
Operate(session, obj);
-
}
-
-
}
-
}
I really can't explain this as my knowledge of NHibernate internals is minimal, but believe me when I say that Clear made a difference... a 2/3h to 10 minutos difference!
Street Fighter IV - The King Returns
July 16th, 2008
And it's looking good:
Bonus for having a child
July 16th, 2008
A friend of mine that works at Dynargie told me this weekend that the company announced that they would pay a bonus of 1000€ to every employee having a child! They'll pay 400€ upon birth, 200€ on the first year and the rest on the second year.
Sometimes we see women being fired just for becoming pregnant, so I see this bonus as great way to motivate employees (and also to keep them around for two years). Kudos for Dynargie!
Application Evolution using Google Charts
July 15th, 2008
I'm becoming a big fan of the Google Chart API, because it's a very easy way to add some charts to a web application. All you have to do is to choose a chart type, bundle in the data, and google will provide you with clean, pretty chart. No more configurations, no third party dependencies, it's as easy as it gets.
I've recently incorporated google charts in what I like to call our application's evolution data. Good metrics are always important, and there are several tools out there like Google Analytics that provide us with good data. The problem is, that these tools only handle visits, pageviews, referrals, keywords, etc. All generic information that makes sense for all sites. But what about custom application information?
How can we track the number of active users, last day logins, number of new users per day, and other useful metrics? This is what I call application evolution, and I'll show how I've achieved it using the Google Chart API.
The Objective
My objective is to have a simple representation of metrics evolution. The metric can be anything, and for each metric I want to present on the admin area, a chart and the last registered value. Example:
77 Active Users
Using Google Chart API with C#
We interact with the API using urls. We build an url with the chart info, and google will return the chart. The documentation on their site is really helpful. So, let's break down the previous chart. The url for that chart is:
If we split the url, we get:
- http://chart.apis.google.com/chart? - The endpoint
- cht=ls - The chart type; this one is the sparkline: it's like a line chart without the axes, very analytics like
- chd=t:10.0,58.0,95.0,40,50,(...) - The actual chart data, using text encoding. With this encoding you specify your data with percentages, separated by a comma. If you need a larger value collection you might want to consider the extended encoding
- chs=200x40 - The chart size
- chm=(...)&chco=(...)&chf=(...) - The chart colors
Preparing the Metrics
We can only build the charts after gathering the metrics. To gather metrics I use a XML file that is created everyday. The file looks like this:
-
<Metrics Date='7/7/2008 2:58:47 PM'>
-
<UserMetrics>
-
<NewUsers Value='1' />
-
<ActiveUsers Value='0' />
-
<RegisteredUsers Value='4' />
-
<LastDayLogins Value='3' />
-
</UserMetrics>
-
<EntityCountMetrics>
-
<ExceptionInfo Value='2' />
-
</EntityCountMetrics>
-
</Metrics>
Each day I create a XML file like this with the name Metrics[Year]-[DayOfYear].xml.
From Metrics to Charts
Having the XML files, and the API to graphically present that information, we only need to do the actual data import. Once a day I open up all the previous 30 files and build a list of values per metric. I start by creating a XPathDocument for each file and with it I extract one value per metric, that I'll register on the global metrics dictionary. After this step, I just have to build the chart URL.
I write all the charts for all the metrics on an HTML file that is imported by the administration front page. Here's an example:
This is nice, but what I would really like, was to provide my custom metrics to Google Analytics, and have them do all the storing, manipulation, presentation, etc. I mailed them suggesting this new feature, but I don't know why, I never got a reply! ![]()
Farmer Jane Game by RTS
July 14th, 2008
RTS, one of the most successful Portuguese companies operating on the casual games market, has just released another game: Farmer Jane! Congratulations to RTS! At this moment, Farmer Jane is the the featured game at the Big Fish Games Home Page, and it's is placed on the Top 10 Downloads page!
Here's a video of the game:
LinkedIn Mayhem
July 11th, 2008
I find it amazing that all the partners and managers that I used to work for/with, are connected on LinkedIn. It almost seams that the IT business in Portugal is a very small ecosystem, where everybody knows everybody.
Another interesting thing on LinkedIn is the way that human resources head hunters are using it to reach applicants. I guess it works like this:
- The head hunter searches for software developers
- For each developer, the head hunter will try to find a contact. He can use the contact methods provided by LinkedIn, of he can just call the target's company, saying that he's a friend, and asking for a contact (yeah, I've seen this happen more than once)
- Then, the hunter will contact the applicant, stating that the applicant was a referral from someone very important, and they would like to present some job opportunities on some highly interesting projects. However, if you want to know who referred you, they'll say that it's classified.
I already know of 3 or 4 companies that are in the business of head hunting, they earn commissions on delivering fresh applicants to companies. There's only one thing that I don't understand... if the market is lacking developers, then why isn't our price rising up?
GameDevPT Gathering
July 10th, 2008
The Portuguese Gamedev Community will be gathering for a GD-PT lunch next July 26. I attended this lunch last year and there was about 40 people, with lots of ideas and projects to show. Just to mention a few, we got people from Vortix Games, Real Time Solutions, Move Interactive, Orion's Belt, Almansur and several independent developers.
So, if you're into gamedev, and you're Portuguese, come and do some networking. ![]()
Software Development Wisdom
July 8th, 2008
- When estimating a task, take your first estimate, double it, and add 50%.
- The 90-90 Rule - The first 90% of the code accounts for the first 10% of the development time. The remaining 10% of the code accounts for the other 90% of the development time.
- The 90-9-1 Rule. In most online communities, 90% of users are lurkers who never contribute, 9% of users contribute a little, and 1% of users account for almost all the action.
- The 80-20 rule - The Pareto principle - for example, in designing software it’s usually safe to assume that 80% of your users’ time will be spent with 20% of the features
- The best developers are 10 times more productive than the worst ones. - nhac! that's just prima donna speaking. In most applications, anyone with a basic knowledge will due, no one cares.
- 2 interruptions cost you 1 hour of work - I really hate context switching
Based on
5 Rules of Thumb for Web Workers.
Google Charts API for Maps
July 8th, 2008
I was just checking out the google charts api reference when I stumbled upon Google Charts API for Maps. Very interesting! It allows you to easily build charts like these:
Google Ad Manager
July 4th, 2008
We've just been accepted for a Google Ad Manager account. We've been using a home made solution to display rotating ads on our sites. This solution is now quite old and deprecated, and a new replacement, a google based solution, was welcome.
Well, at first sight, this is not an easy tool to use, we have a lot of concepts: ads, orders, ad slots, placements, ad products, creatives, and some more. It's not just an ad rotation tool, but actually an ad marketplace. I actually had to check out the video just to have an idea of the overall functionalities. This is not normal in a google application. Google isn't known for having complex applications.
What I found interesting, was the ad manager tutorial. A step by step tutorial that teaches the user how to use the application. I found it interesting because we are studying some easy ways to teach users how to use complex interfaces (like we may have in a webgame). The typical user won't read a manual, won't watch some videos, he'll just want to start playing and learning everything without wasting time. And I found this google ad manager tutorial a good way to accomplish that.
Do you know some other good examples of efective online tutorials?


