The Case of The Async Log4Net Appender

October 16, 2013

It was a bad day. I was coding away happily as we started getting alerts that one of our production farms is down. Our service seemed to be stuck on each one of our servers. Requests are coming in, but no responses appear. Restarting the service helped, only to get stuck again after a while. The logs were unhelpful, and we had to pull out windbg to figure out what was going on. When your day starts with windbg, you know it won’t be a good one. The command ~*e!clrstack (=view stack trace of all managed threads) showed...

Charniak Parser on Windows

March 2, 2013

A while ago we wanted to choose a new natural language parser for our product. One of the strongest candidates in that area is the Charniak-Johnson parser. We ended up not choosing to use this parser for various reasons, but in the process of evaluating it we produced a nice side benefit: we compiled it (well, the Charniak part of it) and ran it natively on Windows. The source code for the converted project can be found on GitHub, and the binaries can be found here. Now, before I tell you a bit about the conversion...
tags: ,

Adapting Lucene scoring for an n-gram index

October 24, 2012

At Ginger we use a large index of n-grams, which is basically a sequence of words and their frequency in our corpus. We wanted to make this index searchable, so naturally, we defaulted to using Lucene, which is the most popular open source IR library. This is how we started adding documents to the index: 1: Document document = new Document(); 2: document.add(new Field("ngram", ngram, Field.Store.YES, Field.Index.ANALYZED)); 3: NumericField frequencyField = new NumericField("frequency", Field.Store.YES, true); ...
no comments

Console.ReadKey .NET 4.5 changes may deadlock your system

September 12, 2012

I’ve hit a weird issue today. We have a service that we run both as Windows service and from console. A specific use case seemed to cause our system to hang, but only when running from console. Also, I was sure this didn’t happen before I upgraded my machine to .NET 4.5. The service initialization code looks something like this: serviceHost.Open();   while (Console.ReadKey().Key != ConsoleKey.Q) { Console.WriteLine("Press Q to exit"); ...

NuGet Annoyance

May 29, 2012

I usually love using NuGet, but there are things about it that can sometimes make me scream with annoyance. My main issue is with the following scenario: I want to add a new dependency to a project. This dependency already exists in the solution. Here, one of two things may happen: The version that exists in the solution is the newest that came out. In which case, no problemo, NuGet will see that I already have that package installed and use it. A...
no comments

ThreadAbortException is Special

February 7, 2012

*Update (27/8): It is critical to set the time below to AutoReset = false, otherwise, the exception might be raised again, even after we handled it. I guess you could say that every exception is special and important in its own way, but ThreadAbortException is really special. In what way, you ask? Well, let me tell you a story. I wanted to implement a hard timeout for our system. That is, if a query to our service takes too long, force kill it, not matter what it is doing at the moment. You may claim that this...

Tip for Profiling NUnit Tests

December 15, 2011

This is just a tiny little note that can save you some precious time. This article explains exactly what you need to do in order to profile NUnit tests with dotTrace (gotta love products with special placement of capital letters) 4.0, except it misses an important detail. The latest versions of NUnit run the actual tests in a separate process, called nunit-agent.exe. So, if you profile nunit-console.exe you won’t see your code there at all. You have to run NUnit in a single process mode. To do that just add /process:Single to the nunit-console command line arguments, and everything...
no comments

How to Save a Unicode Text File That Excel Can Read

December 11, 2011

The other day I had to create a .CSV file with some funky Unicode characters. Not only that, but Excel had to be able to open and edit it. When using .NET’s StreamWriter default constructor, it uses a default encoding of UTF-8 without BOM (byte order mark), which Excel can’t read. Well, actually, it can read it, but it doesn’t realize that this is a unicode file and special characters (such as this lovely one - Ž) have a tendency to look like someone just puked a letter on the screen. The solution is quite...