# Choosing the right AWS instance

**URL:** <https://discourse.mc-stan.org/t/choosing-the-right-aws-instance/19398>\
**Category:** General\
**Tags:** performance, rstan\
**Created:** [November 19, 2020, 8:45pm UTC](https://discourse.mc-stan.org/t/choosing-the-right-aws-instance/19398 "2020-11-19T20:45:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![scijens](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/scijens/32/9695_2.png) [@scijens](https://discourse.mc-stan.org/u/scijens)\
**Post date:** [November 19, 2020, 8:45pm UTC](https://discourse.mc-stan.org/t/choosing-the-right-aws-instance/19398/1 "2020-11-19T20:45:22Z")

</div>

Hi everyone,  
I am generally interested in a procedure to choose the right [instance](https://aws.amazon.com/ec2/instance-types/) to run Stan models on Amazon AWS. I am using [Louis Aslett’s RStudio AMI](http://www.louisaslett.com/RStudio_AMI) and want to run RStan on RStudio Server.

My model is quite complex (Hidden Markov Model where the transition probabilities are driven by time-varying covariates). I ran it on my computer (2 cores with 2.00 GhZ each) and 1/15 of my final dataset. It consumes ~ 1GB RAM and ~ 50% of CPU. I am wondering which assumptions I can make to make the right choice for the AWS instance out of all the instances listed [here](https://aws.amazon.com/ec2/instance-types/). And how would the computational effort increase if I want to run a 3-state model instead of a 2-state model?

.

---

<div class="post-metadata">

**Author:** ![Max\_Mantei](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/max_mantei/32/7912_2.png) [@Max\_Mantei](https://discourse.mc-stan.org/u/Max_Mantei)\
**Post date:** [December 3, 2020, 10:18pm UTC](https://discourse.mc-stan.org/t/choosing-the-right-aws-instance/19398/2 "2020-12-03T22:18:18Z")

</div>

Hey Jens!

I think the important thing is whether you already have threading in your model or not. In terms of chains you need a sufficiently long warmup and some post warmups. So spamming a lot of chains is not the right way to go. Then it’s important how accurate the results should be, i.e. are you interested in tail quantities etc.? So maybe you can figure out how many chains make sense for your model in this way. Then multiply that by the number of threads that make sense for your model and you get a (really rough) rule of thumb for number of core you want. I’d recommend the compute (CPU) optimized machines.

Also, you might want to check out this thread if you haven’t already:

> [@Rstan on remote servers](https://discourse.mc-stan.org/t/rstan-on-remote-servers/19602):
>
> Dear all, I am relatively new to the use of Stan in bayesian modelling, and I am currently working on a fitting a hierarchical model to ecological data in R via rstan. After a few tests the best version of model takes a very long time (~ 1 week) to run fully for about 1000 iterations, as there is a large number of parameters being estimated. This means that for a proper run (which would require potentially 10 times as many iterations) this will take a huge amount of time on my 4 cores computer. …

Mitzi mentions the folk theorem there and from my experience speeding up a model is often impossible if the model is incorrect… Just double check everything and look out for efficiency gains in the code (and then add threading).

I don’t know enough about HMM to make any statement regarding compute time of 3-state vs. 2-state models, sorry.

On a final note: If you are looking for speed you should definitely check out CmdStanR! :)

Hope this was at least a bit helpful.

Cheers,  
Max

---

<div class="post-metadata">

**Author:** ![scijens](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/scijens/32/9695_2.png) [@scijens](https://discourse.mc-stan.org/u/scijens)\
**Post date:** [December 7, 2020, 2:37pm UTC](https://discourse.mc-stan.org/t/choosing-the-right-aws-instance/19398/3 "2020-12-07T14:37:19Z")

</div>

Hi Max,

Thanks very much, this is definitely helpful! With cmdstan I achieved a significant increase in speed and I am running a t3.large machine - thanks!

Cheers,  
Jens
