Jordan Johnson avatar image
Jordan Johnson posted Ben Wilson commented

Using Amazon Web Services for Distributed Experiments or Optimizations

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.

Financial Costs

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:

  1. Download the FlexSim installer and the Webserver installer. If your upload speed is slow, you can skip this step.
  2. Launch the cheapest instance available, with the Windows 2016 Server Base image. There are probably free-tier instances available in the list
  3. Connect to that Instance with Remote Desktop
  4. 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.
  5. Run FlexSim. This creates a directory that is needed later. Then close FlexSim.
  6. 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.
  7. Run the Webserver. It will download a bunch of files the first time it is run.
  8. 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.
  9. Disconnect the Remote Desktop session
  10. Go to the list of Instances in the AWS Console
  11. From the Actions menu, select Image, then select Create Image:

  12. Add a name and description.

  13. Click the Create Image button
  14. On the next dialog, click the View Pending link, or navigate to the list of AMIs:

  15. 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:

  1. In the EC2 Console, choose Launch Instance
  2. Select the AMI you created, from the list of My AMIs

  3. Choose the Instance Type and quantity
  4. Set the Security Group to use the Security Group you created
  5. Launch the instance
  6. 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.
  7. 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.


Spot Pricing

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.

creatingimage.png (49.3 KiB)
viewpending.png (17.4 KiB)
inputipaddrs.png (8.2 KiB)
securitygroup.png (40.5 KiB)
chooseami.png (56.3 KiB)
· 3
5 |100000 characters needed characters left characters exceeded

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

@jordan.johnson - thank you for adding this capability! Just to confirm your first paragraph, can this also be used to send Experimenter and OptQuest runs to another PC on the local network that has more CPU cores, without sending anything to the cloud? We could benefit from offloading replication-intensive experiments to other PCs in the office with more CPU cores available.

2 Likes 2 ·

Yes. You can run FlexSim experiments on any remote machine that meets the requirements in the first paragraph. Another PC on the local network should be fine; it doesn't need to be a VM on a cloud service.

1 Like 1 ·

Here is an article with similar info, but generalized for any cloud provider:

It includes other links and explanations if you are new to the experimenter or optimizer.

1 Like 1 ·



jordan.johnson contributed to this article