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

Rust python module with helpers for meta-memcache #1

Merged
merged 4 commits into from
Nov 17, 2023
Merged

Conversation

bisho
Copy link
Member

@bisho bisho commented Nov 6, 2023

Motivation / Description

Implementing this in rust is simple and benchmarking
the rust cost gives 20-50 ns runtime. Unfortunately
a lot of time is spent in the bridge between python
and rust, so a call to rust code is not cheap, yet
this implementation speeds up some meta-memcache
code significantly.

@bisho bisho force-pushed the initial_import branch 7 times, most recently from 5fd65e7 to 1b416d8 Compare November 7, 2023 14:16
@bisho bisho marked this pull request as ready for review November 7, 2023 23:49
@bisho bisho requested a review from a team November 7, 2023 23:49
Copy link

@thecadams thecadams left a comment

Choose a reason for hiding this comment

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

Took a look. Looks good at first glance, couple of questions:

  • Should .gitignore include everything from the template? Might be better to cut it to what's needed
  • We should remove lib.rs.old I think, no need for it since the refactor to separate files
  • You can have tests in a separate file if you wish to keep the files smaller, following the pattern in khepri auto load shedder and metrics exporter, where the tests are in mod tests in tests.rs and mod tests; is added to lib.rs to make sure the module is imported.

TIL: maturin

@bisho
Copy link
Member Author

bisho commented Nov 8, 2023

Took a look. Looks good at first glance, couple of questions:

  • Should .gitignore include everything from the template? Might be better to cut it to what's needed

What template? This was the default created for the maturin project (I did not manually tunned it), happy to change it if there is a better template.

  • We should remove lib.rs.old I think, no need for it since the refactor to separate files

Ops

  • You can have tests in a separate file if you wish to keep the files smaller, following the pattern in khepri auto load shedder and metrics exporter, where the tests are in mod tests in tests.rs and mod tests; is added to lib.rs to make sure the module is imported.

I read the convention in rust is unit tests in the same file, integration tests in separate module. But no strong opinion on this.

## Motivation / Description
Implementing this in rust is simple and benchmarking
the rust cost gives 20-50 ns runtime. Unfortunately
a lot of time is spent in the bridge between python
and rust, so a call to rust code is not cheap, yet
this implementation speeds up some meta-memcache
code significantly.
Copy link

@ethervoid ethervoid left a comment

Choose a reason for hiding this comment

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

First batch of comments

Cargo.toml Outdated Show resolved Hide resolved
}

#[cfg(test)]
mod tests {

Choose a reason for hiding this comment

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

Is this the way to make tests in Rust? I thought you should have them in another file or something

Copy link
Member Author

Choose a reason for hiding this comment

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

Apparently, for unit tests... but it also bugs me... I'll move them.

Choose a reason for hiding this comment

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

Yes it's idiomatic Rust to do tests in the same file, but given you can have multiple files in the same directory with mod BLAH and the compiler will treat it all as being in the same module (there's a separate file scope).. we can abandon that convention and keep files nice and small for easier reviews.

src/constants.rs Outdated Show resolved Hide resolved
src/impl_build_cmd.rs Outdated Show resolved Hide resolved
src/impl_build_cmd.rs Show resolved Hide resolved
src/impl_build_cmd.rs Show resolved Hide resolved
Copy link

@ethervoid ethervoid left a comment

Choose a reason for hiding this comment

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

Second batch

src/impl_build_cmd.rs Show resolved Hide resolved

pub fn impl_parse_header(
data: &[u8],
start: usize,

Choose a reason for hiding this comment

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

nit: Same here with usize. I assume the data.len is not going to be greater than 65k?

Copy link
Member Author

Choose a reason for hiding this comment

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

You can arguably configure a receive buffer of more than 64KB depending on your usage and avg value len...

src/request_flags.rs Show resolved Hide resolved
Copy link

@thecadams thecadams left a comment

Choose a reason for hiding this comment

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

It's looking great! Super excited to see this out in the wild.

By the way, if you want code coverage, you should be able to adapt cov.sh from the envoy modules.

Giving you an approval so you aren't blocked, but of course @ethervoid should approve too given the open comments

Cargo.toml Outdated Show resolved Hide resolved
Cargo.toml Outdated Show resolved Hide resolved
src/impl_build_cmd.rs Show resolved Hide resolved
src/response_flags.rs Show resolved Hide resolved
src/response_flags.rs Show resolved Hide resolved
@thecadams
Copy link

Took a look. Looks good at first glance, couple of questions:

  • Should .gitignore include everything from the template? Might be better to cut it to what's needed

What template? This was the default created for the maturin project (I did not manually tunned it), happy to change it if there is a better template.

Good point, default template is OK I guess. Just that it had a ton of extraneous stuff. It's always subjective whether to include the everything or be minimal and strip it down to just what's needed, either way is fine so if you prefer to stick with the template .gitignore then no problem.

@bisho bisho merged commit 8d304a2 into main Nov 17, 2023
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants