# Limiting TCP connections

**URL:** https://community.gatling.io/t/limiting-tcp-connections/2682
**Category:** Gatling (Open-Source)
**Created:** [November 26, 2015, 12:31pm UTC](https://community.gatling.io/t/limiting-tcp-connections/2682 "2015-11-26T12:31:52Z")
**Posts on this page:** 16
**Page:** 1

<div class="post-metadata">

### Author: ![aidylewis](https://avatars.discourse-cdn.com/v4/letter/a/e9a140/32.png) [@aidylewis](https://community.gatling.io/u/aidylewis)
#### Post date: [November 26, 2015, 12:31pm UTC](https://community.gatling.io/t/limiting-tcp-connections/2682/1 "2015-11-26T12:31:52Z")

</div>

Hi,

I’d like to limit TCP connections and make all requests go through these.

I thought of injecting x amount of users and then looping:  
[https://github.com/bbc/gatling-load-tests/blob/master/src/test/scala/bbc/geoip/GeoIp.scala](https://github.com/bbc/gatling-load-tests/blob/master/src/test/scala/bbc/geoip/GeoIp.scala)

There are two problems I see with this:

1. I will be unable to control the amount of requests per second without pausing/pacing and throttling
2. The console output keeps printing OK requests of 20 (atOnceUsers(10))

Is there a better way of limiting TCP connections and why do looped requests not appear in the Gatling stdout?

Many Thanks

Aidy

---

<div class="post-metadata">

### Author: ![slandelle](https://dub1.discourse-cdn.com/flex013/user_avatar/community.gatling.io/slandelle/32/4_2.png) [@slandelle](https://community.gatling.io/u/slandelle)
#### Post date: [November 26, 2015, 12:36pm UTC](https://community.gatling.io/t/limiting-tcp-connections/2682/2 "2015-11-26T12:36:42Z")

</div>

> I'd like to limit TCP connections and make all requests go through these.

What's the rationale?

> why do looped requests not appear in the Gatling stdout?

caching?

\*Stéphane Landelle\*  
\*GatlingCorp CEO\*  
slandelle@gatling.io

---

<div class="post-metadata">

### Author: ![aidylewis](https://avatars.discourse-cdn.com/v4/letter/a/e9a140/32.png) [@aidylewis](https://community.gatling.io/u/aidylewis)
#### Post date: [November 26, 2015, 1:09pm UTC](https://community.gatling.io/t/limiting-tcp-connections/2682/3 "2015-11-26T13:09:46Z")

</div>

Hi Stéphane,

> > why do looped requests not appear in the Gatling stdout?\> caching?

Yes, I should have realised that.

> > I’d like to limit TCP connections and make all requests go through these.  
> > What’s the rationale?

After further investigation, it seems that there are x number of clients that make API calls with a keep-alive of 45 secs.

So, I was thinking maybe I inject a new set of users every 45 seconds?

Many Thanks

Aidy

---

<div class="post-metadata">

### Author: ![slandelle](https://dub1.discourse-cdn.com/flex013/user_avatar/community.gatling.io/slandelle/32/4_2.png) [@slandelle](https://community.gatling.io/u/slandelle)
#### Post date: [November 26, 2015, 1:14pm UTC](https://community.gatling.io/t/limiting-tcp-connections/2682/4 "2015-11-26T13:14:03Z")

</div>

> After further investigation, it seems that there are x number of clients  
> that make API calls with a keep-alive of 45 secs.

Are those clients trusted? Even though, keep-alive duration client should  
never be trusted and servers should quickly close connections after some  
idle time. IMHO, 45 secs is very (way too) long. I'd use something like  
5-15 seconds.

---

<div class="post-metadata">

### Author: ![aidylewis](https://avatars.discourse-cdn.com/v4/letter/a/e9a140/32.png) [@aidylewis](https://community.gatling.io/u/aidylewis)
#### Post date: [November 26, 2015, 1:22pm UTC](https://community.gatling.io/t/limiting-tcp-connections/2682/5 "2015-11-26T13:22:51Z")

</div>

Hi Stephane,

The clients are internal, but I am struggling on how to model this. It looks as though we may have a batch of requests within each keep-live session.

Aidy

---

<div class="post-metadata">

### Author: ![slandelle](https://dub1.discourse-cdn.com/flex013/user_avatar/community.gatling.io/slandelle/32/4_2.png) [@slandelle](https://community.gatling.io/u/slandelle)
#### Post date: [November 26, 2015, 1:25pm UTC](https://community.gatling.io/t/limiting-tcp-connections/2682/6 "2015-11-26T13:25:57Z")

</div>

So your clients are other applications, not browsers?

---

<div class="post-metadata">

### Author: ![aidylewis](https://avatars.discourse-cdn.com/v4/letter/a/e9a140/32.png) [@aidylewis](https://community.gatling.io/u/aidylewis)
#### Post date: [November 26, 2015, 2:04pm UTC](https://community.gatling.io/t/limiting-tcp-connections/2682/7 "2015-11-26T14:04:22Z")

</div>

Yes, it is actually one application and X amount of instances of it.

---

<div class="post-metadata">

### Author: ![slandelle](https://dub1.discourse-cdn.com/flex013/user_avatar/community.gatling.io/slandelle/32/4_2.png) [@slandelle](https://community.gatling.io/u/slandelle)
#### Post date: [November 26, 2015, 2:10pm UTC](https://community.gatling.io/t/limiting-tcp-connections/2682/8 "2015-11-26T14:10:06Z")

</div>

So you should share the connection pool.

---

<div class="post-metadata">

### Author: ![aidylewis](https://avatars.discourse-cdn.com/v4/letter/a/e9a140/32.png) [@aidylewis](https://community.gatling.io/u/aidylewis)
#### Post date: [November 26, 2015, 2:22pm UTC](https://community.gatling.io/t/limiting-tcp-connections/2682/9 "2015-11-26T14:22:15Z")

</div>

> So you should share the connection pool.

Thanks, but wouldn’t this mean all users share one connection? Would I need to write x number of similar scenarios to simulate x connections?

---

<div class="post-metadata">

### Author: ![slandelle](https://dub1.discourse-cdn.com/flex013/user_avatar/community.gatling.io/slandelle/32/4_2.png) [@slandelle](https://community.gatling.io/u/slandelle)
#### Post date: [November 26, 2015, 2:29pm UTC](https://community.gatling.io/t/limiting-tcp-connections/2682/10 "2015-11-26T14:29:45Z")

</div>

How do those applications work? Do they use one single connection each? Or do they use a connection pool too?

---

<div class="post-metadata">

### Author: ![aidylewis](https://avatars.discourse-cdn.com/v4/letter/a/e9a140/32.png) [@aidylewis](https://community.gatling.io/u/aidylewis)
#### Post date: [November 26, 2015, 2:33pm UTC](https://community.gatling.io/t/limiting-tcp-connections/2682/11 "2015-11-26T14:33:33Z")

</div>

Each application instance would make a separate connection.

---

<div class="post-metadata">

### Author: ![slandelle](https://dub1.discourse-cdn.com/flex013/user_avatar/community.gatling.io/slandelle/32/4_2.png) [@slandelle](https://community.gatling.io/u/slandelle)
#### Post date: [November 26, 2015, 2:38pm UTC](https://community.gatling.io/t/limiting-tcp-connections/2682/12 "2015-11-26T14:38:23Z")

</div>

OK, so you’re back with your original solution. And I don’t see your points.

---

<div class="post-metadata">

### Author: ![aidylewis](https://avatars.discourse-cdn.com/v4/letter/a/e9a140/32.png) [@aidylewis](https://community.gatling.io/u/aidylewis)
#### Post date: [November 26, 2015, 3:21pm UTC](https://community.gatling.io/t/limiting-tcp-connections/2682/13 "2015-11-26T15:21:05Z")

</div>

> OK, so you’re back with your original solution. And I don’t see your points.

Thanks Stephane,

One of the drawbacks of my original solution was that if I make x number of connections and loop, I will only be able to “control” the request rate through pace/pausing and throttling, and I wondered if there was a better way to handle this.

---

<div class="post-metadata">

### Author: ![slandelle](https://dub1.discourse-cdn.com/flex013/user_avatar/community.gatling.io/slandelle/32/4_2.png) [@slandelle](https://community.gatling.io/u/slandelle)
#### Post date: [November 26, 2015, 3:21pm UTC](https://community.gatling.io/t/limiting-tcp-connections/2682/14 "2015-11-26T15:21:45Z")

</div>

No 🙂

---

<div class="post-metadata">

### Author: ![r\_rajitha](https://avatars.discourse-cdn.com/v4/letter/r/58956e/32.png) [@r\_rajitha](https://community.gatling.io/u/r_rajitha)
#### Post date: [December 17, 2015, 6:23pm UTC](https://community.gatling.io/t/limiting-tcp-connections/2682/15 "2015-12-17T18:23:54Z")

</div>

Hi

my application also having the scenario.As you mentioned can controlling the request rate by pause/throttling .  
which is the best approach ? throttling or pause

---

<div class="post-metadata">

### Author: ![aidylewis](https://avatars.discourse-cdn.com/v4/letter/a/e9a140/32.png) [@aidylewis](https://community.gatling.io/u/aidylewis)
#### Post date: [December 17, 2015, 7:15pm UTC](https://community.gatling.io/t/limiting-tcp-connections/2682/16 "2015-12-17T19:15:14Z")

</div>

Hi,

Could you please express your requirements a little more fully as there may be alternative ways to achieve your goal?
