Moving Away From Godaddy

Just a quick update here: My domains, primarily SlimDX.org and SlimTune.com but a few others as well, are currently hosted by GoGaddy. Now GoDaddy is a company with a long, messy history of being a third tier sleaze-bag registrar, but I stuck with them because of pricing. However their recent support of SOPA, and their pathetic recant, pushed me over the edge.

Effective immediately, I am shifting all domains away from GoDaddy. Because I’m rather new to this process, I don’t know what will happen to DNS and email during the transition. SlimDX or @slimdx.org addresses may become inaccessible for a short period while I sort things out. Please bear with me.

If you are interested in moving your own domains, I found out that NameCheap is running a promotion with code “SOPAsucks”. Their pricing is not quite as aggressive as GoDaddy but it appears that they do offer very competitive pricing ($2 specials) nonetheless. Transfers with the code cost $6.99 per domain, which includes a year renewal of the domain. I am sure there are other anti-SOPA registrars but this one is mine.

SlimTune 0.3.0 Released

Hit the SlimTune homepage for the latest release.

The last release of SlimTune was almost exactly a year ago, in February of 2010. The next version has been a very ambitious project, representing a fairly dramatic overhaul of some of the underpinnings. The end result is that, a year later, things look exactly the same. Oops.

In the end, I saw two options. If I did everything I wanted to do, SlimTune 0.3.0 would be an awesome tool, released years too late for anyone to care. Or I could release now, delayed but not catastrophically slow. In terms of the user experience, only two things have changed. .NET 4 applications are now supported. Also, the CLR backend creates its own log file in the user My Documents directory, in order to provide some debugging options in cases that the profiler isn’t able to connect.

Some of the things that didn’t make it in:
* Native profiling support. The code is “mostly” written, but something about how I’m using DbgHelp and the Sym* functions is badly broken. If someone can help me fix these issues (it’s normal C++ code, nothing crazy), I can ship native support. The core sampler pretty much works.
* Silverlight 4. Just a time issue. I’m hoping to do this in the next week or two.
* New visualizers. These were on infinite hold until the core data systems were fixed. They are now fixed, so a lot of UI work is on the way. Again, help would be great. This will be pure C#/WinForms code.
* Snapshots. There’s just no UI for them, mostly because the existing visualizers don’t handle them correctly at all. Replacing those with NHibernate based visualizers should help substantially.

So…it’s out there now. I might make an incremental release with SL4 support, but after that I think it’s time to sit down and seriously write a new visualizer that uses the overhauled data backend, supports snapshots, etc. I’m not sure how long that will take. The native profiler? I’ll release it as soon as someone fixes it for me.

NHibernate Is Pretty Cool

My last tech post was heavily negative, so today I’m going to try and be more positive. I’ve been working with a library called NHibernate, which is itself a port of a Java library called Hibernate. These are very mature, long-standing object relational mapping systems that I’ve started exploring lately.

Let’s recap. Most high end storage requirements, and nearly all web site storage, are handled using relational database management systems, RDBMS for short. These things were developed starting in 1970, along with the now ubiquitous SQL language for working with them. The main SQL standard was laid down in 1992, though most vendors provide various extensions for their specific systems. Ignoring some recent developments, SQL is the gold standard for handling relational database systems.

When I set out to build SlimTune, one of the ideas I had was to eschew the fairly crude approach that most performance tools take with storage and build it around a fully relational database. I bet that I could make it work fast enough to be usable for profiling, and simultaneously more expressive and flexible. The ability to view the profile live as it evolves is derived directly from this design choice. Generally speaking I’m really happy with how it turned out, but there was one mistake I didn’t understand at the time.

SQL is garbage. (Damnit, I’m being negative again.)

I am not bad at SQL, I don’t think. I know for certain that I am not good at SQL, but I can write reasonably complex queries and I’m fairly well versed in the theory behind relational databases. The disturbing part is that SQL is very inconsistent across database systems. The standard is missing a lot of useful functionality — string concatenation, result pagination, etc — and when you’re using embedded databases like SQLite or SQL Server Compact, various pieces of the language are just plain missing. Databases also have more subtle expectations about what operations may or may not be allowed, how joins are set up, and even syntactical details about how to refer to tables and so on.

SQL is immensely powerful if you can choose to only support a limited subset of database engines, or if your query needs are relatively simple. Tune started running into problems almost immediately. The visualizers in the released version are using a very careful balance of the SQL subset that works just so on the two embedded engines that are in there. It’s not really a livable development model, especially as the number of visualizers and database engines increases. I needed something that would let me handle databases in a more implementation-agnostic way.

