From 2762245519efa299063fd3e91a4f2c7c2e5d7804 Mon Sep 17 00:00:00 2001 From: "Jonathan M. Henson" Date: Wed, 8 Nov 2023 16:33:38 -0800 Subject: [PATCH] =?UTF-8?q?Added=20function=20for=20returning=20the=20reco?= =?UTF-8?q?mmended=20max=20bandwidth=20for=20the=20cr=E2=80=A6=20(#520)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Waqar Ahmed Khan Co-authored-by: Michael Graeb --- awscrt/s3.py | 19 ++++++++++++++++++- crt/aws-c-auth | 2 +- crt/aws-c-cal | 2 +- crt/aws-c-common | 2 +- crt/aws-c-http | 2 +- crt/aws-c-s3 | 2 +- crt/aws-lc | 2 +- crt/s2n | 2 +- source/module.c | 1 + source/s3.h | 1 + source/s3_client.c | 9 +++++++++ 11 files changed, 36 insertions(+), 8 deletions(-) diff --git a/awscrt/s3.py b/awscrt/s3.py index 2278d8856..d0f559994 100644 --- a/awscrt/s3.py +++ b/awscrt/s3.py @@ -178,7 +178,8 @@ class S3Client(NativeResource): throughput_target_gbps (Optional[float]): Throughput target in Gigabits per second (Gbps) that we are trying to reach. - (10.0 Gbps by default) + You can also use `get_recommended_throughput_target_gbps()` to get recommended value for your system. + 10.0 Gbps by default (may change in future) """ __slots__ = ('shutdown_event', '_region') @@ -586,3 +587,19 @@ def is_optimized_for_system(): for the current system. """ return _awscrt.s3_is_crt_s3_optimized_for_system() + + +def get_recommended_throughput_target_gbps() -> Optional[float]: + """ + Returns: + Recommended throughput, in gigabits per second, based on detected system configuration. + If the best throughput configuration is unknown, returns None. + Use this as the S3Client's `throughput_target_gbps`. + """ + # Currently the CRT returns 0 if it was unable to make a good guess on configuration. Pre-known configs, have this value set. + # Eventually, the CRT will make a full calculation based on NIC and CPU configuration, but until then handle 0. + max_value = _awscrt.s3_get_recommended_throughput_target_gbps() + if max_value > 0: + return max_value + else: + return None diff --git a/crt/aws-c-auth b/crt/aws-c-auth index ecbb37fe6..71bad382f 160000 --- a/crt/aws-c-auth +++ b/crt/aws-c-auth @@ -1 +1 @@ -Subproject commit ecbb37fe6549e7a0f5814050be076a2312118b38 +Subproject commit 71bad382fe0a61e4426987c1abe6aca2fe1c1953 diff --git a/crt/aws-c-cal b/crt/aws-c-cal index 033a132df..b52d9e8ee 160000 --- a/crt/aws-c-cal +++ b/crt/aws-c-cal @@ -1 +1 @@ -Subproject commit 033a132dfbcd1822ac65969a1feee31d6e1a81f9 +Subproject commit b52d9e8ee7af8155e6928c977ec5fde25a507ba0 diff --git a/crt/aws-c-common b/crt/aws-c-common index fb3182c54..00157ef20 160000 --- a/crt/aws-c-common +++ b/crt/aws-c-common @@ -1 +1 @@ -Subproject commit fb3182c5411e4f5da2ee9372e0d66aa3f15a026d +Subproject commit 00157ef20fd270d393930ac1cfed5190ccba2af8 diff --git a/crt/aws-c-http b/crt/aws-c-http index d777859b6..a082f8a20 160000 --- a/crt/aws-c-http +++ b/crt/aws-c-http @@ -1 +1 @@ -Subproject commit d777859b6da179b9098f87a2077fbf2129b574dc +Subproject commit a082f8a2067e4a31db73f1d4ffd702a8dc0f7089 diff --git a/crt/aws-c-s3 b/crt/aws-c-s3 index ecaf3f754..f354c535d 160000 --- a/crt/aws-c-s3 +++ b/crt/aws-c-s3 @@ -1 +1 @@ -Subproject commit ecaf3f7549c8339f678ed348706fcc62038a5a5e +Subproject commit f354c535db928591d7f44bdc00acccc77650a67c diff --git a/crt/aws-lc b/crt/aws-lc index 40f0eb69c..fa62b83a7 160000 --- a/crt/aws-lc +++ b/crt/aws-lc @@ -1 +1 @@ -Subproject commit 40f0eb69cfbdb201308c51bf12feffc247fb4186 +Subproject commit fa62b83a70fa44d31bca43a0c3f82b7c4d3d5e1c diff --git a/crt/s2n b/crt/s2n index 3526e69d6..95753f0c5 160000 --- a/crt/s2n +++ b/crt/s2n @@ -1 +1 @@ -Subproject commit 3526e69d6b61efedf454f436a6d876fb3e9b6cd7 +Subproject commit 95753f0c528b59025343e8799cb25d3e9df89e21 diff --git a/source/module.c b/source/module.c index 20c6fadfe..bb423f029 100644 --- a/source/module.c +++ b/source/module.c @@ -801,6 +801,7 @@ static PyMethodDef s_module_methods[] = { AWS_PY_METHOD_DEF(s3_meta_request_cancel, METH_VARARGS), AWS_PY_METHOD_DEF(s3_get_ec2_instance_type, METH_NOARGS), AWS_PY_METHOD_DEF(s3_is_crt_s3_optimized_for_system, METH_NOARGS), + AWS_PY_METHOD_DEF(s3_get_recommended_throughput_target_gbps, METH_NOARGS), AWS_PY_METHOD_DEF(s3_cross_process_lock_new, METH_VARARGS), AWS_PY_METHOD_DEF(s3_cross_process_lock_acquire, METH_VARARGS), AWS_PY_METHOD_DEF(s3_cross_process_lock_release, METH_VARARGS), diff --git a/source/s3.h b/source/s3.h index 48c847ea2..3821acd07 100644 --- a/source/s3.h +++ b/source/s3.h @@ -9,6 +9,7 @@ PyObject *aws_py_s3_get_ec2_instance_type(PyObject *self, PyObject *args); PyObject *aws_py_s3_is_crt_s3_optimized_for_system(PyObject *self, PyObject *args); +PyObject *aws_py_s3_get_recommended_throughput_target_gbps(PyObject *self, PyObject *args); PyObject *aws_py_s3_client_new(PyObject *self, PyObject *args); PyObject *aws_py_s3_client_make_meta_request(PyObject *self, PyObject *args); diff --git a/source/s3_client.c b/source/s3_client.c index 25966d756..33bb17b29 100644 --- a/source/s3_client.c +++ b/source/s3_client.c @@ -39,6 +39,15 @@ PyObject *aws_py_s3_is_crt_s3_optimized_for_system(PyObject *self, PyObject *arg Py_RETURN_FALSE; } +PyObject *aws_py_s3_get_recommended_throughput_target_gbps(PyObject *self, PyObject *args) { + (void)self; + (void)args; + + const struct aws_s3_platform_info *platform_info = aws_s3_get_current_platform_info(); + + return PyFloat_FromDouble(platform_info->max_throughput_gbps); +} + struct cross_process_lock_binding { struct aws_cross_process_lock *lock; struct aws_string *name;