One of the new features in FlexSim 2018 Update 2 is the ability to use distributed CPUs for the Experimenter or Optimizer. Those cores can exist on any machine that meets the following requirements:
- The machine is accessible by IPv4 address
- The machine has FlexSim installed
- The machine is running the FlexSim Webserver (version 18.2.0 or later) on port 80
- The machine meets hardware requirements to support running the specified number of simultaneous replications.
This article describes how to use Amazon Web Services to create remote machines that meet the above requirements. Using AWS, you can launch and connect to as many servers as you want, and pay only for the time used on those instances.
Anticipated Use Case
Using distributed CPUs can significantly reduce the required time to run an experiment if:
- The time to run a single replication is high (a couple minutes or more)
- The number of replications to run is high
If the time per replication is short, then the increased communication overhead may outweigh the benefit of using distributed CPUs. The communication overhead increases because all CPUs still report results to a single FlexSim process, and that communication occurs over the internet, rather than on a single machine. If an Experiment or Optimization completes in an acceptable amount of time, you may not need to use distributed CPUs.
Amazon charges for its services. Costs for running instances (and transferring data out of them) are found here :
Costs for storing data (including AMIs) are found here:
These instructions include steps to create an AMI, which will likely cost around $1 per month at current rates. It also includes steps for launching high-performance instances, which have an hourly cost. Suitable instances can be as cheap as $0.50 per hour. Note that there are also charges for transferring data from an instance to another computer.
Step 0: Complete an EC2 Tutorial
If you are not already familiar with EC2 instances, you should complete the following tutorial:
Step 1: Create a Security Group
You will need to create a security group with the following rules:
- Allow HTTP traffic on port 80. This allows incoming connections to the FlexSim Webserver. You can choose which inbound IP addresses to accept. You should make this as strict as possible. The strictest setting is to only allow incoming connections from the current IP address.
- Allow TCP traffic on ports 9000-9200. This is a Custom TCP rule. Note that you can make this range smaller, if all machines that use this Security Group have fewer than 200 cores. For example, if the biggest machine launched with this Security group has 72 cores, you would only need ports 9000-9072 in this rule.
- Allow RDP traffic on the default RDP port. This allows you to connect to the instance using remote desktop.
Name the Security Group something that shows that this group is related to running FlexSim instances, and add a description if you want. Here is an example Security Group that works, but allows all TCP traffic, and so should only be used for testing purposes:
Step 2: Create a Custom Amazon Machine Image (AMI)
You will need to create a custom AMI. A custom AMI allows you to launch an instance that has the software you need already installed. To create one, follow these steps:
- Download the FlexSim installer and the Webserver installer. If your upload speed is slow, you can skip this step.
- Launch the cheapest instance available, with the Windows 2016 Server Base image. There are probably free-tier instances available in the list
- Connect to that Instance with Remote Desktop
- Copy (or download, if upload speed is slow) the FlexSim installer to the remote machine, and run it to install FlexSim. You do NOT need to activate a license.
- Run FlexSim. This creates a directory that is needed later. Then close FlexSim.
- Copy (or download, if your upload speed is slow) the Webserver installer to the remote machine, and run it to install the webserver. If using the 2018 Update 2 Beta, be sure to change the Webserver configuration file accordingly.
- Run the Webserver. It will download a bunch of files the first time it is run.
- Allow both FlexSim and node.js through the Windows Firewall. To do so, use the Allow an App through the Windows Firewall tool. You will need to browse for both FlexSim and Node.js. Both are in the ProgramFiles directory.
- Disconnect the Remote Desktop session
- Go to the list of Instances in the AWS Console
- From the Actions menu, select Image, then select Create Image:
- Add a name and description.
- Click the Create Image button
- On the next dialog, click the View Pending link, or navigate to the list of AMIs:
- Once the image becomes Available, terminate the running instance.
Step 3: Launching Usable Instances
Before running an Experiment or Optimization, you need to be sure that all remote instances you will use are current running. To launch and initialize these instances, follow these steps:
- In the EC2 Console, choose Launch Instance
- Select the AMI you created, from the list of My AMIs
- Choose the Instance Type and quantity
- Set the Security Group to use the Security Group you created
- Launch the instance
- Once each instance is initialized, connect to each one with Remote Desktop. Note that when you launch an instance with a given Key File, the password for each instance will be the password associated with that Key File, so you only need to decrypt the file once.
- Start the FlexSim Webserver in each instance
Once all instances are running the Webserver, you are ready to run an Experiment or Optimization.
Author's Note: There is probably a way to make it so that when instances start up, they automatically run the Webserver, so that you don't have to manually connect to each one. I welcome any suggestions or steps for how to make that happen.
Step 4: Using the Instances in FlexSim
Once you have a list of running instances available, you just need to input their IP Addresses into FlexSim, on the Advanced tab of the Experimenter:
Once you have input this information, you just need to click the Experiment or Optimize button. FlexSim will then use the remote CPUs for running replications.
Amazon offers two pricing models: On Demand and Spot Pricing. FlexSim recommends On Demand instances. Spot instances can be significantly cheaper, but they can also be shut down by Amazon and given to an On Demand user at any time, if On Demand requests exceed the number of available machines. FlexSim does not try to recover from this kind of error, and it may lead to unexpected behavior.
CPU Count, RAM, and Disk Space
When you pick an instance type, be sure to understand how much ram you will need. If a model requires 4 GB of RAM while running, and you use an instance with 128 cores, be sure that the instance has at least 512 GB of RAM, or don't use all 128 cores.
Disk space is usually not an issue. However, if you are using the Store Data on Hard Drive option in the Statistics Collector, you will need to be sure that there is enough disk space to run the model to completion on the hard drive, multiplied by the number of cores. The amount of disk space on each instance also affects the total cost of using this service.