After some research it became clear that what I needed was an object/relational mapper, or ORM. Now an ORM does not exist to make databases consistently; that’s mostly a side effect of what they actually do, which is to hide the database system entirely. ORMs are actually the most popular form of persistence layers. A persistence layer exists to allow you to convert “transient” data living in your code to “persistent” data living in a data store, and back again. Most code is object oriented and most data stores are relational, hence the popularity of object/relational mapping.

After some reading, I picked NHibernate as my ORM of choice, augmented by Fluent mapping to get away from the XML mess that NH normally uses. It’s gone really well so far, but over the course of all this I’ve learned it’s very important to understand one thing about persistence frameworks. They are not particularly generalized tools, by design. Every framework, NH included, has very specific ideas about how the world ought to work. They tend to offer various degrees of customization, but you’re expected to adhere to a specific model and straying too far from that model will result in pain.

Persistence frameworks are very simple and effective tools, but they sacrifice both performance and flexibility to do so. (Contrast to SQL, which is fast and flexible but a PITA to use.) Composite keys? Evil! Dynamic table names? No way! I found that NHibernate was amongst the best when it came to allowing me to bend the rules — or flat out break them. Even so, Tune is a blend of NH and native database code, falling back to RDBMS-specific techniques in areas that are performance sensitive or outside of the ORM’s world-view. For example, I use database specific SQL queries to clone tables for snapshots. That’s not something you can do in NH because the table itself is an implementation detail. I also use database specific techniques to perform high-volume database work, as NH is explicitly meant for OLTP and not major bulk operations.

Despite all the quirks, I’ve been really pleased with NHibernate. It’s solved some major design problems in a relatively straightforward fashion, despite the somewhat awkward learning curve and lots of bizarre problem solving due to my habit of using a relational database as a relational database. It provides a query language that is largely consistent across databases, and very effective tools for building queries dynamically without error-prone string processing. Most importantly, it makes writing visualizers for Tune and all around much smoother, and that means more features more quickly.

So yeah, I like NHibernate. That said, I also like this rant. Positive thinking!

Next Step for SlimTune

Okay, it’s been a long time since I touched Tune. In fact I think I’m averaging one major blast of work just about every six months. That’s terrible, but I don’t really know what to do about it. I don’t have the bandwidth to run a company and two open source projects at once. Even my involvement with SlimDX is much weaker than it used to be. The difference is that DX has more very competent developers to take care of it; Tune is all on me.

All the same I am back and I’m working on improving the thing once again. It’s been long enough that I can’t remember exactly what the roadmap was or what I was trying to accomplish. (Protip: Write down your roadmaps, people!) That gave me an opportunity to step back and really examine what the state of Tune is. A lot of people were pulling for memory profiling support, which I had slated for 0.3.x and planned to start fairly soon. I no longer think that’s a good idea. It’s more in my (and hopefully your) interests to make the 0.2.x series as strong as possible.

The basic problem is that SlimTune is a really, really cool program with a very mediocre implementation. I still think the ideas in there blow away a lot of the commercial profiling tools out there. All the same, I’m one person and the code’s accumulated about eight weeks of full time work since its beginning (8*40 = 320 total man hours). It’s still a prototype. Before I can do any significant expansion of features, I first need to rebuild the foundation in a stable fashion. The database code is basically a complete loss. The UI is a rough draft. The backend is actually pretty solid, as far as I know, but it isn’t good with error reporting. Things just stop working sometimes.

This is stuff that needs to be tackled long before adding more features. That means I’m not going to see very many users soon, and that corporate adoption will be slow at best. I have several good friends on commercial products who need memory tracking, end of story. But honestly, I have a reputation of building quality work and it’s not casually earned.

In short, the next phase of development is to build the best damn sampling profiler out there.

SlimTune 0.2.1 Released!

I’ve been working towards this milestone for some time now, and it’s finally ready for public consumption. SlimTune 0.2.1 is out!

SlimTune Profiler on Google Code

