We set up a StackExchange site for Entrepreneurs in Germany. Now, what do you call a StackExchange type of site? We’re proposing »Wikorum«. What do you think about it? You can vote and comment over at meta.StackExchange.com, or comment right here of course!

This is an interesting experiment… I’m interested to see how it works out :)

Post to Twitter Post to Delicious Post to Digg Post to Facebook

Tags: , , , ,

db4o Queries on Large Datasets and a bit of Linq

by Christoph Menge in .NET, db4o

My last small note on db4o performance will soon be outdated – fortunately. Newer releases of db4o will no longer rely on Cecil to perform reflection, thereby speeding up db4o linq queries – However, make sure you have Mono.Reflection.dll in your app! Also there are some restrictions when it comes to the compact framework and native queries (which still need Cecil), so you’d best make sure to read this official db4o announcement.

Talking about speed and performance, I just came across an issue that was also discussed in db4o forums very recently: Sort operations on large datasets.
Note: This has nothing to do with linq or linq to db4o, it’s just the same for SODA queries.

Let’s take a very common example: Find some most recent items, for example most recent blog/forum posts or some other ‘top list’ on a very large amount of entries N:

        var mostRecentPosts = (from Posts o
              in ObjectContainer
              orderby o.Created descending
              select o).Take(100).ToList();

This query will be really really slow on a large amount of objects. Why? Essentially, the BTREE operation is very fast as it should be, but unfortunately db4o will invoke its SODA system on each of the objects, even if they are already outruled by the BTREE operation.

See this discussion on the db4o forum and the associated Jira-bug.

This is somewhat sad, because a query on a previously filtered set of items is blazing, about 100x faster:

        var mostRecentPosts = (from Posts o
              in ObjectContainer
              where o.Created > yesterday
              orderby o.Created descending
              select o).Take(100).ToList();

The latter operation plays roughly in the same league as SQL Server (don’t flame me – performance comparisons and profiling is really complicated and there is a zillion of factors that influence it, I know. That’s why I say ‘roughly the same league for this query’ and I’m talking about default setups).

This is a somewhat unfortunate situation, because it produces slow queries for many typical applications – unless you have a strong where clause that cuts down N from millions to hundreds. If you’re interested in seeing this issue fixed, head over to their issue tracker and vote for the issue to be fixed! Thanks!

I’ll be posting a bit more on db4o over the next few days I hope.

Post to Twitter Post to Delicious Post to Digg Post to Facebook

Tags: , ,

Random Rant: Don’t Teach Units in Math Class

by Christoph Menge in Off-Topic

A few days ago, I registered at bettermarks, a German startup co-founded by successful entrepreneur Arndt Kwiatkowski. I played around a little pretending I was in 7th class and looked at what they’ve built. This is certainly a very interesting project, and I hope that it will help to improve math lessons in Germany – but that is a long way to go.

Anyway, I don’t want to rant about bettermarks. On the contrary, I think bettermarks is great. But I’m worried about the content of math classes. The content that is specified by politicians. 7th-grade students in Germany seem to constantly deal with units in math. I guess the correct English term is “physical units”. Physical units because units are a concern of physics and, more importantly:

Mathematics is not concerned with units.

That’s the whole point of mathematics: You make things simple so you can handle them. In mathematics, there is no unit of area and unit of length.
Mathematicians are happy if something can be measured at all, a property that not too many mathematical entities have.

Take fractals for example: Suppose I drew a Sierpinski
Triangle
on a piece of paper, how much space do I need to do that?
Obviously, I will need some space if I wanted to actually draw it (physical reality), otherwise I couldn’t see it. Mathematically speaking, however, it has Lesbegue measure 0 and thus, vanishing area. Not square kilometers, apples or Newton, just a number.

How about a Hilbert Curve? I can draw an approximation on some finite area. Now I can refine it, thereby increasing its length, but I don’t need to extend my drawing. Eventually, the length will grow to infinity – how can this be? In the context of soccer fields and living rooms, this doesn’t make sense – it’s purely theoretical. It’s mathematics.

I agree, it is important to teach children about the typical size of a living room, a soccer field or the distance between some well-known cities. But that shouldn’t be done in mathematics: Mathematics should be concerned with abstract thinking only. Many people believe abstract thinking makes classes less appealing to children, but honestly: Do they really think that “Martha owns a set of Miley Cyrus stickers of cardinality 8″ type of exercises make math more interesting, let alone be taken seriously by children?

Post to Twitter Post to Delicious Post to Digg Post to Facebook

