-
Notifications
You must be signed in to change notification settings - Fork 74
Use aiobotocore 2.2.0 to support assume role credentials #157
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
Changes from all commits
6e30410
d1db395
6381e5c
f8e8cba
3fc3f1e
69dbe3e
d3e4813
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,8 +3,9 @@ | |
| # Copyright (c) 2015, thumbor-community | ||
| # Use of this source code is governed by the MIT license that can be | ||
| # found in the LICENSE file. | ||
| import io | ||
|
|
||
| import aiobotocore | ||
| import aiobotocore.session | ||
| from botocore.client import Config | ||
| from thumbor.utils import logger | ||
| from thumbor.engines import BaseEngine | ||
|
|
@@ -26,6 +27,7 @@ def __new__(cls, bucket, region, endpoint, *args, **kwargs): | |
| """ | ||
| This handles all communication with AWS API | ||
| """ | ||
|
|
||
| def __init__(self, bucket, region, endpoint, max_retry=None): | ||
| """ | ||
| Constructor | ||
|
|
@@ -44,24 +46,22 @@ def __init__(self, bucket, region, endpoint, max_retry=None): | |
| ) | ||
| ) | ||
|
|
||
| if self._client is None: | ||
| self._client = aiobotocore.get_session().create_client( | ||
| 's3', | ||
| region_name=region, | ||
| endpoint_url=endpoint, | ||
| config=config | ||
| ) | ||
| self.region_name = region | ||
| self.endpoint_url = endpoint | ||
| self.session = aiobotocore.session.get_session() | ||
|
|
||
| async def exists(self, path): | ||
| """ | ||
| Checks if an object exists at a given path | ||
| :param string path: Path or 'key' to retrieve AWS object | ||
| """ | ||
| try: | ||
| await self._client.head_object( | ||
| Bucket=self._bucket, | ||
| Key=self._clean_key(path), | ||
| ) | ||
| async with self.session.create_client('s3', region_name=self.region_name, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did you test this with a load-intensive process? We had performance issues in the past without the singleton client
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I did some tests using I remember that the client was a corutine itself ... but I'll run some tests and paste the results here to help with the analysis. Originally, I was worried about opening the payload at https://github.com/thumbor-community/aws/pull/157/files#diff-8c5f6e09db7784ddba2fc0a87e8c9e5436275868ae07088bc1f5a1c888c45224R74-R81, but that hint about the client is warm as well. I'll brb soon with the hey results.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there any performance tests guidelines or number to make a comparison? Here is the information about the tests that I made. In my case, my CPU is the following: I ran the tests using docker on a Linux Machine in all cases. Each test was run three times and in my scenario, I have an S3 bucket served through minio and a redis cache: Bellow, I post the results for both thumbor 6.3 and thumbor 7.0.7 with the new plugin.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thumbor 6.3.0 using apsl/thumbor docker imageThis is an old but functional image (but with lots of critical CVEs though) using the following packages: The command hey -c 100 -z 30s http://localhost:8080/unsafe/300x200/smart/0864bf97-8369-42d7-ad8c-449541ea541c-original.png`, which emulates 100 clients during the 30s, yielded the following results: During the tests, the CPU use was 100% (1 CPU) and RAM usage was about ~160MB in the first run, but was increasing by ~20MB on each test round, maybe indicating some sort of memory leak.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thumbor 7.0.7This image has the following packages: The command This time, the RAM Usage was near ~82MB of RAM and didn't change during other test rounds. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the performance tests. |
||
| endpoint_url=self.endpoint_url) as s3_client: | ||
| await s3_client.head_object( | ||
| Bucket=self._bucket, | ||
| Key=self._clean_key(path), | ||
| ) | ||
| except Exception: | ||
| return False | ||
| return True | ||
|
|
@@ -71,11 +71,16 @@ async def get(self, path): | |
| Returns object at given path | ||
| :param string path: Path or 'key' to retrieve AWS object | ||
| """ | ||
| async with self.session.create_client('s3', region_name=self.region_name, | ||
| endpoint_url=self.endpoint_url) as s3_client: | ||
| response = await s3_client.get_object(Bucket=self._bucket, Key=self._clean_key(path)) | ||
| # TODO: Verify if it is possible to restore the original behavior were response['Body'] was a coroutine. | ||
| # Thumbor was getting stuck when response['Body'].read() was being called by s3_loader.load. | ||
| # To Avoid this, we read the Body content and expose it as a BytesIO to maintain the interface. | ||
| content = await response['Body'].read() | ||
| response['Body'] = io.BytesIO(content) | ||
|
|
||
| return await self._client.get_object( | ||
| Bucket=self._bucket, | ||
| Key=self._clean_key(path), | ||
| ) | ||
| return response | ||
|
|
||
| async def get_url(self, path, method='GET', expiry=3600): | ||
| """ | ||
|
|
@@ -84,18 +89,19 @@ async def get_url(self, path, method='GET', expiry=3600): | |
| :param string method: Method for requested URL | ||
| :param int expiry: URL validity time | ||
| """ | ||
| async with self.session.create_client('s3', region_name=self.region_name, | ||
| endpoint_url=self.endpoint_url) as s3_client: | ||
| url = await s3_client.generate_presigned_url( | ||
| ClientMethod='get_object', | ||
| Params={ | ||
| 'Bucket': self._bucket, | ||
| 'Key': self._clean_key(path), | ||
| }, | ||
| ExpiresIn=expiry, | ||
| HttpMethod=method, | ||
| ) | ||
|
|
||
| url = await self._client.generate_presigned_url( | ||
| ClientMethod='get_object', | ||
| Params={ | ||
| 'Bucket': self._bucket, | ||
| 'Key': self._clean_key(path), | ||
| }, | ||
| ExpiresIn=expiry, | ||
| HttpMethod=method, | ||
| ) | ||
|
|
||
| return url | ||
| return url | ||
|
|
||
| async def put(self, path, data, metadata=None, reduced_redundancy=False, encrypt_key=False): | ||
| """ | ||
|
|
@@ -123,17 +129,21 @@ async def put(self, path, data, metadata=None, reduced_redundancy=False, encrypt | |
| if metadata is not None: | ||
| args['Metadata'] = metadata | ||
|
|
||
| return await self._client.put_object(**args) | ||
| async with self.session.create_client('s3', region_name=self.region_name, | ||
| endpoint_url=self.endpoint_url) as s3_client: | ||
| return await s3_client.put_object(**args) | ||
|
|
||
| async def delete(self, path): | ||
| """ | ||
| Deletes key at given path | ||
| :param string path: Path or 'key' to delete | ||
| """ | ||
| return await self._client.delete_object( | ||
| Bucket=self._bucket, | ||
| Key=self._clean_key(path), | ||
| ) | ||
| async with self.session.create_client('s3', region_name=self.region_name, | ||
| endpoint_url=self.endpoint_url) as s3_client: | ||
| return await s3_client.delete_object( | ||
| Bucket=self._bucket, | ||
| Key=self._clean_key(path), | ||
| ) | ||
|
|
||
| def _clean_key(self, path): | ||
| logger.debug('Cleaning key: {path!r}'.format(path=path)) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.