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

Codegenerate StructureShape, BlobShape, application, server and Python runtime #1403

Merged
merged 62 commits into from
Jun 14, 2022

Conversation

crisidev
Copy link
Contributor

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@github-actions
Copy link

A new generated diff is ready to view.

A new doc preview is ready to view.

Rust Wrk benchmark report:

Duration: 90 sec, Connections: 32, Threads: 2

Measurement Deviation Current Old
Requests/sec 10.45% 67390.31 61012.18
Total requests 10.47% 6070367 5495122
Total errors NaN% 0 0
Total successes 10.47% 6070367 5495122
Average latency ms 26.76% 0.9 0.71
Minimum latency ms 0.00% 0.02 0.02
Maximum latency ms 30.99% 21.64 16.52
Stdev latency ms 58.24% 1.44 0.91
Transfer Mb 10.47% 631.02 571.22
Connect errors NaN% 0 0
Read errors NaN% 0 0
Write errors NaN% 0 0
Status errors (not 2xx/3xx) NaN% 0 0
Timeout errors NaN% 0 0

@github-actions
Copy link

A new generated diff is ready to view.

A new doc preview is ready to view.

Rust Wrk benchmark report:

Duration: 90 sec, Connections: 32, Threads: 2

Measurement Deviation Current Old
Requests/sec 5.06% 38569.19 36712.83
Total requests 5.11% 3474887 3305971
Total errors NaN% 0 0
Total successes 5.11% 3474887 3305971
Average latency ms -2.20% 0.89 0.91
Minimum latency ms -33.33% 0.02 0.03
Maximum latency ms -4.45% 19.13 20.02
Stdev latency ms 16.39% 0.71 0.61
Transfer Mb 5.11% 361.22 343.66
Connect errors NaN% 0 0
Read errors NaN% 0 0
Write errors NaN% 0 0
Status errors (not 2xx/3xx) NaN% 0 0
Timeout errors NaN% 0 0

@github-actions
Copy link

A new generated diff is ready to view.

A new doc preview is ready to view.

Rust Wrk benchmark report:

Duration: 90 sec, Connections: 32, Threads: 2

Measurement Deviation Current Old
Requests/sec -2.79% 73331.78 75435.49
Total requests -2.83% 6604353 6796506
Total errors NaN% 0 0
Total successes -2.83% 6604353 6796506
Average latency ms -7.04% 0.66 0.71
Minimum latency ms 0.00% 0.02 0.02
Maximum latency ms 17.74% 21.04 17.87
Stdev latency ms -14.29% 0.96 1.12
Transfer Mb -2.83% 686.53 706.5
Connect errors NaN% 0 0
Read errors NaN% 0 0
Write errors NaN% 0 0
Status errors (not 2xx/3xx) NaN% 0 0
Timeout errors NaN% 0 0

@crisidev crisidev added enhancement New feature or request server Rust server SDK labels May 23, 2022
@github-actions
Copy link

A new generated diff is ready to view.

A new doc preview is ready to view.

Rust Wrk benchmark report:

Duration: 90 sec, Connections: 32, Threads: 2

Measurement Deviation Current Old
Requests/sec 0.94% 71465.14 70796.63
Total requests 0.94% 6434729 6374545
Total errors NaN% 0 0
Total successes 0.94% 6434729 6374545
Average latency ms 8.65% 1.13 1.04
Minimum latency ms 0.00% 0.02 0.02
Maximum latency ms 45.88% 34.34 23.54
Stdev latency ms 11.70% 1.91 1.71
Transfer Mb 0.94% 668.89 662.64
Connect errors NaN% 0 0
Read errors NaN% 0 0
Write errors NaN% 0 0
Status errors (not 2xx/3xx) NaN% 0 0
Timeout errors NaN% 0 0

@github-actions
Copy link

A new generated diff is ready to view.

A new doc preview is ready to view.

Rust Wrk benchmark report:

Duration: 90 sec, Connections: 32, Threads: 2

Measurement Deviation Current Old
Requests/sec 9.18% 78921.15 72284.45
Total requests 9.19% 7110228 6511760
Total errors NaN% 0 0
Total successes 9.19% 7110228 6511760
Average latency ms 28.38% 0.95 0.74
Minimum latency ms 0.00% 0.02 0.02
Maximum latency ms 15.51% 22.27 19.28
Stdev latency ms 42.11% 1.62 1.14
Transfer Mb 9.19% 739.11 676.9
Connect errors NaN% 0 0
Read errors NaN% 0 0
Write errors NaN% 0 0
Status errors (not 2xx/3xx) NaN% 0 0
Timeout errors NaN% 0 0

@github-actions
Copy link

A new generated diff is ready to view.

A new doc preview is ready to view.

Rust Wrk benchmark report:

Duration: 90 sec, Connections: 32, Threads: 2

Measurement Deviation Current Old
Requests/sec -1.01% 85915.53 86792.88
Total requests -0.95% 7737265 7811493
Total errors NaN% 0 0
Total successes -0.95% 7737265 7811493
Average latency ms 9.65% 1.25 1.14
Minimum latency ms 0.00% 0.02 0.02
Maximum latency ms -10.20% 25.43 28.32
Stdev latency ms 4.72% 2.22 2.12
Transfer Mb -0.95% 804.29 812.01
Connect errors NaN% 0 0
Read errors NaN% 0 0
Write errors NaN% 0 0
Status errors (not 2xx/3xx) NaN% 0 0
Timeout errors NaN% 0 0

@github-actions
Copy link

A new generated diff is ready to view.

A new doc preview is ready to view.

Rust Wrk benchmark report:

Duration: 90 sec, Connections: 32, Threads: 2

Measurement Deviation Current Old
Requests/sec 2.08% 88795.1 86985.81
Total requests 2.07% 7995892 7833927
Total errors NaN% 0 0
Total successes 2.07% 7995892 7833927
Average latency ms -4.17% 0.46 0.48
Minimum latency ms 0.00% 0.01 0.01
Maximum latency ms -41.43% 16.61 28.36
Stdev latency ms -6.94% 0.67 0.72
Transfer Mb 2.07% 831.18 814.34
Connect errors NaN% 0 0
Read errors NaN% 0 0
Write errors NaN% 0 0
Status errors (not 2xx/3xx) NaN% 0 0
Timeout errors NaN% 0 0

Add decorator to add `use aws_smithy_http_server_python::types` to
lib.rs.
@github-actions
Copy link

A new generated diff is ready to view.

A new doc preview is ready to view.

Rust Wrk benchmark report:

Duration: 90 sec, Connections: 32, Threads: 2

Measurement Deviation Current Old
Requests/sec 7.38% 73412.13 68366.65
Total requests 7.30% 6609403 6159650
Total errors NaN% 0 0
Total successes 7.30% 6609403 6159650
Average latency ms 21.65% 1.18 0.97
Minimum latency ms -50.00% 0.01 0.02
Maximum latency ms -7.65% 22.1 23.93
Stdev latency ms 25.93% 2.04 1.62
Transfer Mb 7.30% 687.05 640.3
Connect errors NaN% 0 0
Read errors NaN% 0 0
Write errors NaN% 0 0
Status errors (not 2xx/3xx) NaN% 0 0
Timeout errors NaN% 0 0

@github-actions
Copy link

A new generated diff is ready to view.

A new doc preview is ready to view.

@github-actions
Copy link

A new generated diff is ready to view.

A new doc preview is ready to view.

@github-actions
Copy link

A new generated diff is ready to view.

A new doc preview is ready to view.

@github-actions
Copy link

A new generated diff is ready to view.

A new doc preview is ready to view.

Copy link
Contributor

@david-perez david-perez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2nd pass. Much better regarding code duplication. We should invest into reducing the remaining bits of duplication via decorators, CodegenTarget, or more inheritance in future PRs.

@@ -61,6 +60,9 @@ class RustCodegenServerPlugin : SmithyBuildPlugin {
symbolVisitorConfig: SymbolVisitorConfig = DefaultConfig
) =
SymbolVisitor(model, serviceShape = serviceShape, config = symbolVisitorConfig)
// Rename a set of symbols that do not implement `PyClass` and have been wrapped in
// `aws_smithy_http_server_python::types`.
.let { PythonServerSymbolProvider(it) }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll also need a symbol provider that renames reserved Python keywords?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so. We are not generating any pure python code, everything is shared through the CFFI layer, hence I don't see anything we should really rename here.

class PythonServerCodegenVisitor(context: PluginContext, private val codegenDecorator: RustCodegenDecorator) :
ServerCodegenVisitor(context, codegenDecorator) {

init {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could have a function that given a symbol provider, sets up the rest of the stuff.

import software.amazon.smithy.rust.codegen.server.python.smithy.PythonServerCargoDependency

/**
* This module contains utilities to render PyO3 attributes.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these extension methods really necessary? It think you get the same syntax sugar by using the Attribute class from RustTypes and calling render.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are probably right, but I think having these methods in their own separate file is actually nice and I think this file will grow over time with new helpers.. If don't have strong opinions on this, if you feel we should get rid of them I can try to just use the Attribute class.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have tried to use the Attribute class to render pyo3 attributes, but it messes up the code by removing the // of any doc block that is rendered just after it and I don't really understand why.

I will add an issue to this block of code to understand what is going on and try to move to the Attribute class at a later stage.

Copy link
Contributor Author

@crisidev crisidev Jun 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like the issue comes from https://github.com/awslabs/smithy-rs/blob/15e1b3425f56ff2606121e99dff11de38424c744/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/rustlang/RustTypes.kt#L377

This line uses writer.raw(). If I change the line from writer.raw("#$bang[$annotation]") to writer.rust("##$bang[$annotation]" it start rendering as I would expect.

I am not sure of the implications of making this change..

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"SmithyPython" to PythonServerCargoDependency.SmithyHttpServerPython(codegenContext.runtimeConfig).asType()
)

override fun renderStructure() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think tacking on attributes is best accomplished through decorators. If the structures we're generating are fundamentally different / additional, then inheritance, CodegenTarget or splitting are better approaches.

/// Custom error.
#[error("{0}")]
Custom(String),
/// Implement `From<pyo3::PyErr>`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are the Rustdoc comments accurate? Starting with "Implement" I mean.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regarding thiserror, why are we not using it in other places? @rcoh

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed Rustdoc comments.

@github-actions
Copy link

A new generated diff is ready to view.

A new doc preview is ready to view.

@github-actions
Copy link

A new generated diff is ready to view.

A new doc preview is ready to view.

@github-actions
Copy link

A new generated diff is ready to view.

A new doc preview is ready to view.

@github-actions
Copy link

A new generated diff is ready to view.

A new doc preview is ready to view.

Copy link
Collaborator

@jdisanti jdisanti left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@crisidev crisidev enabled auto-merge (squash) June 14, 2022 15:45
@github-actions
Copy link

A new generated diff is ready to view.

A new doc preview is ready to view.

@crisidev crisidev merged commit 8e84ee2 into main Jun 14, 2022
@crisidev crisidev deleted the oxipy-struct-codegen branch June 14, 2022 16:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request server Rust server SDK
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants