Skip to content

Migrate from Rocket to Axum#95

Merged
RemiBardon merged 31 commits intomasterfrom
axum
Jan 5, 2025
Merged

Migrate from Rocket to Axum#95
RemiBardon merged 31 commits intomasterfrom
axum

Conversation

@RemiBardon
Copy link
Member

@RemiBardon RemiBardon commented Dec 13, 2024

I don't want to finish #71 using Rocket while we're supposed to migrate to Axum after that. Let's migrate now.

Compile time and size comparisons

After rewriting the API using Axum and fixing all smoke tests and integration tests, I executed a custom script which would build the API before and after the rewrite, in release mode, to compare the compile times and image sizes.

I executed the script on my machine with no other app running in the foreground, and made sure to purge all Docker caches to get a complete build.

The script
#!/bin/bash

SUMMARY_FILE="summary-$(date +%s).txt"
TIME_LOG_FILE='build-time.log'
IMAGE_NAME='proseim/prose-pod-api:local'

try() {
	local ref="${1:?"Pass a git revision (hash or tag)"}"
	echo "# ${ref:?}" >> "${SUMMARY_FILE:?}"

	git -C "${PROSE_POD_API_DIR:?}" checkout "${ref:?}"

	docker system prune -a -f
	/usr/bin/time -o "${TIME_LOG_FILE:?}" task --taskfile "${PROSE_POD_API_DIR:?}"/Taskfile.yaml build-image

	build-time >> "${SUMMARY_FILE:?}"
	image-size >> "${SUMMARY_FILE:?}"
	echo '' >> "${SUMMARY_FILE:?}"

	rm "${TIME_LOG_FILE:?}"
}

build-time() {
	cat "${TIME_LOG_FILE:?}"
}

image-size() {
	docker image ls "${IMAGE_NAME:?}" --format "{{.Size}}"
}

try v0.4.0
try axum

After 18 minutes, it yielded the following:

# v0.4.0
      606.08 real         4.27 user         5.88 sys
25.2MB

# axum
      410.05 real         3.33 user         5.11 sys
24.1MB

We can see that the build took 32% less time using Axum ($(606-410)/606=0.32$), and 22% less User CPU time ($(4.27-3.33)/4.27=0.22$), which is even better than I expected! System CPU time also went down by 13% ($(5.88-5.11)/5.88=0.13$).

The resulting binary is almost the same size, with a small 4% reduction ($(25.2-24.1)/25.2=0.04$). At least it didn't increase.


NOTE: I will fix release builds in a separate PR. (Already done in #96)

@RemiBardon RemiBardon added enhancement New feature or request cleanup Refactors / cleans up the code labels Dec 13, 2024
@RemiBardon RemiBardon self-assigned this Dec 13, 2024
@RemiBardon RemiBardon changed the title chore: Add axum as a dependency Migrate from Rocket to Axum Dec 13, 2024
Base automatically changed from workspace-integration-tests to master December 14, 2024 10:53
RemiBardon added a commit that referenced this pull request Dec 18, 2024
`redocly lint` would raise an error and it would have been a problem when [migrating to Axum](#95) so it was a good time to do it.

Breaking changes:

- `GET /v1/invitations/{invitationIdOrToken}` was split in two: `GET /v1/invitations/{invitationId}` and `GET /v1/invitation-tokens/{token}/details`
  - `GET /v1/invitations/{invitationId}` don't need any query parameter (like before)
  - `GET /v1/invitation-tokens/{token}/details` expects `token_type=(accept|reject)` (like before)
- `PUT /v1/invitations/{token}/accept` is now `/v1/invitation-tokens/{token}/accept`
- `PUT /v1/invitations/{token}/reject` is now `/v1/invitation-tokens/{token}/reject`
RemiBardon added a commit that referenced this pull request Dec 19, 2024
`redocly lint` would raise an error and it would have been a problem when [migrating to Axum](#95) so it was a good time to do it.

Breaking changes:

- `GET /v1/invitations/{invitationIdOrToken}` was split in two: `GET /v1/invitations/{invitationId}` and `GET /v1/invitation-tokens/{token}/details`
  - `GET /v1/invitations/{invitationId}` don't need any query parameter (like before)
  - `GET /v1/invitation-tokens/{token}/details` expects `token_type=(accept|reject)` (like before)
- `PUT /v1/invitations/{token}/accept` is now `/v1/invitation-tokens/{token}/accept`
- `PUT /v1/invitations/{token}/reject` is now `/v1/invitation-tokens/{token}/reject`
@RemiBardon RemiBardon marked this pull request as ready for review January 5, 2025 16:31
@RemiBardon RemiBardon merged commit 2785af1 into master Jan 5, 2025
8 checks passed
@RemiBardon RemiBardon deleted the axum branch January 5, 2025 16:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cleanup Refactors / cleans up the code enhancement New feature or request

Projects

Status: Done ✅

Development

Successfully merging this pull request may close these issues.

Re-implement databases.data.* config values from Rocket Make sure tracing is always imported where necessary

1 participant