Skip to content

Commit

Permalink
Added function for returning the recommended max bandwidth for the cr… (
Browse files Browse the repository at this point in the history
#520)

Co-authored-by: Waqar Ahmed Khan <[email protected]>
Co-authored-by: Michael Graeb <[email protected]>
  • Loading branch information
3 people authored Nov 9, 2023
1 parent 16e6492 commit 2762245
Show file tree
Hide file tree
Showing 11 changed files with 36 additions and 8 deletions.
19 changes: 18 additions & 1 deletion awscrt/s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion crt/aws-c-cal
2 changes: 1 addition & 1 deletion crt/aws-c-common
2 changes: 1 addition & 1 deletion crt/aws-c-s3
2 changes: 1 addition & 1 deletion crt/aws-lc
2 changes: 1 addition & 1 deletion crt/s2n
Submodule s2n updated from 3526e6 to 95753f
1 change: 1 addition & 0 deletions source/module.c
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
1 change: 1 addition & 0 deletions source/s3.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
9 changes: 9 additions & 0 deletions source/s3_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 2762245

Please sign in to comment.