-
-
Notifications
You must be signed in to change notification settings - Fork 43
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
Optimize activity delivery for large audiences #220
Comments
This sounds reasonable to me. Though, folks will possibly still face issues if they need to vary payload per recipient. |
Perhaps instead of modifying So like if the number recipients is low, it just directly enqueues the sends to each, if it's past X threshold, it chunks and enqueues in batches |
@ThisIsMissEm Thank you for the feedback! You raise a valid concern about payloads that need to vary per recipient. Building on your suggestion, what if we add a sendActivity(
sender,
recipients,
activity,
{
fanout: "auto" | "skip" | "force",
// other existing options...
}
) Where:
This would preserve backward compatibility while giving developers explicit control when needed. The system would optimize for the common case by default, but provide an escape hatch for scenarios requiring per-recipient customization. What do you think? |
I'm not a fan of overloading the |
Arguably, |
I appreciate the API design perspective! Your point about method naming clearly reflecting behavior is excellent. For Fedify 1.5.0, we need to balance immediate performance improvements with backward compatibility. The Here's what we're thinking:
This gives us the performance gains we need now while setting up for a cleaner API design in the future. |
I think you could retain, but mark as deprecated the |
Yeah, we're making it default to Another question I've been considering: If we were to introduce an Currently,
Option 1 is cleaner from an API perspective (the method does what its name implies or fails), but option 2 might be more practical for development environments where queues aren't always configured. |
Ah, okay. I'd probably suggest not adding the option & just making it always use auto mode in that case. For testing you probably just want to mock sendActivity entirely and just assert things about the arguments passed to it For a new API, I think error when no queue configured is the right way to go |
Current design
Currently, when
Context.sendActivity()
is called, Fedify creates separate queue entries for each recipient's inbox. This design has been intentional to achieve the following benefits:The core principle is to prioritize delivery reliability and speed in the face of the fediverse's unpredictable server behaviors and response times.
Current limitations
While this approach works well for activities with a small to moderate number of recipients, it shows significant performance issues when delivering to large audiences:
Web request latency: When an activity is sent to many recipients (e.g., a user with thousands of followers), the
sendActivity()
method takes a long time to return because it must enqueue separate messages for each recipient.Memory consumption: Each queue message contains a copy of the entire activity payload, leading to significant data duplication when delivering to large audiences.
Queue overhead: Managing thousands of individual queue entries for a single activity creates unnecessary overhead for the message queue system.
UI responsiveness: The long processing time affects user experience, as the UI might appear frozen while enqueueing all the individual messages.
Proposed design
To address these limitations while preserving the benefits of the current design, we propose a two-stage queuing approach:
Fast initial enqueueing:
sendActivity()
is called, create a single queue entry containing:sendActivity()
to return promptlyBackground fan-out processing:
This approach effectively moves the fan-out process from the web request handler to a background worker.
Expected benefits
Improved response times:
sendActivity()
will return much faster, particularly for high-volume deliveries.Better resource utilization: Memory consumption will be significantly reduced by avoiding unnecessary duplication of the activity payload.
Enhanced user experience: Web UI responsiveness will improve as federated publishing actions complete more quickly.
Preserved reliability: We maintain the independent delivery and retry mechanisms that make the current system robust.
Scalability: This design better accommodates accounts with large follower bases or posts with extensive distribution lists.
Implementation considerations
Backward compatibility: Ensure all existing consumer code continues to work with this implementation change.
Would appreciate feedback on this approach before we begin implementation. Our goal is to make this optimization transparent to users while significantly improving performance for high-volume scenarios.
The text was updated successfully, but these errors were encountered: