Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: moto_service s3 becoming slow and timing out as tests continue #2288

Closed
gmossessian opened this issue Jul 9, 2019 · 4 comments
Closed
Labels
debugging Working with user to figure out if there is an issue

Comments

@gmossessian
Copy link

I have a test suite of ~1000 tests. Previously we were using the mock_s3 decorator which only worked because our "integration tests" just imported modules from other services and mocked their functionality. This was always been undesirable but has not been a priority to fix until recently.

I'm attempting to use moto in standalone server mode, hackily starting the service in conftest.py using

def start_local_moto_server():
    global moto_subprocess
    moto_subprocess = subprocess.Popen(
        ['moto_server', 's3'],
        stdout=subprocess.PIPE, stderr=subprocess.PIPE,
        bufsize=0, universal_newlines=True,
    )
    print 'Waiting for moto local service to start...'
    while True:
        moto_log = moto_subprocess.stderr.readline()
        print moto_log
        if 'Running' in moto_log:
            break

    boto3.resource(
        's3', region_name='us-east-1', endpoint_url='http://127.0.0.1:5000'
    ).create_bucket(Bucket=TEST_S3_BUCKET_NAME)

As the tests progress, any calls to the s3 client become slower and slower, until finally I get

ReadTimeoutError: Read timeout on endpoint URL: "http://localbox:5000/my-bucket/my/key/file.tar"

Running those tests individually causes all of them to pass.

I don't really know where to begin debugging this or understanding the issue, or how to provide more information. Could someone please help identify the problem?

@gmossessian
Copy link
Author

(cross-posting to SO here)

@spulec
Copy link
Collaborator

spulec commented Jul 9, 2019

For the most part, moto will store S3 files in memory. It looks like anything greater than 16MB, we will flush to disk.

If you continue to write files under 16MB to moto s3, then the slowness would make sense.

A couple options:

  • do you need to persist the same s3 backend for each test? If not, you can issue a reset to the backend to clear it (http://localhost:5000/moto-api/reset)
  • Maybe our 16MB is a bad config and we should lower it

@spulec spulec added the debugging Working with user to figure out if there is an issue label Jul 9, 2019
@gmossessian
Copy link
Author

That did help with the speed issues! Thanks.

I wonder if that 16mb number could be configurable, as well as the total memory used before flushing all files to disk?

@spulec
Copy link
Collaborator

spulec commented Jul 11, 2019

Yeah, we can make the individual file size to flush configurable, but we don't have an easy way to make this global.

If anyone has time to make a PR to do that, I would be happy to accept, but otherwise am going to close this out for now. Let me know if there is anything else!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
debugging Working with user to figure out if there is an issue
Projects
None yet
Development

No branches or pull requests

2 participants