-
-
Notifications
You must be signed in to change notification settings - Fork 889
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
Improve api response times by doing send_activity asynchronously #3493
Conversation
f93e150
to
edda90c
Compare
edda90c
to
a83b8d8
Compare
Its a good idea. Unfortunately it breaks federation tests ( On a side note, we also need to get rid of the SendActivity and Perform traits. The latter were only necessary for websocket. Then we can switch to normal actix-web handler methods which are much more flexible. But so far I couldnt think of a good way to do that, because api methods need to call apub send methods which are in an independent, parallel crate. Maybe some kind of message queue would work, although it seems wrong to use a message queue inside another. Btw you can also move the webmention send to a background thread along with this. |
Why not just move the apub sends into the API functions? That's more explicit anyway. |
Could probably be fixed by a wait / sleep in the api test code. |
Sorry, i don't understand exactly what you mean? You mean get rid of the SendActivity trait and move the content of send_activity into what's currently the Perform impls? |
Yep. |
ok well makes sense, but i think it should maybe be a different PR? seems somewhat orthogonal |
Apub and api crates are currently completely independent, meaning code in api crates cant access any code in the apub crate. This means that both crates can be compiled in parallel which speeds up the build considerably.
I would hate to do this because its much more fragile and slower. |
I'm looking for a clean way to fix the fed tests but I'm not sure. should i:
Edit: I'll solve it by adding a env var LEMMY_SYNCHRONOUS_FEDERATION that defaults to cfg!(debug_assertions). |
I've fixed the tests hopefully. No idea why CI just suddenly seems to cancel now. |
Looks good, thanks! |
* do send_activity after http response * move to util function * format * fix prometheus * make synchronous federation configurable * cargo fmt * empty * empty --------- Co-authored-by: Dessalines <[email protected]>
…myNet#3493) * do send_activity after http response * move to util function * format * fix prometheus * make synchronous federation configurable * cargo fmt * empty * empty --------- Co-authored-by: Dessalines <[email protected]>
* Fix #3366: API does return plain HTML errors * Fix Clippy errors * Improve api response times by doing send_activity asynchronously (#3493) * do send_activity after http response * move to util function * format * fix prometheus * make synchronous federation configurable * cargo fmt * empty * empty --------- Co-authored-by: Dessalines <[email protected]> * Updating `login.rs` with generic `incorrect_login` response. (#3549) * Adding v0.18.1 and v0.18.0 release notes. (#3530) * Update RELEASES.md (#3556) added instruction to find the location of your docker directory (especially useful for those who used ansible since they never had to setup docker manually) * Use async email sender (#3554) * Upgrade all dependencies (#3526) * Upgrade all dependencies * as base64 * Adding phiresky to codeowners. (#3576) * Error enum fixed (#3487) * Create error type enum * Replace magic string slices with LemmyErrorTypes * Remove unused enum * Add rename snake case to error enum * Rename functions * clippy * Fix merge errors * Serialize in PascalCase instead of snake_case * Revert src/lib * Add serialization tests * Update translations * Fix compilation error in test * Fix another compilation error * Add code for generating typescript types * Various fixes to avoid breaking api * impl From<LemmyErrorType> for LemmyError * with_lemmy_type * trigger ci --------- Co-authored-by: SleeplessOne1917 <[email protected]> * Only update site_aggregates for local site (#3516) * Fix #3501 - Fix aggregation counts for elements removed and deleted (#3543) Two bugs were found and fixed: - previously elements removal and deletion were counted as two separate disappearances - removing comments did not affect post aggregations * Use LemmyErrorType also make error_type compulsory * Add missing import for jsonify_plain_text_errors * Fix formatting * Trying to make woodpecker run again --------- Co-authored-by: phiresky <[email protected]> Co-authored-by: Dessalines <[email protected]> Co-authored-by: rosenjcb <[email protected]> Co-authored-by: nixoye <[email protected]> Co-authored-by: dullbananas <[email protected]> Co-authored-by: Nutomic <[email protected]> Co-authored-by: SleeplessOne1917 <[email protected]> Co-authored-by: Sander Saarend <[email protected]> Co-authored-by: Piotr Juszczyk <[email protected]>
Right now, all API responses (esp. create comment, like, etc) wait for send_activity to complete before returning to the caller. The API response though is already known before this, so it makes sense to do it afterwards, whenever the scheduler has time. send_activity can be very expensive because it has to collect all the interested parties, fetch more rows from db, insert a row into activities, parse a pem private key, and loop through all inboxes in order to schedule the outgoing tasks.
This does change the semantics a bit because errors in send_activity will not propagate to the HTTP caller. I'm not sure if this is required somewhere though. It's kind of not great anyways though, since if send_activity fails, it will be shown to the user as a failed action even though ::perform() succeded and returned a response (that is lost in the current version).
This does not decrease the total load, but it should increase responsiveness. It also requires one clone on responses, but most responses seem to be tiny.