Notes from Delphi Days (Delphi Tage) 2014

After doing new development mostly in C# for the past couple of years, I’ll be creating some major additions to a (legacy) Delphi application soon. I already got Delphi XE7, so I figured what better way to catch up than attending the Delphi Tage which happened to be fairly close again (I attended once before in 2011, when they were held in Cologne).

In the end, I didn’t learn that much about Delphi (except for Marco Cantu’s keynote). Instead, of the sessions offered, the ones that interested me most, were actually not about Delphi at all.

TypeScript

Bonn (2)Most of the applications I work on are heavily multi-threaded server applications. Occasionally, I also get to write a client application. Except for some HTML+CSS experiments in college, I’ve never worked on web applications. Hence, I have never written a single line of JavaScript code.

Part of the reason is that I’m skeptical of dynamic languages in general. I have done some Python development and on more than one occasion I have tripped over issues that would have been easily avoidable in a language with strong typing and compilation.

Enter Anders Hejlsberg.

He’s one of my favorite people in software development. That’s not very surprising  as he is the “father” of Turbo Pascal, Delphi and C#, the three languages that have determined my path as a software developer from my very first line of code till now.

His latest project has been TypeScript, a superset of JavaScript that basically adds everything that’s been missing from the language to make it useful for larger development projects. This is, in my opinion, exactly what that language needed and I don’t know why anyone would still be writing pure JavaScript instead of switching to TypeScript.

So in an effort to branch out and learn something new this year, I really want to learn TypeScript and develop something useful in it.

Distributed Version Control

I’ve been an avid reader of Joel Spolsky’s Joel on Software since the beginning of college (i.e. for more than ten years now). So I first heard about distributed version control when his company FogCreek was developing Kiln and he published Hg Init, a Mercurial tutorial.

I didn’t think much of it, because I was mostly a coder then and didn’t care about the tools used throughout the development lifecycle other than my IDE. As more and more of my work is in project management and other “meta” tasks these days, I now know what an impact the right choice of tools has on workflow and productivity. This is why I was particularly interested in this session and hearing peoples’ experience with real-world DVCS usage.

I mostly use Perforce, though for some things I have to put up with CVS (which I’d rather not talk about). Looking at a DVCS such as Mercurial I can see how someone coming from CVS or Subversion could get a lot of value out of switching to a DVCS. However, a lot of the supposed advantages of using a DVCS, I think, are really things you can do with a centralized version control system; such as larger number of smaller check-ins instead of just one check-in a day or one a week. It’s really just a question of how you and your team decide to work. With the way I use Perforce, I think I’m already doing 90% of what’s supposedly so great about DVCS.

One thing I was quite shocked by was learning how many people in the audience did not use a real version control system at all. Instead they used group messaging to tell others what they are working on and thus “lock” a file, or resorted to regularly zipping and archiving their code manually.

Plans

As a next step, I want to give Kiln a try (it’s free for up to two users) by storing my .NET Gadgeteer code there. This is a project I stared about two years, yet never really finished. But once the code is there, I want to improve it and finally get it working with Wifi. For that, I’m also going to get the latest version of Visual Studio Express as that comes with full support for TypeScript and I can play with that, too. We’ll see how it goes.

Final thoughts

It was a fun day and even though I don’t do much with Delphi these days, it’s nice seeing the community. I like the fact that it’s rather small and you have the same people popping up everywhere. If you’ve ever asked a Delphi question on Stack Overflow, you’ve probably interacted with some of them already.

Reading up on Windows Server 2008 R2

For reasons I would rather not into detail about, I had to help with setting up a Windows Server 2008 R2 machine. Researching this, I found this great video on Channel 9 from PDC 2009 by Mark Russinovich: Windows 7 and Windows Server 2008 R2 Kernel Changes Part 1 and Part 2.

Here are a couple of the key takeaways from that talk from a performance point-of-view.

Timers

It’s been said before and even made it into a Forbes article, but it’s worth repeating, because many applications (even major ones) get it wrong anyway:

Don’t mess with the system timer resolution (via timeBeginPeriod) because it will increase overhead and thus reduce performance.

