s3-proxy icon indicating copy to clipboard operation
s3-proxy copied to clipboard

Potential memory leak

Open armin-malek opened this issue 1 year ago • 10 comments

after startup, it slowly starts using more memory, in a few hours it reaches over 1GB because it works just fine with much less memory usage at startup, I think it's caused by a memory leak

To Reproduce here is the config file I'm using my provider is Idrive e2

# Log configuration
log:
  # Log level
  level: info
  # Log format
  format: text
  # Log file path
  # filePath:

#Server configurations
server:
  listenAddr: ""
  port: 8080

# Targets map
targets:
  first-bucket:
    ## Mount point
    mount:
      path:
        - /mybucket/
    # ## Actions
    actions:
      # Action for GET requests on target
      GET:
        # Will allow GET requests
        enabled: true
        # Configuration for GET requests
        config:
          # Redirect with trailing slash when a file isn't found
          redirectWithTrailingSlashForNotFoundFile: true
          # Index document to display if exists in folder
          indexDocument: index.html
          # Allow to add headers to streamed files (can be templated)
          streamedFileHeaders: {}
          # Redirect to a S3 signed URL
          redirectToSignedUrl: false
          # Signed URL expiration time
          signedUrlExpiration: 15m
          # Disable listing
          # Note: This will return an empty list or you should change the folder list template (in general or in this target)
          disableListing: true
          # Webhooks
          webhooks: []
      # Action for PUT requests on target
      PUT:
        # Will allow PUT requests
        enabled: false
        # Configuration for PUT requests
        config:
          # Metadata key/values that will be put on S3 objects.
          # Values can be templated. Empty values will be flushed.
          metadata:
            key: value
          # System Metadata cases.
          # Values can be templated. Empty values will be flushed.
          systemMetadata:
            # Cache-Control value (will be put as header after)
            cacheControl: ""
            # Content-Disposition value (will be put as header after)
            contentDisposition: ""
            # Content-Encoding value (will be put as header after)
            contentEncoding: ""
            # Content-Language value (will be put as header after)
            contentLanguage: ""
            # Expires value (will be put as header after)
            # Side note: This must have the RFC3339 date format at the end.
            expires: ""
          # Storage class that will be used for uploaded objects
          # See storage class here: https://docs.aws.amazon.com/AmazonS3/latest/dev/storage-class-intro.html
          # Values can be templated. Empty values will be flushed.
          storageClass: STANDARD # GLACIER, ...
          # Will allow override objects if enabled
          allowOverride: false
          # Canned ACL put on each file uploaded.
          # https://docs.aws.amazon.com/AmazonS3/latest/userguide/acl-overview.html#canned-acl
          # cannedACL: ""
          # Webhooks
          webhooks: []
      # Action for DELETE requests on target
      DELETE:
        # Will allow DELETE requests
        enabled: false
        # Configuration for DELETE requests
        config:
          # Webhooks
          webhooks: []
   
    ## Bucket configuration
    bucket:
      name: mybucket
      prefix:
      region: eu-west-1
      s3Endpoint: "idrive-e2.com"
      disableSSL: false
      credentials:
        accessKey:
          env: S3_ACCESS
        secretKey:
          env: S3_KEY

Expected behavior less and stable ram usage

Version and platform (please complete the following information):

  • Platform: Linux
  • Arch: amd64
  • Version: 4.12 (should be latest)

armin-malek avatar Feb 12 '24 09:02 armin-malek

Hello @armin-malek ,

Thanks for your issue.

I never used this provider so I can't say if it is coming from this or not. But I have other ideas in mind. Can you answer those questions please ?:

  • Do you have a lot of requests on your server ?
  • Do you have a lot of different path on your requests ? (/mybucket/file1, file2, file3, ...)

Regards,

oxyno-zeta avatar Feb 12 '24 09:02 oxyno-zeta

we have close to 8 million files in the bucket and we serve around 7 objects per second (in reality it's a burst of 30 to 40 objects every few seconds), the average object size is around 70KB

armin-malek avatar Feb 12 '24 12:02 armin-malek

I think I have an idea of why.

People requesting different files all the time ? Or are they the same for multiple minutes ?

oxyno-zeta avatar Feb 12 '24 13:02 oxyno-zeta

it's like an image hosting platform so yeah it should be mostly random objects

armin-malek avatar Feb 12 '24 13:02 armin-malek

Ok so I think I know why. This must come from prometheus metrics which are saving metrics per "request path". This can be patched for sure.

oxyno-zeta avatar Feb 12 '24 14:02 oxyno-zeta

Ok so I think I know why. This must come from prometheus metrics which are saving metrics per "request path". This can be patched for sure.

I'm not familiar with the code base but maybe an option to disable the metrics in the config file should do the trick for now, i'll keep restarting the container every once in a while :)

armin-malek avatar Feb 12 '24 14:02 armin-malek

I've just released a new version. The 4.13.0 release have a configuration dedicated for this.

Here is an example:

# Metrics configuration
metrics:
  # Disable router path save in HTTP metrics
  disableRouterPath: true

That should fix your problem.

PS: Out of this, do you use s3-proxy to make a tile map server ?

oxyno-zeta avatar Feb 15 '24 21:02 oxyno-zeta

thanks, it has solved the problem!

PS: Out of this, do you use s3-proxy to make a tile map server ? no it is just serving images from a private bucket for a machine learning project

armin-malek avatar Feb 17 '24 07:02 armin-malek

out of this too currently it's logging every request to stdout, is there way to disable that too? i couldn't find it in the docs if i'm not mistaken writing to stdout is not exactly cheap what other log levels we have in the config file?

armin-malek avatar Feb 17 '24 07:02 armin-malek

Cool to hear this ! That's great!

Yes that's a feature to log everything. You can change the log level to error if you want only errors. All log levels from uber/zap logger are supported.

oxyno-zeta avatar Feb 17 '24 12:02 oxyno-zeta

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 10 days

github-actions[bot] avatar Mar 19 '24 00:03 github-actions[bot]