Blog

Notes from the Field: Don't Overlook NGen Optimization in Non-Persistent Citrix Environments

In non-persistent Citrix DaaS Local and Cloud environments, monitoring and managing write cache consumption is essential for maintaining stable and reliable operations. Unexpected write cache growth can eventually lead to serious problems, potentially affecting VDA availability and disrupting active user sessions.

Recently, while supporting a Citrix Provisioning (PVS) environment, we encountered an issue where the write cache on several non-persistent Virtual Delivery Agents (VDAs) was growing unexpectedly fast.

The issue was initially identified through MetrixInsight for Citrix VAD/DaaS, which provides monitoring capabilities for PVS write cache consumption.

NGen optimization in the writable master image prevents repeated compilation writes to the PVS write cache.
MetrixInsight warning: the drive containing the PVS write cache is 85% full.
Figure 1: MetrixInsight for Citrix VAD/DaaS warning about high disk usage on a drive containing a PVS write cache file. Open full-size screenshot

This prompted us to investigate what was generating the excessive disk writes.

As it turned out, the underlying cause was an often-overlooked Windows background process: the .NET Framework Runtime Optimization Service.

Understanding Citrix PVS Write Cache and Its Impact

In a Citrix Provisioning environment, multiple VDAs can boot from the same shared virtual disk (vDisk). When running in standard image mode, the vDisk is read-only, meaning that changes made by individual VDAs cannot be written back to the shared image.

Instead, write operations are redirected to a separate write cache. Depending on the configured caching mode, this cache can reside in memory, on disk, or use a combination of both.

This allows each VDA to operate as if it has its own writable system disk, while the underlying shared image remains unchanged.

However, disk writes generated by Windows, installed applications, background services, and user activity all contribute to write cache consumption. In a non-persistent configuration, these changes are normally discarded when the VDA restarts, meaning that the same disk writes may occur repeatedly during subsequent machine startups.

When the write cache reaches its capacity, the VDA may no longer be able to complete write operations to its system disk. Depending on the caching configuration, this can result in application failures, unresponsive user sessions, operating system instability, or even complete VDA unavailability.

Regularly rebooting non-persistent VDAs is therefore an important best practice. Scheduled reboots help reset the write cache, remove accumulated changes, and return machines to a clean state based on the published master image.

The appropriate reboot frequency depends on the workload, write cache capacity, and operational requirements. For many environments, daily reboots outside business hours are a practical approach, while others may require a different schedule.

However, scheduled reboots should not be considered a solution to excessive write cache consumption. If the underlying cause remains unresolved, the same background processes may simply generate the same disk writes after every reboot.

This makes proactive monitoring of PVS write cache consumption important for identifying abnormal growth before it impacts users and service availability.

Identifying the Source of the Disk Writes

Our initial investigation focused on common sources of background disk activity, including Microsoft Defender, Microsoft Edge updates, and Windows Update.

Although we observed activity from some of these components, the collected logs did not provide sufficient evidence to explain the excessive write cache consumption.

To identify which processes were responsible, we used Windows Resource Monitor (resmon.exe) and examined the Disk Activity section.

By sorting the activity by write throughput, we discovered that multiple instances of mscorsvw.exe, associated with the .NET Framework Runtime Optimization Service, were generating substantial disk writes.

These processes were writing native image files to the following directory:

C:\Windows\assembly\NativeImages_v4.0.30319_64\

At the time of investigation, the combined write activity of these processes exceeded 12 MB/s.

Resource Monitor: mscorsvw.exe processes writing .NET Framework native images.
Figure 2: Windows Resource Monitor showing multiple instances of mscorsvw.exe generating significant disk writes to the .NET Framework native image directory. Open full-size screenshot

This finding pointed towards pending .NET Framework native image compilation tasks as a likely explanation for the unexpected write cache growth.

Why NGen Optimization Matters in Non-Persistent Environments

The .NET Framework Runtime Optimization Service uses the Native Image Generator (NGen) to compile managed .NET Framework assemblies into native images.