I remember having a system where Sysinternals ClockRes showed the timer resolution being way higher (i.e. lower tick interval) than it should have been. Unfortunately, I had no idea what application was responsible for this. In Server 2008 R2, however, one has a way of finding out:

powercfg.exe -energy duration 5

This will produce an HTML report showing you a couple of things that can have an impact on your system’s power consumption (and performance), including the processes that changed the timer resolution.

Power Plan

Also in this report is your system’s power plan. The default is Balanced, which may not be the best choice under certain circumstances. I found a couple of good articles on the topic:

Scott Hanselman’s blog post in particular left me convinced that High Performance was the way to go, given my intended use for this server is pretty close to what he described.

Dispatcher Lock Gone

In my own testing I noticed that the same application on Windows Server 2008 R2 was scaling much better with more threads than it did on Windows Server 2003 (R2). I’m not sure I have (the absence of) the dispatcher lock to thank for that, but I here’s what I noticed:

  • On Server 2003, multiple threads would not use all of the available CPU, and queues of outgoing messages would built up. Distributing the work over more threads did not improve overall throughput.
  • On Server 2008 R2 with the same number of threads, there were no queues in data processing and we reached a limit only when the NIC exceeded 90% utilization.

This was far better than I had expected. To be fair, I have not tested to what degree the increase in performance can be attributed to newer hardware versus the newer operating system. But since I can’t have one without the other, I don’t think it matters.

A Cautionary Tale

I am not entirely sure whether this is related to the absence of the dispatcher lock, but migrating to Server 2008 R2 also revealed a very nasty concurrency problem in one application. The code had been running fine for many years on Server 2003, but failed rather quickly on Server 2008 R2. My guess is that the increased degree of parallelism in 2008 R2 just made it more likely for the race condition to reveal itself.

It also shows that upgrading from 2003 to 2008 R2 (or newer) does require some testing. Even though I have not run into any APIs that were changed, there appear to be subtle timing changes such as this one that could make an application stumble.

Conclusion

I was pretty amazed how much better our Server 2008 R2 machines performed compared to the old 2003 machines after checking the settings mentioned above. If there are other’s I have missed, please leave a comment.

I still have to research the changes coming in Server 2012 (R2), maybe Windows Server got even better in that version.

Experimenting Some More

Normally, on a Sunday like this I would go running in one of the nearby parks. However, a month ago Düsseldorf was struck by one of the worst storms in recent history and about 17 000 trees in this city alone were destroyed or damaged.

The fire department (helped by other emergency services and even combat engineers from the army) did a tremendous job clearing the streets and allowing public transportation to resume within a few days. Despite the severity of the storm, the impact on public life was rather low.

The city’s many other patches of green including the parks I use to go for a run, though, are still not entirely safe again. So many of them have been closed off to the public out of fear that some loose branches might fall down (although I haven’t heard of anybody getting injured after the initial storm).

So instead of running, I took out my camera and shot what the areas I would usually run at looked like. Not a pretty picture.

Panorama Black & White

Detail Black & White

On a more positive note, here’s a shot I did experimenting with my new 18-250mm lens last week. After borrowing my father’s lens a while ago, I was so taken with its possibilities, I just had to get my own.

By the way, the bottom picture in that post was taken in the same park (though not the same spot) as the ones above. Once the park is accessible again, I’ll try to recreate the shot. I’m afraid there is going to be considerably less green there.

Smart Herb Garden

One of the most fun projects I backed on Kickstarter has been Smart Herb Garden from Click & Grow.

I don’t cook a lot; in fact I barely spend any time in my kitchen. But still, I’ve been very excited about watching this thing grow. The first batch of seeds I’ve “planted” was Basil, Mini Tomatoes and Salad Rocket.

Below are a couple of pictures documenting my garden grow. I’ll update this page as time goes on and harvest approaches.

18 April 2014: Unpacking

Smart Herb Garden

13 May 2014: Seeds planted

Smart Herb Garden

21 May 2014: First Green

First Green

25 May 2014

Smart Herb Garden

29 May 2014

