title: How to optimze throughput for REST API calls in an akka-stream
body: <p>I'm currently learning about akka streams and I'm trying to implement a simple stream that gets an item from a source and calls a 
  REST api for every item.</p>
  
  <p>A simplified version of my code looks like this:</p>
  
  <pre class="lang-scala prettyprint-override"><code>source.mapAsync(parallelism){ item =&gt;
      Http().singleRequest(HttpRequest(HttpMethods.GET, "http://myserver:8080/$item"))
          .flatMap(response =&gt; response.entity.toStrict(20.seconds))
  }
  </code></pre>
  
  <p>I'm wondering now how to set <code>parallelism</code> to get maximal throughput if the bottleneck is the REST server.</p>
  
  <p>My understanding is that if we assume that the server cannot handle request in parallel, I could use <code>parallelism = 1</code> as first approximation
  and my stream would send one request after another. 
  If the server can handle <code>n</code> requests in parallel, the stream wouldn't utilize that and I would have to set <code>parallelism = n</code> to get a
  better throughput. </p>
  
  <p>I could now play around with <code>parallelism</code> to optimize throughput for my setup at a given point in time.
  However, myserver could be behind a load balancer and an auto-scaler. Then the number of parallel requests available to the stream would depend on the time
  and maybe my program is not the only user of the REST API.</p>
  
  <p>My question is now, what would be the best approach for calling the REST API when I want to utilize myserver as good as possible but
  don't want to overwhelm it if it is under pressure or not yet scaled up?</p>