VirtualBox CPU Performance Tuning

Because my Windows Server 2019 guest system felt quite sluggish, I first googled (of course! šŸ˜‰ and then tested myself to improve the performance.

Thanks to a blog entry from Mihai Matei on the topic at hand y had an idea on where to look and I could confirm his findings regarding Hyperthreading.

Here are my test-details, in case you are interested. If not you can jump right to the conclusions at the end of the article.

CPU: Intel 8350U (4 Cores, 8 Threads, 15W TDP)
Host RAM: 32GB
Host OS: Windows 10 Pro (1809) 64 bit
Guest OS: Windows Server 2019
Benchmarking-Tool: CPU-Z

Mulithreading on (Bios setting on host)

CPU-Z benchmark results on the host

  • SC: 406
  • MC: 2002

    Guest with 4 Cores

  • Observation: Opening Windows Explorer slow
  • CPU-Z-Bench
    • SC: 280 Max
    • MC: 1300 Max

      Guest with 1 Core

  • Observation: Opening Windows Explorer much faster
  • CPU-Z Bench
    • SC: 360
    • MC: 360
    • Note: SC is substantially higher, but MC a lot lower. The GUI feels a lot more responsive with only 1 core assigned.

Mulithreading off (Bios setting on host)

CPU-Z on the host

  • SC: 411
  • MC: 1540
  • Note: SC performance not changed, but about 25% loss on MC performance.

Guest with 4 Cores

  • Observation:

1) Task manager on guest: 6% (almost idle), task manager on host: 28% for VirtualBox task
2) CPU-Frecuency drops from 3,6 to 2,5 during MC test and goes only back up to 3Ghz during SC. Explanation: CPU seems to throttle because of temperature (monitored with HW Info Tool). Environment temp is about 32 C

  • CPU-Z-Bench
    • SC: 295 Max
    • MC: 1070 Max

Guest with 1 Core

  • Observation: The benchmark does not get 100% CPU, because 18% is eaten up by “System Interrupts” accoring to task manager.
  • CPU-Z Bench
    • SC: 370
    • MC: 360

Guest with 2 Cores

  • Observation: System interrupts low (2%, almost all % used by benchmark)
  • CPU-Z Bench
    • SC: 370
    • MC: 730
    • Note: Best result so far. SC performance still high and MC doubled compared to 1 Core.

Guest with 3 Cores

  • Observation: System interrupts low (2%, almost all % used by benchmark). Looks like 3 cores is not a good idea! šŸ˜‰
  • CPU-Z Bench
    • SC: 305
    • MC: 660

Conclusion

On my particular system the best setting for my Windows Server 2019 guest are:

  • Host: Disable hyperthreading in BIOS settings
  • VirtualBox Guest Settings: Assign 2 cores

Due to the switched off hyperthreading some mulithreading performance is lost. But as I am mostly depending on high single-threading performance for compiling tasks it is not an issue.

Depending on your CPU and number of cores available your optimal settings may vary.

Developer and Power User Tools for Windows