Smart Herb Garden (1)

Miscellaneous

At night, the light casts a very interesting pattern onto the ceiling of my kitchen.

Lichteffekte

Random Pictures

If I were asked what my hobbies were, I probably wouldn’t list photography among them. Nonetheless, I like to grab my camera every now and then and take some pictures. And sometimes, I even like to sit down afterwards and fiddle around a bit in Photoshop Elements to touch them up.

Here is a random selection of some of the more recent ones. I take most of my pictures while traveling, so you’ll find them included with one of my Travel posts.

In Orbit von unten

Frische Luft und Kamillentee

Dach

The Case of Metro Apps not Starting and Failing to Install

Inactive TileI don’t not how this got started, but at some point I noticed that more and more Metro apps (or Modern apps or Windows 8 apps or whatever you want to call them) were no longer working properly. I haven’t been able to locate a solution online, so I figured one out myself and document it here in case someone encounters the same problem.

The Symptoms

Failed InstallationsLive tiles on the start screen were no longer showing updates, but instead had an X in the bottom right corner (see screenshot at the top). When started, these apps would either briefly display their splash screen and then terminate, or go back straight to the desktop.

Also, the apps no longer updated, showing the following error messages in the Windows Store (see screenshot on the left) and varying error codes, such as 0x80070002 or 0x80073D05.

Looking for Answers

I found descriptions of similar problems online, and even this quite comprehensive selection of fixes. Unfortunately, none of them worked for my particular case.

So I dug around in the Windows event log. Recent versions of Windows actually store quite a lot of information in there. And it’s much better structured than in earlier releases that lumped most events into just three sections: Applications, Security and System.

From my online research I knew that apps were being installed by a process called AppX deployment. So I looked through everything mentioning that in the event log and I found this error under Application and Service Logs\ Microsoft\ Windows\ AppXDeployment-Server\:

Cannot register the request because the following error was encountered during the registration of the windows.stateExtension extension: An error occurred while deleting the package’s previously existing application data.

Event Viewer

Further research online showed that there are two locations where apps store data (possibly more that I don’t know of):

  • On disk: C:\Users\<YourUserName>\AppData\Local\Packages
  • In the registry: HKEY_CURRENT_USER\ Software\ Classes\ Local Settings\ Software\ Microsoft\ Windows\ CurrentVersion\ AppModel\ SystemAppData\

The Cause

Turns out, it was data in the registry that was causing problems. I’m not sure how this is related, but in each of the affected apps’ keys there was an “invalid DWORD (32-bit) value” named STATE_LEFT_FROM_LAST_UNINSTALL. None of the working apps seemed to have had this value.

image

As I was trying to access the sub-key “PSR” of one of the applications that wasn’t running, I got the following error. Deleting the key didn’t work either.

image

image

Since I was denied access (though I had started regedit as an administrator), maybe the installer was denied access, too. Checking the permissions, I got this message and then an empty permissions dialog.

image

image

The Solution

I couldn’t change the permissions for the app’s PSR in this dialog right away and I couldn’t even view the owner (under Advanced). But I could take ownership of that key and then I was able to grant myself full control over the key. And with full access I was now able to delete the key for the app, including the PSR key.

After I had repeated this for each one of the affected apps, I went back into Windows Store, retrying the installation. And lo and behold, all apps installed correctly and are now working properly.

Aftermath

I never found out why the permissions on those registry keys got messed up. I just know that through the process described above, I have got all my apps working again.

Unfortunately, I still have a problem with the OneDrive and Photos apps on Windows 8.1 as described in this post on the Microsoft support forums. But since OneDrive and Photos aren’t apps that are installed via the Windows Store, the above trick does not work on them. So I’m still trying to figure that one out…

Düsseldorf Skyline

Stadtpanorama

I don’t know what it is about this picture, but I just really love it. It so wonderfully captures the atmosphere of a perfect Saturday night last week.

I didn’t even need to edit it much. It’s just two pictures I took with my phone (a Lumia 920) stitched together and cropped, with a little bit of sky generated in the top left corner in Photoshop.

WP_20140503_002 WP_20140503_003