I'm distributed locust using the provided terraform on AWS. Between the load, I update the route53 weighted records of my target to point to another version.
What I see is that locust don't update the initial DNS resolution, and keep targetting my first version.
How can I make locust to recalculate the dns resolution during the load ?
That is kind of hard, as your OS will most likely cache the dns resolution.
You could use dnspython
to resolve the address yourself (https://blog.devgenius.io/pyops-dnspython-toolkit-590a368b5c2)
A = dns.resolver.resolve(domain, 'A')
for answer in A.response.answer:
for item in answer.items:
ip = item.address
And then do the request against that ip, manually adding the appropriate Host
header.
self.client.get(f"http://{ip}", headers={"Host": domain})
Edit: if using OS dns resolution is ok or even desirable, then maybe just creating a new Session
is enough. That creates a new tcp connection and should trigger a new DNS query once any OS level caching times out:
from locust.clients import HttpSession
...
@task
def t(self):
self.client.close()
self.client = HttpSession(
base_url=self.host,
request_event=self.environment.events.request,
user=self
)
# your actual requests