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

Performance & Threading for AuditLog create_event #335

Open
danielduan opened this issue Nov 19, 2024 · 0 comments
Open

Performance & Threading for AuditLog create_event #335

danielduan opened this issue Nov 19, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@danielduan
Copy link

danielduan commented Nov 19, 2024

The use case for this API call seems to revolve around recording that a resource has been accessed by a user. The current implementation of WorkOS::AuditLogs.create_event blocks the execution thread and delays the response until the audit trail has been logged.

It would be nice to have a create_event_async where the SDK could perform the call on a separate thread, or to default that API to async. This would shave off 200-500ms off our backend APIs.

We will try to mitigate this on our end and see if we can manage the threading. Maybe this would be good to mention in the documentation as well in lieu of any SDK changes.

I'm also very curious why this API call performs so poorly. We are seeing an average of 240ms on this with p95 of 450ms.
Screenshot 2024-11-19 at 5 18 44 PM

event = {
      action: action,
      occurred_at: Time.now.utc.iso8601,
      actor: {
        id: workos_user,
        type: "user"
      },
      context: {
        location: request.remote_ip,
        user_agent: request.user_agent
      },
      targets: targets
    }


WorkOS::AuditLogs.create_event(
      organization: workos_org_id,
      event: event

wrapping the actual API call in a Thread.new seems to at least take it of the main execution thread so it's not blocking the render:

Thread.new do
      WorkOS::AuditLogs.create_event(
        organization: workos_org_id,
        event: event
      )
end
@danielduan danielduan changed the title Threading for AuditLog create_event Performance & Threading for AuditLog create_event Nov 19, 2024
@PaulAsjes PaulAsjes added the enhancement New feature or request label Nov 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Development

No branches or pull requests

2 participants