Precompile Identify resources to speed up deployment
The problem
When installing a new Identify tenant or upgrading an existing one, there are noticeably slow steps during the process. Specifically, steps involving REST API calls take significant time:
#1 - 04/06/2024 11:05:45: Successfully generated REST API access token ...
#2 - 04/06/2024 11:07:15: The 1st attempt to warm-up Identify tenant successfully!
#3 - 04/06/2024 11:07:15: ...DONE.
#4 - 04/06/2024 11:07:15: 29. ACTION: "Provisioning OAuth 2.0 protocol connection for Safewhere Admin" IS RUNNING....
#5 - 04/06/2024 11:07:15: Creating protocol connection: teststartup.safewhere.local
#6 - 04/06/2024 11:08:30: The protocol connection "teststartup.safewhere.local" created successfully.
In this example, it took:
- 90 seconds to start up the Admin app (#1 and #2)
- 75 seconds to provision a connection (#5 and #6), which also started up the Runtime site.
Note that the time taken depends on the configuration of the specific machine.
The slowness is caused by ASP.NET compiling text resource files into DLLs when the Identify application starts for the first time. For customers upgrading hundreds of tenants, this delay adds up and becomes a major performance issue.
Solution
The solution is to use the provided PowerShell script, SafewhereASPNETCompilerScript.ps1, to precompile text resources for the Identify Admin and Runtime applications.
Step 1: Copy your custom text resource files to the appropriate folders in
C:\Program Files\Safewhere\Identify\Admin
andC:\Program Files\Safewhere\Identify\Runtime\
folders. If you installed Identify in a non-default location, adjust the paths accordingly. Note that you need to copy the files to the source Identify folders, not the Identify tenant folders inside theTenant
folder.Step 2: Open the script and configure the following settings:
- Set the
pathToASPNETCompilerTool
parameter to the appropriate folder for the ASPNET Compiler Tool. The default value isC:\Windows\Microsoft.NET\Framework\v4.0.30319
. - Set the
pathToIdentifyInstallation
parameter to the correct Identify installation folder. The default value isC:\Program Files\Safewhere\Identify
.
- Set the
Step 3: Run the script as an administrator and wait for it to complete.
After precompilation completes, the script will back up the original sources into two folders: admin_original
and runtime_original
After precompilation, performance during tenant creation or upgrades improves significantly. For example:
#1 - 08/08/2024 08:28:38: Successfully generated REST API access token ...
#2 - 08/08/2024 08:29:10: The 1st attempt to warm-up Identify tenant successful! ==> 32 seconds
#3 - 08/08/2024 08:29:10: ...DONE.
#4 - 08/08/2024 08:29:10: 29. ACTION: "Provisioning OAuth 2.0 protocol connection for Safewhere Admin" IS RUNNING....
#5 - 08/08/2024 08:29:10: Creating protocol connection: teststartup.safewhere.local
#6 - 08/08/2024 08:29:52: The protocol connection "teststartup.safewhere.local" created successfully.
Here, it took:
- 32 seconds to start up the Admin app (#1 and #2), and
- 42 seconds to provision a connection (#5 and #6).
This shows a noticeable reduction in overall time compared to the initial logs. Although this process takes time to precompile Identify resources, the benefit can easily outweigh the cost when you have many tenants to upgrade.
Clean up precompiled files
Given that you have precompiled Identify resources, before installing a new version of Identify on your server, you must clean up the precompiled files to avoid conflicts Use the CleanupASPNETCompilerFilesAndFolders.ps1 script to remove all precompiled ones for both Identify Admin and Runtime. This ensures a clean environment for the new installation.
- Step 1: Open the script and set the
pathToIdentifyInstallation
parameter to the correct Identify installation directory. The default value isC:\Program Files\Safewhere\Identify
. - Step 2: Run the script as an administrator and wait for it to complete.