Deployment to a Virtual Machine running IIS

How to deploy compute for production on a virtual machine running Internet Information Services (IIS).

Overview

This guide will walk you through how to setup an instance of rhino.compute on a virtual machine running Internet Information Services (IIS). IIS, is a flexible, general-purpose web server developed by Microsoft which can be configured to serve requested HTML pages or files. We can setup IIS to process incoming requests (either from Hops or some other client) and forward that request to the rhino.compute instance.

You may be asking yourself, “Why do I need IIS at all? Why can’t I simply launch the rhino.compute server and send API requests directly to that instance?”. Technically speaking, you don’t need IIS. However, you would need to figure out how to relaunch the compute server should it crash or malfunction. You would also need to configure rhino.compute to launch whenever the virtual machine is launched.

One of the main benefits of using IIS as a middleware is that it can automatically spin up an instance of the rhino.compute server whenever a request is recieved. With this configuration, you do not have to have compute running continuously. Instead, IIS can launch an instance of compute when it is needed which in turn will launch one or more child processes. These child processes are what perform the actual computation and also what require your license authorization.

When rhino.compute.exe does not receive requests to solve over a period of seconds (this is called idlespans and the default is set to 1 hour), child compute.geometry.exe processes will shut down and stop incurring core hour billing. At some date in the future when a new request is received, IIS will make sure that rhino.compute.exe is running which will then relaunch the child processes. Note, there may be some small delay in the response while the child processes are launching.

Fig.1 - A flow diagram showing how IIS recieves an incoming request and launches rhino.compute.exe which in turn spins up child processes.

Create the VM

The first step in the process of deploying rhino.compute to a remote instance is to set up a virtual machine (VM). There are several popular services which can be configured to setup a wide array of virtual machines depending on your resource needs. Two of the most prominent providers include Azure and AWS.

Depending on your preferences, we recommend starting with an Azure or AWS VM. Use the following guides to walkthrough that process.

Connect via RDP

Now that we’ve configured the virtual machine, we need to be able to log onto it so that we can setup IIS and the rhino.compute instance. We’ll do this by using a remote desktop protocol (RDP) which connects two computers over a network.

To start, let’s download the RDP file for our Azure VM.

  1. First, make sure the virtual machine is running. Click on the Overview tab in the left-hand menu. If the Status says Stopped (Deallocated), click on the Start button at the top to start the remote machine. After a few seconds, the status should say Running.

  2. Click on the Connect menu item in the left-hand menu to pull out the connection settings blade.

  3. Click on the Download RDP File button and save the file somewhere on your computer.

  4. Click on the Windows Start menu and start typing remote desktop connection in the search bar. Click on the link to launch app.

  5. Click on the button at the bottom of the app to Show Options

  6. Under the Connection Settings area, select Open and navigate to the directory where you saved your RDP file. Choose that file and hit Open.

  7. Select the checkbox to Allow me to save credentials

  8. Click Connect.

  9. A security pop-up will be opened. Click the checkbox for Don’t ask me again for connections to this computer and then click Connect.

  10. Enter the administrator credentials that you entered in step 7 of Creating a Virtual Machine.

  11. You may see another security pop-up. Again, select Don’t ask me again for connections to this computer and click Yes.

Congratulations. You should now have access to the desktop of the remote machine running Windows Server 2022.

Configuring the VM

Now that you have logged into the virtual machine via RDP, let’s take a look at how to setup Windows Server to host our instance of rhino.compute.

Open Firewall Port

We have already created an inbound port rule for the Azure network interface and the Windows firewall already has inbound port rules to allow HTTP traffic on port 80 and HTTPS traffic on port 443. However, we must also create a rule to allow ICMP messages through the Windows firewall.

  1. Launch Powershell (right-click to Run as Administrator).

  2. Type in the following commands:

     # For IPv4
     netsh advfirewall firewall add rule name="ICMP Allow incoming V4 echo request" protocol="icmpv4:8,any" dir=in action=allow
     
     # For IPv6
     netsh advfirewall firewall add rule name="ICMP Allow incoming V6 echo request" protocol="icmpv6:8,any" dir=in action=allow 
    
  3. You should see an OK message after each command.

  4. Now, Restart your virtual machine.

