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

Moved to Axum and async #33

Merged
merged 8 commits into from
Feb 10, 2025
Merged

Moved to Axum and async #33

merged 8 commits into from
Feb 10, 2025

Conversation

dpp
Copy link
Contributor

@dpp dpp commented Feb 10, 2025

💻 Description of Change(s) (w/ context)

Moved From Roullie web framework (synchronous) to Axum (tokio's own web framework and async)

Updated a lot of code to be async. Addressed some async performance issues related to BufReader

Cleaned up routing code

🧠 Rationale Behind Change(s)

Moving to a supported web framework is important.

Axum is OpenAPI-friendly and soon there'll be OpenAPI endpoints

Axum's routing scheme is easier to layer on top of which will be important for other applications
that embed Big Tent.

Async is Rust's future (ha ha)... so might as well get on the Async train... or at least Promise to...

📝 Test Plan

All existing tests work

📜 Documentation

Added code documentation

💣 Quality Control

(All items must be checked before a PR is merged)
Did you…

  • Mention an issue number in the PR title?
  • Update the version # in the build file?
  • Create new and/or update relevant existing tests?
  • Create or update relevant documentation and/or diagrams?
  • Comment your code?
  • Fix any stray verbose logging (removing, or moving to debug / trace level)?

Before Merging…

  • Make sure the Quality Control boxes are all ticked
  • Make sure any open comments or conversations on the PR are resolved

Comment on lines 47 to 51
// 25M
const MAX_DATA_FILE_SIZE: u64 = 15 * 1024 * 1024 * 1024;
const MAX_INDEX_CNT: usize = 25 * 1024 * 1024;

// 15GB
Copy link
Contributor

Choose a reason for hiding this comment

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

Comments got dissociated from their target

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

.file
.lock()
.map_err(|e| anyhow!("Failed to lock {:?}", e))?;
let mut my_file = self.file.lock().await;
Copy link
Contributor

Choose a reason for hiding this comment

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

Interesting. Locking that's infallible?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Probably causes the whole Tokio runtime to panic/collapse... but that'll never happen in production at 2am... never!

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh no

src/server.rs Outdated
Comment on lines 163 to 170
.route("/bulk", post(serve_bulk))
.route("/{*gitoid}", get(serve_gitoid))
.route("/aa/{*gitoid}", get(serve_anti_alias))
.route("/north/{*gitoid}", get(serve_north))
.route("/north_purls/{*gitoid}", get(serve_north_purls))
.route("/north", post(serve_bulk_north))
.route("/north_purls", post(serve_bulk_north_purls))
.with_state(state);
Copy link
Contributor

Choose a reason for hiding this comment

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

So much nicer to parse as a person trying to understand the structure of the app

src/config.rs Outdated
pub fn num_threads(&self) -> u16 {
self.threads.unwrap_or(7)
}
// pub fn num_threads(&self) -> u16 {

Choose a reason for hiding this comment

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

Is this no longer needed? Should it be removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

let mut data_file = GoatRodeoCluster::find_file(dir, hash, "grd")?;
pub async fn new(dir: &PathBuf, hash: u64) -> Result<DataFile> {
let mut data_file = GoatRodeoCluster::find_file(dir, hash, "grd").await?;

Choose a reason for hiding this comment

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

what is this magic value "grd" ? should it be a named constant?

Copy link
Contributor

Choose a reason for hiding this comment

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

"Goat rodeo data"

I'm definitely on team "just inline them please, so I don't have to chase a zillion references to read anything"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Created constants...

Copy link

@dpletter dpletter left a comment

Choose a reason for hiding this comment

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

just left a couple nit-picky questions

pub fn get_cluster(&self) -> GoatRodeoCluster {
let the_cluster: GoatRodeoCluster = (&(**self.get_cluster_arcswap().load())).clone();
pub fn get_cluster(&self) -> Arc<GoatRodeoCluster> {
let the_cluster: Arc<GoatRodeoCluster> = (&(*self.get_cluster_arcswap().load())).clone();
Copy link
Contributor

Choose a reason for hiding this comment

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

This smells funny, I might unpack that later and see if I can figure out why the reference hackery is needed. Looks like it does the right thing though so shipit

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's because we need to pass Arc<GoatRodeoCluster> around... and clone()ing an Arc is much cheaper than cloning the underlying data structure.

Copy link
Contributor

Choose a reason for hiding this comment

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

okay but the reference and pointer creation isn't needed:

Suggested change
let the_cluster: Arc<GoatRodeoCluster> = (&(*self.get_cluster_arcswap().load())).clone();
let the_cluster: Arc<GoatRodeoCluster> = self.get_cluster_arcswap().load().clone();

Comment on lines 40 to 41
pub fn get_cluster(&self) -> Arc<GoatRodeoCluster> {
let the_cluster: Arc<GoatRodeoCluster> = (&(*self.get_cluster_arcswap().load())).clone();
Copy link
Contributor

@aredridel aredridel Feb 10, 2025

Choose a reason for hiding this comment

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

Or even this:

Suggested change
pub fn get_cluster(&self) -> Arc<GoatRodeoCluster> {
let the_cluster: Arc<GoatRodeoCluster> = (&(*self.get_cluster_arcswap().load())).clone();
pub fn get_cluster(&self) -> Arc<GoatRodeoCluster> {
self.get_cluster_arcswap().load().clone()

Signed-off-by: David Pollak <[email protected]>
@dpp dpp requested a review from aredridel February 10, 2025 22:27
@dpp dpp merged commit edff1f6 into main Feb 10, 2025
1 check passed
@dpp dpp deleted the poem_version branch February 12, 2025 13:16
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.

4 participants