Tags: , , , , , ,

db4o Performance Pitfalls

by Christoph Menge in db4o, Software

This is just a quick note, but I just gotta share this right now.

It’s actually in the manual so this is not exactly a secret, but I managed to overlook it so perhaps I’m not the only one…

In our specific scenario, db4o was about 3 times slower than MSSQL via Linq to SQL in the past days.

Just a few minutes ago, I finally read this:

Native Query optimizer for .NET requires the following libraries to work:
Db4obects.Db4o.Instrumentation.dll
Db4objects.Db4o.NativeQueries.dll
Mono.Cecil.dll
Cecil.FlowAnalysis.dll

(see http://developer.db4o.com/Documentation/Reference/db4o-7.12/net35/reference/html/reference/tuning/native_query_optimization.html)

I added these dll’s to my solution and wooosh! Now it’s up to 50 times faster than before! That’s what I needed… Will see how this works with larger data sets…

Update: There have been some important changes in builds past 14021, see my more recent post on that topic. In short, the new kid in town is Mono.Reflection.dll, which took Cecil’s place.

Post to Twitter Post to Delicious Post to Digg Post to Facebook

Tags: , , ,

Areas, Routes and defaults in MVC 2 RC

by Christoph Menge in Software

Download sample

There has been some discussion over at stackoverflow on setting a default route to an area in mvc, so I want to post some very crude, but working example code here… I will write some explanatory text here if I find the time.

I feel that the fact that the order of operation in Application_Start() matters is quite problematic, but that has been discussed elsewhere (I’ll be searching for the link…) Anyway, when registering the areas first, the default route can be set to an area.

        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            RegisterRoutes(RouteTable.Routes);
        }

In the AreaRegistration,

        public override void RegisterArea(AreaRegistrationContext context)
        {
            context.MapRoute(
                "ShopArea_default",
                "{controller}/{action}/{id}",
                new { action = "Index", id = "", controller = "MyRoute" },
                new { controller = "MyRoute" }
            );
        }

will do the job. Note the use of the constraint that will only accept requests to the areas’ controller that should be used as a default.

This is a working solution, but I think it is quite error-prone and not very elegant. In the meantime, I started to use MvcContrib, because it’s portable areas are really smart, make deployment easier and foster reusability of the code, and the views.

Post to Twitter Post to Delicious Post to Digg Post to Facebook

Tags: , ,

A Simple Standalone Server for db4o as Windows Service

by Christoph Menge in db4o, Software

Download: db4oSimpleServer

Lately, I have fiddled around with Versant’s excellent dual-license object database db4o a little and I think object databases are very neat. In fact, I read a few pages in PoEAA [Patterns of Enterprise Application Architecture] today, and here and there Fowler writes how cool object databases are. The Fowler knows!

Well, anyhow when you download db4o (sign up and go for the latest release) there is no standalone server application included. That makes perfect sense, because the server needs access to your domain model / data model dll. In an object database, there are no tables, but there are objects, so you have to compile them into the application that runs the actual db4o server. There is server code which handles practically everything that is tricky, but it’s in a dll so you’ll have to write a few lines to build an application out of it. I figured this would be a great time to write my first windows service and so I mashed up some code I found on the net.

I initially thought the VS 2008 designer would set up pretty much everything, but it turned out that things are a little more complicated.

The Installer

Since a service will run in a different manner, potentially using a different user account, etc. it needs to be installed first. There is a tool called installutil.exe, but using it is a little awkward. Also, you’d have to deploy it along your application. Matt Davis posted a cool guide on stackoverflow and some additional information here on how to write a windows service that is esentially able to install itself!

Unexpected Features

One of the most peculiar features is that -should you prefer to have your own event log instead of writing to the ApplicationLog- you have to search through a tree of installers, find the EventLogInstaller and modify it instead of simply adding a new one because the ServiceInstaller will come along with the EventLogInstaller as a child:

EventLogInstaller installer = FindInstaller(this.Installers);
if (installer != null)
    installer.Log = ServiceConfiguration.LogName;

We also need to take care of spawning the actual worker thread, but fortunately there is a comprehensive guide on MSDN explaining this.

Using the Sample

First things first: Of course, this is not nearly production-safe code! Also, I did not include the db4o dll’s because I’m not sure about the licence terms.