This is a collection of the important tools for development and productivity I currently use (C#, ASP.NET, WPF, JavaScript).

.NET

Web development

  • Chrome DevTools – Debug and analyse your frontend stuff. Some Tips and Tricks.
  • Charles Web debugging proxy – See all HTTP/HTTPS traffic of your app. Especially useful if you debug something that does not run in a browser (.NET app, …).
  • WinSCP – Free SFTP, SCP and FTP client for Windows.
  • Putty – Free SSH client
  • BrowserSelector – Windows tool to open different browsers based on the URL. Great if you are using different browsers for different things. I love it!

REST (Web API)

  • httpstat.us – Generate different HTTP status code. Simulate delays
  • Mockoon – Multi-Platform API Mock software. Great UI, simple to use and tons of features (dynamic responses, CORS, delays, …)

Editors, file comparison

  • VS Code – powerful, open-source multi-platform editor. Don’t use it too much, since I do most of my work in Visual Studio. But I like to use it for editing certain file types (XML).
  • Notepad++ – My workhorse for analysing log-files, search and anything not done in VS Code or Visual Studio.
  • HxD Hex Editor – Nice hex editor. Can calculate checksums like CRC-16.
  • Beyond compare – Compare files, folders, merge, synchronize. An evergreen in my tool belt for comparing stuff.

Automation

AutoHotKey – Very complex and powerfull tool to automate your windows applications

Database

System tools

  • WinDirStat – Visualize the occupied space on your disk. I use that for deleting crap when the disk is getting full.
  • MiniTool Partition Wizard – Manage partitions, move OS from harddrive to SSD and much more. Many features already available in the free version.
  • CPU-Z – Lightweight and fast tool to check you hardware-configuration and run some basic CPU benchmarks.

Graphics

  • Paint.NET – Free and powerful image editor. When Photoshop is too much (and too expensive).

Media

  • ActivePresenter – Records your screen and microphone. Used it for recording tutorials (screencast for YouTube). It also makes a great tool for helping you test your GUI, as you can record what you are doing and what is happening. When something breaks, you can replay and go back in time. Version 7 did not work for me, better try Version 6 of their program while it’s still available.

Health and productivity

  • OneNote – All my notes, bookmarks, screenshots and complete knowledge bases go into OneNote. Make screenshots, format your entries with simple keyboard-shortcuts without touching the mouse, collaborate on content with notebooks stored on MS SharePoint or OneDrive.
  • EyeLeo – Prevents eye strain. Gentle reminders now and then to get your eyes off the screen.
  • Tomighty Pomodoro timer – Get more done with more breaks. The Pomodoro technique works out great for development. Moving my body every half-hour amps up my creativity and helps me getting unstuck. I prefer to move my body, jog for a couple of minutes. Many times it’s off the screen when the aha-moments hit me.

 

For a much more extensive list of tools check out the resource from Scott Hanselman. Last time I checked it has been updated in 2014, but still of great value for discovering stuff:

Scott Hanselman’s Ultimate Developer and Power Users Tool List for Windows

Another list by Steve Smith (aka Ardalis), who I admire for his software design and coding skills:

Ardalis – Tools Used

 

Notes about Live Unit Testing in Visual Studio

MS introduced Live Unit Testing in the Enterprise edition of Visual Studio 2017.

I quite like it. A few notes about some issues I had:

  • Don’t mix testing frameworks (MsTest, NUnit, xUnit). Live testing will use one or another test adapter, but only one at the same time. Depending on which one is active you will have tests excluded from live-testing.
  • Update your references. If you cannot debug your unit-tests anymore with Live Unit Testing enabled, have a look at this support case. You might need to delete your existing project reference to “Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll” and install the NuGet packages MSTest.TestAdapter and MSTest.TestFramework instead.
  • Choose your tests wisely. You might want to exclude your long-running integration tests and other tests from being executed by Live Unit Testing: Right-Click on your test project, go into that “Live Unit Testing” entry and include and exclude what you need to be covered by Live Testing.
  • Included test files not updated automatically. If you have included test-data files in your project that are copied to your Output Directory by the build process: These are not updated automatically. I had to Stop and Start Live Testing in order to access added or updated files.

Hope you find that helpful.

Breakpoint in ASP.NET MVC View not hit when using RazorGenerator

If your breakpoints in an ASP.NET MVC view are not hit: Check if you are using RazorGenerator for this particular view:

Screenshot of ASP.NET MVC view Properties. Custom tool set to RazorGenerator
RazorGenerator enabled for ASP.NET MVC view

Fix: Temporarily disable Razor Generator removing the “RazorGenerator” text from the Custom Tool property. Make sure to put it back in after your debugging session.

 

Change of connection string in deployed WEB.CONFIG overridden by Application setting

I just had an issue with a deployed ASP.NET app on Azure: I changed the connection string in the deployed web.config using the new App Service Editor in the Azure Portal, but the changes had no effect in my application!

This answer from StackOverflow gave me the hint I needed: My connection string was being overridden by an Application Setting in the Azure App Service. I didn’t even know that it was configured.

To see if you have a connection string defined in your Azure App service log into the Azure Portal, open your App Service and go to Settings -> Application Settings -> Connection strings.

Fixes

  1. Delete the connection string in the Azure application settings. Now you can change the connection string in the web.config using the App Service Editor, for example.
  2. Use the Azure application settings to manage your connection strings. The values defined here will always override the connection strings from your web.config.

“Inconclusive” error in ReSharper unit test runner caused by “async void”

The ReSharper unit test runner doesn’t like test methods which are declared as “async void”.

Unfortunately you won’t get any compiler or intellisense warning to tell you. When trying to run the test in ResSharper unit test runner it will first get a blue question-mark icon and when you run it individually it will get the test result Inconclusive.

Example of an “conclusive” test result and a good one.

Code:

[TestMethod]
public async void This_Test_Will_Cause_Inconclusive_Message()
{
    // tests
}

[TestMethod]
public async Task This_Test_Will_Run_Ok()
{
 // tests
}

 

How to reset a SQL Server LocalDB instance in Visual Studio

Many Visual Studio project-templates configure a SQL Server LocalDB instance for development on your local machine. For example the ASP.NET with Identity template.

But what to do if that database gets corrupted or you need a clean one for testing your Entity Framework Migrations, for example?

One solution is this:

  1. Open up the Package Manager Console (Tools -> NuGet Package Manager -> Package Manager Console). Make sure to select the project containing your database in the DefaultProject dropdown.
  2. Enter the commandĀ sqllocaldb infoat the prompt. The result is the name of your SQL Server LocalDB instance.
  3. Enter the command sqllocaldb stop InstanceName. Replace “InstanceName” with the name you got from the previous command.
  4. Enter the command sqllocaldb delete InstanceName. Replace “InstanceName” as in the command before.

    Commands to stop and delete the LocalDB database.
  5. Open the folder where the database files (*.mdf) are stored.

    Open App-data folder in Windows Explorer
  6. Delete the two *.mdf files in the folder.

Depending on your configuration your database will be re-created automatically when you execute your application or runningĀ Update-Databasein the Package Manager Console.

 

Show PDF in browser instead of downloading (ASP.NET MVC) without JavaScript

If I want to display a PDF file in the browser instead of downloading a copy, I can tell the browser via an additional Content-Disposition response header.

This code example assumes that the file content is available as byte-array, reading the content from a database, for example.

// Get action method that tries to show a PDF file in the browser (inline)
public ActionResult ShowPdfInBrowser()
{
  byte[] pdfContent = CodeThatRetrievesMyFilesContent();

  if (pdfContent == null)
  {
    return null;
  }

  var contentDispositionHeader = new System.Net.Mime.ContentDisposition
  {
    Inline = true,
    FileName = "someFilename.pdf"
  };

  Response.Headers.Add("Content-Disposition", contentDispositionHeader.ToString());
  return File(pdfContent, System.Net.Mime.MediaTypeNames.Application.Pdf);
}

Please keep in mind that ultimately we don’t have control over the browser. We can politely request to show the PDF inline, but this can be overridden by a user configuration, for example.

Keep your eyes healthy

Staring at our screen all day long can take a toll on our eyes:

I was forced to wear glasses a few years ago for which I blame my screen-time. Since then I am more conscious about the health of my “biological data interface” (eyes) and just got myself computer glasses with blue filter, although I am not sureĀ  if they are necessary. The information available on the web is contradictory, but I have an acquaintance who fixed her problem getting tired with computer-glasses.

What DID convince me though is this free tool for Windows-User: EyeLeo. It will ask me every now and then to exercise my eyes. Together with Tomighty Pomodoro timer I get the frequent breaks I need to finish my work days without my eyes hurting.