This version sports a newly retooled interface, along with numerous stability improvements and several new features. To recap, here’s some of the cool things SlimTune can do:

  • Live Profiling – Why should you have to wait until your program has ended to see results? SlimTune reports results almost immediately, while your code is still running. See your bottlenecks in real-time, not after the fact.
  • Remote Profiling – Other tools must be run on the same machine as the application being profiled, which can be inconvenient and worse, can interfere with the results. Remote profiling is an integral part of SlimTune.
  • On-Demand Profiling – Just because your code’s running doesn’t mean you want the profiler interfering. SlimTune lets you profile exactly when and where you need it, so you can focus on the results you need instead of filtering uninteresting data.
  • SQL Database Storage – Instead of developing a custom, opaque file format, we use well known SQL database formats for our results files. That means you don’t have to rely on SlimTune to be able to read your files.
  • Multiple Visualizations – Most performance tools offer a single preset view of your data. Don’t like it, or want it sliced differently? Tough. With SlimTune, multiple visualizers ship out of the box to show you what you want to see, the way you want to see it.
  • Plugin Support – We’re doing our best to produce the most useful visualizations, but that doesn’t mean your needs are the same as everyone else. A few dozen lines of standard SQL and C# code are all it takes to drop in your own view of the performance data, focused on what YOU want to see.

And yes, I know the writing is a bit cheesy, but product pages usually are.

SlimTune was started because the .NET profilers out there suck, or are expensive. I thought there should be a good, open source product out there to support all the developers who are doing real work, but can’t necessarily spend hundreds of dollars per seat for licensing. The more people using SlimTune, the better the feedback will be and the better the thing will get. Please help spread the word, and if you’re using SlimTune for something cool, let me know!

SlimTune Testers Needed

I’m currently working towards the release of SlimTune 0.2.1, which will hopefully happen before GDC. If you’ve been paying attention, that might seem a bit odd to you — 0.2.0 isn’t out yet. That’s because 0.2.0 is the pre-release version, and I need testers for it.

The idea is basically to poke around the new code, let me know about glaring omissions or failures, etc. This is a short process, so if you want to do it I need you to have sufficient time this week. I want to put the final touches in this weekend, if possible. The pre-release will install normally and won’t interfere with an upgrade to the proper release version later on.

I’m particularly interested in verification that ASP.NET is working correctly, and simple sanity checks that everything is that it should be. UI feedback is always welcome, though it may not make it into 0.2.1. In any case, if you’re interested you should email me. The address, as usual, is promit dot roy, gmail.

More SlimTune UI

Still working on the details, but here are some new teaser shots.


[Update] Slightly newer version of the visualizer:

The best part of the current iteration? NO DAMN REFRESH BUTTON! The graph redraws itself, and the counter list updates itself. No user interaction required.

New SlimTune UI Teaser

Here’s a quick teaser of the new UI:

The window hosting the visualizer is missing all of its widgets, but will eventually have a variety of controls along the edges. The revised main SlimTune window is essentially complete. This window is always open as long as SlimTune is running, and maintains a list of the connections that are active. One window, one connection, and closing one closes the other. It’s much easier to keep track of things this way, and the individual windows can be hidden away to reduce clutter if desired.

[EDIT] Starting to think I should stop using JPEG. Even at 100%, it does some horrible things to text.

SlimTune and Services

I’ve now added service and ASP.NET profiling support to SlimTune. Services seem to work, although I’ve tested it pretty minimally. ASP.NET should work but I’m really not set up to test it properly. I might attempt a VM based test later, because I’m not really sure what sort of status IIS is on my main machine and I don’t really want to find out. Still, ASP.NET is little more than a special case of the service profiling.

Unfortunately, it turns out that admin level privileges are required in order to control (and therefore profile) services. I’ve decided not to automatically request privilege escalation in SlimTune. Instead, it simply blocks you from selecting service or ASP.NET profiling unless you’re running with administrator privileges (and pops up a message box explaining this). You’ll have to right click -> Run as Administrator in order to select those options, unless you’ve turned off UAC outright. Kind of annoying, but I figured it was the best compromise.

Incidentally, the code to support this is mostly cloned out of CLRProfiler, with some work to integrate it into SlimTune smoothly. I don’t even understand why half of it is there. You know why? It’s because there’s no other documentation about how to do it. This problem is somewhat endemic across all the .NET profiling bits, unfortunately. It may also affect the debugger documentation, but I’m not sure.

SlimTune is essentially patched together using a combination of a helpful CodeProject sample, the official documentation, blog posts, MSDN forum questions, and experimentation. I’m hopefully that by publishing a reasonably full featured open source profiler, I’m also creating a good practical reference on how to handle the guts of .NET. I’ve considered blogging more about the internals as well, but that remains to be seen.