You should be able to ping your Azure virtual machine using your public IP address. Note: your IP address will be different than the one shown below.

Install Rhino

Next we need to install Rhino on the virtual machine and setup core-hour billing.

  1. Download the Rhino 7.0.

  2. Follow this guide for setting up core-hour billing on the virtual machine.

Install IIS

By default, IIS is not enabled on Windows Server. To install IIS on the virtual machine, follow these steps.

  1. Open the Server Manager console. This usually opens by default after startup, however if its not there, click on the Start menu and search for Server Manager.

  2. Click the Add roles and features button.

  3. Click Next on the Before you begin page

  4. On the Installation type page, select Role-based or feature-based installation.

  5. We will be installing IIS on this local machine, so leave Select a server from the server pool checked.

  6. Click Next.

  7. On the Select server roles page, check the box next to Web Server (IIS). A pop-up dialog will be opened advising that additional features are required. Click the Add Features button to install these as well.

  8. Click Next.

  9. On the Select features page, add all of the checkboxes under the .NET Framework 4.8 Features. Then scroll down and make sure the IIS Hostable Web Core checkbox is checked. Click Next.

  10. On the Select role services page, review the available features that are available. For now, we will simply leave the default selections, but you can always come back and add more later.

  11. Click Next.

  12. Finally, on the Confirmation page, review the items that are going to be installed on the VM. When satisfied, click the Install button. Note, no reboot should be required with a standard IIS installation. However, if you remove the role a reboot will be needed.

  13. Once the installation has succeeded, click the Close button. At this point, IIS should be running on port 80 (by default).

  14. You can now open the IIS Manager app by clicking on the Windows Start menu and searching for *IIS Manager**. This will launch the IIS Manager console app. We won’t do anything in the IIS Manager just yet, but you should be able to confirm that IIS is now operational on the VM.

Install .NET Core Hosting Bundle

The first thing we need to do is install the .NET Core Hosting Bundle on the VM in order to run rhino.compute (an ASP.NET Core app) on the VM. The bundle installs the .NET Core Runtime, .Net Core Library, and the ASP.NET Core Module which allows ASP.NET Core apps to run behind IIS. Before we can install the .NET Core Hosting Bundle, we need to make sure the

  1. Download the .NET Core Hosting Bundle (direct download) Note: Rhino.compute currently targets the .NET Core 5.0 Framework.

  2. Restart your virtual machine.

Publish rhino.compute

The next step in the process will be to publish the rhino.compute and compute.geometry projects. In order to do this, you will need to have the Visual Studio 2019 IDE and Git installed on your machine.

