skip to content
Relatively General .NET

Caching Enum.ToString to improve performance

by Gérald Barré

posted on: June 14, 2021

Converting an enum value to a string using the ToString() method is expensive. In general, the performance impact is negligible. But when you call the ToString method thousands of times per second, saving a few milliseconds is important.C#copyenum Color { AliceBlue, AntiqueWhite, Aqua,

Webinar

by Oren Eini

posted on: June 11, 2021

The performance regression odyssey

by Oren Eini

posted on: June 10, 2021

We care a lot about the performance of RavenDB. Aside from putting a lot of time an effort into ensuring that RavenDB uses optimal code, we also have a monitoring system in place to alert us if we can observe a performance degradation. Usually those are fairly subtle issues, but we got an alert on the following scenario. As you can see, we are seeing a big degradation of this test.The actual test in question is doing a low level manipulation of Voron (RavenDB’s storage engine), and as such, stand at the core of our performance hotspots to watch for.Looking at the commits around that time frame, we quickly narrow the fault down to the following changes:A really important observation here, however, is that this method is not called in the test. So we were looking at whatever this change caused a regression in code generation. I couldn’t believe that this is the case, to be honest. Indeed, looking at the generated assembly, there was no difference between the two versions. But something cause the performance to degrade significantly enough for this test that it raised all sorts of alarm bells.We started looking into a lot of details about the system, the usual things like checking for thermal throttling, etc. We struck gold on this command: sudo smartctl --all /dev/nvme0n1Take a look at the results: SMART overall-health self-assessment test result: FAILED! - NVM subsystem reliability has been degraded SMART/Health Information (NVMe Log 0x02, NSID 0x1) Critical Warning: 0x04 Temperature: 35 Celsius Available Spare: 100% Available Spare Threshold: 10% Percentage Used: 115% Data Units Read: 462,613,897 [236 TB] Data Units Written: 2,100,668,468 [1.07 PB] Host Read Commands: 10,355,495,581 Host Write Commands: 9,695,954,131 Controller Busy Time: 70,777In other words, the disk is literally crying at us. This tells us that the drive has been in action for ~50 days of actual activity and that it has gone beyond is design specs. In particular, you can see that we wrote over a petabyte of data to the disk as part of our test case executions. This is a 500GB drive, which means that we fill it to capacity over 2,000 times before we hit this issue.Once we hit this capacity (Percentage Used is > 100%), the drive needs to do a lot more work, so we are seeing longer test times.First time that I closed a bug by sending a PO to get new hardware, I got to admit.

Messing up a live demo, opps

by Oren Eini

posted on: June 09, 2021

Yesterday I had presented a webinar on using Machine Learning and Time Series in RavenDB. One of the things that I love about doing those webinars is that I get to field questions from the audience and have to really think on my feet.In almost all cases, I think that I am able to provide good answers, and I usually accompany these with a live demo showing what is going on.Yesterday, that wasn’t the case. During the demo, I managed to run into a fairly obscure bug very deep in the internals of RavenDB and got the wrong results. Then I got stuck on that and couldn’t figure out what is a proper workaround until just after the webinar concluded.Hugely embarrassing, but at least I can take comfort that it wasn’t the first time that a live demo failed and probably won’t be the last time. The good news, on the other hand, is that I created an issue to fix this problem. Today I made myself a cup of coffee and was about to dig into the problem when I realized that it has already been fixed. Time from opening the bug to it getting fixed, under 6 hours. That is without rushing it, mind you. I think that given the turnaround time, it is a good thing overall that I run into this.The actual problem, for what it is worth, is that we had lazily evaluated a collection during its enumeration. However, when using GroupBy(), we effectively enumerated the value twice, fetching different values each time. The second time, we would use the last value from the collection, since it was lazily evaluated. You can check the pull request if you are that much of a nerd .

C# Generics Best Practices

by Ardalis

posted on: June 08, 2021

There was a time when C# didn't support generics. It was a dark time. Ragged bands of .NET developers roamed the harsh landscape, copy…Keep Reading →

Different ways to check if a value is null in C#

by Gérald Barré

posted on: June 07, 2021

In .NET, there are multiple ways to check if a value is null. But all of them are not equivalent. Let's look at the different ways to check if an object is null:C#copyobject obj = ...; obj == null; object.Equals(obj, null); object.ReferenceEquals(obj, null); obj is null; // Equivalent to

Nulls in Value Objects

by Vladimir Khorikov

posted on: June 03, 2021

Today, we’ll discuss an interesting use case of handling nulls in value objects. Should you put null inside the value objects themselves or decorate those value objects using the nullable reference type notation (? or Maybe)?

Monitor your RavenDB instances using Grafana

by Oren Eini

posted on: June 01, 2021

You can now get a Grafana dashboard that would monitor your RavenDB instances. You can use Telegraf 1.18.0+, which includes a RavenDB input plugin, which will expose all the relevant details. You can see how that would look like:This is part of the work we want to do in order to make it easier and smoother to operate your RavenDB clusters. It joins the work we do on the cluster dashboard as well as a host of other (mostly minor) changes.

What If Product Owners Reported to Dev Teams?

by Ardalis

posted on: June 01, 2021

In most organizations, if there's a Product Owner, the dev team is generally subservient to it and charged with building whatever the…Keep Reading →