locustio / locust

Write scalable load tests in plain Python 🚗💨
MIT License
24.64k stars 2.96k forks source link

Save responses to a file #774

Closed dron4ik85 closed 4 years ago

dron4ik85 commented 6 years ago

Environment settings (for bug reports)

Hello,

In Jmeter I have option Save Responses to a file. How can I do that via locust? I can't find this information in your documentation.

Thank's 6

aldenpeterson-wf commented 6 years ago

What type of "responses" do you mean?

You can save the actual metric data. But if you mean saving the http responses, thats not supported by default (though it'd be easy to add a custom filewriter).

dron4ik85 commented 6 years ago

Well I find some solution for me:

from locust import HttpLocust, TaskSet, task

class UserBehavior(TaskSet):

    @task
    def get_file(self):
        count = 0
        response = self.client.get(
            "http://speedtest.ftp.otenet.gr/files/test100k.db"
        )
        file = '/Path/To/File/file/test_file({0}).bin'.format(count+1)
        with open(file, 'wb') as f:
            f.write(response.content)
            count += 1

class WebsiteUser(HttpLocust):
    task_set = UserBehavior
    min_wait = 1000
    max_wait = 1000

But the problem is, that I need to save file per request. Only I can do is to save one file and modifies him every request.

cgoldberg commented 6 years ago

But the problem is, that I need to save file per request. Only I can do is to save one file and modifies him every request.

@dron4ik85 your solution will write one file per request. But if you were to hatch more than one Locust, you could get filename collisions as multiple locusts try to write to the same file. You would need to create files with unique names, perhaps using a timestamp and an id.

Also note, that by saving full HTTP responses, you will be doing a ton of disk i/o and any timing metrics you collect will be invalid.

cyberw commented 4 years ago

See https://github.com/locustio/locust/issues/864 for a suggested workaround.