You have two options as to where you can install these applications. You can either install these on virtual machine and publish the rhino.compute applications locally, or you can install these on a different machine and then copy/paste the published files over to the VM. In this walkthrough, I will choose the later approach.

  1. Go to https://github.com/mcneel/compute.rhino3d and clone the repo to a directory on your machine. To do this:

    • Open Powershell and navigate to a directory where you want to clone the repository.
    • Type $ git clone https://github.com/mcneel/compute.rhino3d.git compute into the terminal.
    • Press Enter to create a local clone of the rhino.compute repo on your machine.
  2. Next, launch Visual Studio

  3. Choose Open a Project or Solution and navigate to the directory where you cloned the repo, then choose the src subfolder. Choose the compute.sln file and choose Open.

  4. In the Solution Explorer you should see two projects. One is called rhino.compute and the other compute.geometry. Right-click on the rhino.compute project and select Publish from the menu.

  5. A new Publish dialog will be opened. For the Target choose the Folder option.

  6. Next you will be asked for a directory to save all of the published files. You can choose any location but I have created a directory called compute-for-IIS. Inside this folder, I’ve created two subfolders called rhino.compute and compute.geometry. Select the rhino.compute subfolder as the target location to save the files. Your folder structure looks like this:

     * compute-for-IIS
         * rhino.compute
         * compute.geometry
    
  7. Click Finish.

  8. Back in the Visual Studio Publish window, select Show all settings.

  9. In the Publish setting dialog, select Settings. Make sure that the Configuration is set to Release, Deployment Mode is set to Self-contained, and the Target Runtime is set to win-x64. Leave all other defaults.

  10. Click Save.

  11. Click the Publish button to begin the process of saving the rhino.compute project to the target directory.

  12. Now, we have to go through a similar process to publish all of the files for the compute.geometry project. This time, right-click on the compute.geometry project in the Solution Explorer and select Publish.

  13. Choose Folder as the Target type, just like in step 5.

  14. This time, set the compute.geometry subfolder that you created in step 6.

  15. Click Finish.

  16. We can leave all of the other configuration settings to their defaults. Click Publish to save the files to the target directory.


At this point, you should have a folder on your machine labeled compute-for-IIS. Inside that folder, you should have two subfolders each of which contain a number of files. Next, we need to copy those two subfolders over to a directory on the virtual machine.

If you aren’t already logged into your virtual machine through the Remote Desktop Connection app, please do so now.

When we installed IIS on the virtual machine, it created a folder called inetpub on the C:\ drive.

The folder structure looks like this:

* C:\inetpub
    * custerr
    * history
    * logs
    * temp
    * wwwroot
        * aspnet_client
            * system_web
                *4_0_30319   <- copy/paste rhino.compute and compute.geometry folders here 

We need to copy/paste the contents of the compute-for-IIS folder (the two subfolders) into the 4_0_30319 directory.

In the next step, we will create an IIS application and point it to this directory in order to launch an instance of rhino.compute when it receives an API request.

Create the app in IIS

Setup the App Pool & Site

Our next step will be to create an application in IIS and link it to the rhino.compute directory. To start we’ll need to create a new app pool in IIS.

  1. Select the Windows Start button and type IIS in the search bar. Click on the Internet Information Services (IIS) Manager app to launch the IIS Manager.

  2. In the Connections pane on the left-hand side of the IIS Manager you should see two items: 1) Start Page and 2) Rhino-Compute-VM (or whatever you named your virtual machine). Click on the carat to the left of the VM name to expand the submenu.

  3. Select the Application Pools submenu item.

  4. In the Actions pane on the far right, click the Add Application Pool button.

  5. In the Add Application Pool dialog, type RhinoComputeAppPool in the Name input. Set the .NET CLR version to No Managed Code. Leave all other defaults.

  6. Click OK to add the new app pool.

  7. Under the Actions pane, click Advanced Settings.

  8. In the Advanced Settings dialog, scroll down to the Process Model section. Change the Load User Profile to True.

  9. Click OK to close the Advanced Settings dialog.

  10. Now, in the Connections pane, click on the Sites menu item.

  11. In the Actions pane, select Add Website.

  12. In the Add Website dialog, set the Site name to Rhino.Compute.

  13. Click the Select button and set the Application Pool to RhinoComputeAppPool.

  14. Click the ellipsis button next to the Physical path and select the rhino.compute directory (ie. C:\inetpub\wwwroot\compute-for\IIS\rhino.compute).

  15. Under the Binding section, type 80 to bind the application to incoming messages on port 80. For now, leave the binding type to http.

  16. Click OK to create the site.

  17. At this point, you may see a popup that says you are trying to use the same binding as another site. This is because the Default Site that IIS set up during the initial configuration is also bound on port 80. Click Yes and we will edit the binding on the Default Site in a minute.

  18. Next, under the Actions pane, click Advanced Settings.

  19. In the Advanced Settings dialog, under the General section, click on the elipsis button to set the Physical Path Credentials.

  20. In the Connect As dialog, select Specific user. Then click the Set button to add your administrator credentials.

  21. Enter the Username and Password associated with your administrator account. Hint: this should be the same username and password that you set in step 7 when setting up Azure virtual machine.

  22. Click OK To save the credentials.

  23. Click OK to save the user information.

  24. In the Advanced Settings dialog, change the Preload Enabled value to True.

  25. Click OK to save the settings.