The installer in 'action'. Note the Administrator prompt

  1. Download the sample, extract
  2. Download db4o, install
  3. Copy Db4objects.Db4o.dll and Db4objects.Db4o.CS.dll from the db4o install directory to the samples’ lib directory
  4. Compile
  5. Open an Administrator command prompt and find the sample’s bin folder. There is no feedback in case anything goes wrong (at best, the program crashes)
  6. Call the install routine by executing emphess.db4oServer.exe -install. This will install the db4o server and the associated event log. The server will not be started automatically.
  7. Head over to services.msc or your EventLog, where you should find a new entry!
  8. Edit the configuration file, ready to run!
  9. Don’t use this for anything production…

The App.Config

The configuration file looks like this

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <appSettings>
    <add key="UseLocalFile" value="false" />
    <!-- <add key="DatabaseLocalFileName" value="irrelevant"/> -->
    <add key="DatabaseHost" value="localhost" />
    <add key="DatabasePort" value="52354" />
    <add key="DatabaseServerFileName" value="C:/Development/db4oServer/db/server.db4o" />
    <add key="DatabaseUser" value="test" />
    <add key="DatabasePassword" value="test" />
  </appSettings>
</configuration>

The UseLocalFile setting is meant for clients so you can easily switch between file-based and network-based configurations. Since db4oServer.Shared contains a small class that holds this configuration data, you can easily reuse the code in a different app, e.g. in the client.

Todo-List

There are some things I’d like to add over the next weeks, so I put the list here to give me some ‘pseudo-extrinsic motivation’… (yes, I like complicated words)

  • Simple sample client
  • Out-of-band data for backup, defragmentation commands, etc.
  • Tests / Benchmarks

I hope you have any use for this.

Post to Twitter Post to Delicious Post to Digg Post to Facebook

Tags: , , , ,

A Nice Product Crippled

by Christoph Menge in Software

A screenshot of Yahoo's signup page

Not so delicious

Well… with a few years delay, I just wanted to sign up to del.icio.us, which is now simply called delicious.com. When Yahoo bought it, they obviously decided they didn’t want to have any more users, as you can see on the right.

I want to store some bookmarks online. period. Do they really think I’ll signup for a yahoo mail account (given that I already have a dozen accounts anyway?) Why does one need two secret questions? Secret questions are stupid in my eyes anyhow, but in times of facebook, knowing one’s mothers maiden name does not mean anything… Anyway, can somebody recommend a (good) online bookmarking service? yeah, I know, shouldn’t be too hard to find, hm? I better get some sleep… :)

Post to Twitter Post to Delicious Post to Digg Post to Facebook

Updating WordPress Plugins

by Christoph Menge in Software

Automatic updates are great, especially for web applications. Apart from saving you some time, I believe they help to enhance security since updating is really easy if you just need to push a button. The ‘traditional’ workflow involves backing up, finding and downloading the most recent (compatible) version from an external site, unzipping, uploading via FTP, calling some update script, perhaps setting a maintenance mode, etc.

However, when using shared hosting there are some pitfalls. I just trapped into the “Unable to locate WordPress Content directory (wp-content).” error. Here’s what I did:
My web hoster allows many FTP logins, so I created one especially for WordPress and set its ftp root to the WordPress root
It seems that the error message is a little misleading, because it turned out that access to the temp-directory was the actual problem. In this post, user lightwolf posted a workaround:

putenv('TMPDIR=' . ini_get('upload_tmp_dir'));

Added to wp-config.php.

This fixed my problem.

Post to Twitter Post to Delicious Post to Digg Post to Facebook

Tags: ,

A very simple profiler

by Christoph Menge in Software

When I just posted the source code of the Dependency Property Serialization sample, I realized it included a small piece of source code that might come in handy from time to time:

A very basic, but rather exact profiler. It uses QueryPerformanceCounter. Perhaps I shouldn’t even call this profiler, because a profiler typically keeps track of the parts of code it measures. So let’s call it a precise stopwatch. Well, anyways, here’s the code:

Continue Reading

Post to Twitter Post to Delicious Post to Digg Post to Facebook

Tags: ,

DependencyProperty Serialization Part II

by Christoph Menge in .NET

First off, my apologies for not posting the second part earlier. I have had a lot to do in the past Months…

Part II of the article will show how a SerializationSurrogate works and explore wheter we can use it for generic de-serialization of DependencyProperties. Also, in this article I provide full source code for both parts of the article.

UPDATE: A much better version of this article can now be found at the CodeProject: DependencyProperty Serialization for Business Objects

Alternatively, directly get the source code here: http://www.emphess.net/wp-content/uploads/2009/03/bpboserialization1.zip

Continue Reading

Post to Twitter Post to Delicious Post to Digg Post to Facebook

Tags: , ,