[Update] I would like to mention, though, that this is vastly more documentation than is available for Mono.

SQLite Support in SlimTune

I’ve mentioned before that most of SlimTune’s core functionality is pluggable. This actually includes the underlying data storage system. The app works through a fairly simple interface, and even SQL is only used by the visualizers and not the core program. To date, the engine in use was Microsoft’s SQL Server Compact Edition (SQLCE). With the next release, I’m introducing support for SQLite as well.

Let’s recap. Every other profiler I’m aware of works in more or less the same way. While the application is running, data is written to a file. Once the run is complete, the frontend steps in to parse the data and visualize it one way or another. SlimTune on the other hand allows (encourages, in fact) live visualization while the application is running. It also supports very different visualizations that slice the data in entirely different ways. The enabling technology for these features is the use of an embedded database. I’m not sure why no one else has taken this approach, but my theory at the time was that it was a simple matter of performance. Databases have to be manipulated with SQL, have to store everything in tables, etc. I suspected that updating a database so often was a problem. My goal was to write a blindingly fast database backend that would be capable of handling large amounts of data efficiently.

I was very, very successful. There’s a number of application side tricks to batch writes together, and I modify the database tables directly instead of issuing queries. The code is quite complex, and annoying to maintain. But the results are nothing short of fabulous. With the standard sampling rate, the database update takes 3-10 ms every second or two, and the frontend process accumulates about one second of CPU time for every thirty on a target single-threaded process eating 100% CPU. Live queries don’t really make a dent at all, since they’re so infrequent. Overall I was thrilled with the performance I’ve gotten out of SQLCE.

I decided to add SQLite support for a few reasons. First of all, it’s cross platform and I’m looking to enable Mac OSX support (and potentially Linux) in this release series. Second, it doesn’t require installation and so distribution could potentially be simplified somewhat. Third, SQLite supports in-memory databases, which MS SQL does not. Some people have complained about the need to create a file every time they run a profile, and that will no longer be necessary.

There was one more reason though — I was honestly curious how the performance of SQLite compares. I started by deciding I didn’t like any of the existing C# wrappers, so I wrote my own. (Wasn’t interested in ADO.NET support.) It’s a simple PInvoke deal, took me an hour to build the support I needed. The SQLite implementation is also much, much simpler than my SQLCE code. As I said before, I work directly with the tables in CE, which is fairly annoying to code. There’s no support for that type of thing in SQLite, so I simply issue prepared statements. All the application side caching tricks are still there, but writes are using normal SQL, one entry at a time. (No batched inserts!)

And how is performance? Equivalent to SQLCE, actually, with far less code and effort. Figures, right? It took a little legwork to get there, but nothing compared to what I spent on making the SQLCE implementation fast. When I started, the amount of time spent in the database was catastrophically long, and I thought maybe I’d wasted the effort. SQLite has a few options which are important to look at in order to get the best possible performance out of it. These options are called pragmas, and they turned extremely poor initial performance into an implementation that is good enough that I’ve now marked the SQLCE code obsolete.

I changed two pragmas in order to get the performance I wanted. Remember that the way I’ve written the code, every single data point (several thousand a second) is a separate transaction. I tried to combine them into one transaction but that failed miserably. I ended up specifying two pragmas:

m_database.Execute("PRAGMA synchronous=OFF");
m_database.Execute("PRAGMA journal_mode=MEMORY");

The first setting had a particularly dramatic effect, about 2000x in fact. It turns out that SQLite’s default behavior is to force a filesystem flush to disk of the database after every transaction ends, which is hideously slow. (I’m told that on some systems, it forces a flush of the ENTIRE filesystem’s pending writes.) Setting synchronous to off disables filesystem flushes, and relies on the OS to get things to disk safely. The second setting moves the transaction journal to memory instead of using a file. Again, with thousands of transactions this is dramatically faster than creating file traffic. Unfortunately it does mean a high likelihood of file corruption if your app crashes, but .NET’s ability to fail fairly gracefully and still run finalizers offers a lot of protection against that.

I’m still planning on a few more database engines to be available. I had kicked around the idea last year of being able to profile to a remote database instead of being restricted to a local filesystem, and I’m eager to see how a full blown MySQL or SQL Server instance handles the data. I’m worried about the amount of data moving through the TCP/IP stack on a single system though. I guess we’ll see what happens. I’m considering enabling plugins for that too, but right now I’m still fighting with how to expose data engine selection in UI. I haven’t figured out a way I like yet.