Next, we need to edit the port bindings on the default website so that they do not conflict with the one we just set up for rhino.compute (ie. port 80).

  1. In the Connections pane, select the Default Web Site.

  2. In the Actions pane, select Binding….

  3. In the Site Bindings dialog, select the row with the Type labeled http. Click the Edit button.

  4. In the Edit Site Bindings dialog, change the Port number to 8080. This number is arbitrary and can be any other valid port identifier other than 80.

  5. Click Close on the Site Bindings dialog.

Lastly, you may need to restart the IIS server and/or RhinoCompute site for the changes to go into effect.

  1. In the Connections pane, select the RhinoComputeVM root server (one level up from the Application Pools and Sites).

  2. In the Actions pane, select Restart.

  3. After the server has been restarted, select the RhinoCompute site in the Connections pane.

  4. In the Actions pane, under the Manage Website heading, select Restart.

Edit Permissions

The next thing we have to do is edit the permissions of the rhino.compute and compute.geometry subfolders. Open the File Explorer and navigate to those subfolders (Hint: they should be located in C:\inetpub\wwwroot\aspnet_client\system_web\4_0_30319).

  1. Right-click on the rhino.compute folder and click Properties.

  2. Click on the Security tab and then click Edit.

  3. For each group or user name, provide Full control access.

  4. Next, click the Add button.

  5. Under the section titled Enter the object names to select, type in IIS AppPool\RhinoComputeAppPool. Then, click on the Check Names button to verify the name.

  6. Click OK.

  7. Back in the Security tab, make sure the RhinoComputeAppPool object is select. Then check Full control to give full access to this app pool.

  8. Click Apply to modify the permissions.

  9. Click OK to close the dialog.

Now, follow the same steps to provide Full control access to the compute.geometry folder.

Testing the app

At this point, IIS should be configured to launch the rhino.compute instance when an API request is made. You can test this by opening a web browser on your local machine (not the VM) and typing in “http://” followed by the IP address of the virtual machine followed by a : and the port number (80) followed by “/activechildren”. So, the full address would look something like this:

http://52.168.38.105:80/activechildren

The /activechildren endpoint will return an integer value for the number of child processes that were started by rhino.compute (the default is 4).

If you’ve succeeded in returning a numeric value larger than zero, then at least one child process has been started. Next, let’s try getting Hops to send a definition to that URL.

  1. Launch Rhino on your local machine.

  2. If you have not already installed hops on this machine, please do so by searching for it in the Rhino Package Manager.

  3. Start Grasshopper by typing the word Grasshopper into the command prompt and hitting enter.

  4. Go to File and then Preferences to open the preferences dialog.

  5. Click on the Solver tab in the left-hand menu.

  6. In the Hops - Compute server URLs section, type in the web address from above (do not include the /activechildren endpoint). Your URL should look something like this.

  7. Add a Hops component to the Grasshopper canvas (Params/Util)

  8. Right-click on the Hops component and set the Path to a valid Hops/Grasshopper definition. To learn more about setting up a Grasshopper definition that will work properly with Hops, follow this guide.

Once the path is set, the Hops component will create the appropriate API request and send it to the URL that we specified in step 6 (the rhino.compute server running on IIS). The compute server processes the request and send a response back to Hops, which returns the result.

Congratulations! You have successfully setup an instance of rhino.compute running behind IIS on a virtual machine.