These native images are stored locally and can improve application startup performance by reducing the need for Just-In-Time (JIT) compilation.

Following the installation or updating of Windows components, .NET Framework components, or applications, native image compilation tasks may be queued for background processing.

On a persistent Windows machine, the generated native images remain available after a reboot.

However, in a non-persistent Citrix PVS environment, pending compilation tasks inherited from the master image may be processed again after each VDA startup. The resulting native images are written to the redirected write cache rather than the read-only shared vDisk.

Because these changes are discarded when the VDA restarts, the same compilation work can be repeated during subsequent machine startups.

This means that a background optimization process intended to improve application performance can repeatedly consume valuable PVS write cache capacity.

In addition to generating significant disk writes, native image generation can also be CPU-intensive. Compiling .NET Framework assemblies into native code requires processing resources, which may result in increased CPU utilization while the optimization tasks are running. This can also affect application responsiveness and the user experience, particularly when the compilation tasks are still running as users begin connecting to their sessions.

Resolving the Issue

To resolve the issue, we completed the pending .NET Framework native image compilation tasks directly in the writable PVS maintenance image, before promoting the updated vDisk version to production in read-only (standard image) mode.

From an elevated PowerShell session, we executed the following commands.

For 32-bit .NET Framework components:

& "$env:windir\Microsoft.NET\Framework\v4.0.30319\ngen.exe" executeQueuedItems

For 64-bit .NET Framework components:

& "$env:windir\Microsoft.NET\Framework64\v4.0.30319\ngen.exe" executeQueuedItems

These commands instruct NGen to process pending native image compilation tasks.

On 64-bit Windows systems, both commands should be executed to ensure that queued tasks for both 32-bit and 64-bit .NET Framework components are completed.

After allowing the commands to finish, we finalized the maintenance image and deployed the updated version to the production VDAs.

Following this change, the unexpected write cache growth was resolved.

The .NET Framework optimization tasks no longer generated the excessive disk write activity we had previously observed.

Including NGen Optimization in Your Image Maintenance Process

Based on this experience, we recommend including NGen optimization as part of the regular maintenance procedure for non-persistent Citrix images.

In particular:

  • Complete pending NGen tasks after installing or updating applications and Windows components in the master image.
  • Run both the 32-bit and 64-bit NGen commands on 64-bit Windows systems.
  • Perform these optimizations in the writable maintenance image, rather than on production VDAs where the resulting disk writes would consume write cache space.
  • Monitor PVS write cache consumption after deploying updated images to detect unexpected background disk activity.

It is also worth noting that image optimization tools such as Citrix Optimizer provide functionality to process pending .NET Framework native image generation tasks as part of the image optimization process.

If you are already using Citrix Optimizer or a similar tool during image maintenance, make sure this optimization step is included and successfully completed before promoting the updated image to production.

Regardless of whether you use an optimization tool or execute the NGen commands manually, the objective remains the same: complete pending native image compilation tasks in the writable master image rather than allowing them to run repeatedly on non-persistent production VDAs.

Final Thoughts

Unexpected PVS write cache growth is not always caused by user activity, antivirus scanning, or Windows updates.

As we discovered, background optimization processes such as the .NET Framework Runtime Optimization Service can also generate significant disk writes, particularly in non-persistent environments where changes are discarded after each reboot.

In this case, MetrixInsight for Citrix VAD/DaaS provided the visibility needed to identify abnormal write cache consumption, while Windows Resource Monitor helped us pinpoint the underlying cause.

Completing pending NGen tasks during image maintenance not only prevents unnecessary write cache consumption but also reduces avoidable CPU activity after VDA startup. This is particularly important in non-persistent Citrix environments, where the same optimization tasks might otherwise run repeatedly after every reboot.

The key takeaway is simple: don't overlook NGen optimization when maintaining non-persistent Citrix images. A small step during image maintenance can prevent unnecessary write cache consumption and potentially serious operational issues in production.