<p>I'm doing a load test with python Locust package on an service API that's running on Kubernetes.</p>

<p>I saw in the source code that the <code>HttpUser</code> uses <code>requests.session.request()</code> to send the requests. By default <code>requests.session</code> keeps the connection alive (which causes all the requests going to one pod instead of getting distributed across all pods on Kubernetes). Only way I know to close the connection after each request is setting <code>connection: close</code> when initializing the <code>requests.session</code>, which is abstracted away from me in Locust. </p>

<p>I tried adding <code>headers={'connection':'close'}</code> in the request call but that didn't do the trick. All requests still goes to the same pod. Anyone know how I can change this setting at runtime?</p>

Xuekai Du
<p>Maybe you can also use User instead of HttpUser because HttpUser is thought to keep session betweek tasks.</p>
<p>using User instead of HttpUser you need to import requests and instance it, but it doesn't keep session by default. if you want to keep session create a session object and make calls with it.</p>
<p>for example</p>
<pre><code>class Login(HttpUser)
    @task
    def activity():
        self.client.get('/url')
</code></pre>
<p>session betweek every run of this task id shared.</p>
<pre><code>import requests

class Login(User)
    @task
    def activity():
        answer = requests.get('/')
        answer2 = requests.get('/')
        #answer and answer2 doesn't share session, every run of task doesn't share session
        session = requests.Session()
        answer3 = session.get('/')
        answer4 = session.get('/')
        #answer3 and 4 share same session, every run of task doesn't share session
</code></pre>
