-
-
Notifications
You must be signed in to change notification settings - Fork 67
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
InvalidWorkerCreation: Edge functions cannot handle concurrent requests #408
Comments
I have encountered a similar issue when trying to call an edge function multiple times concurrently. In my case, making a lot of calls resulted in I feel like other serverless functions can handle concurrent requests with ease, yet edge functions can't even handle 50? Is Supabase not equipped to handle more than 50 concurrent requests? It seems as if the edge function is attempting to create a worker for every single request rather than queuing or using some implementation to resolve concurrency on a large scale. |
Hello @nathanaeng and @ethan-dinh I am not a member of the Supabase team that works on Supabase Edge Functions, but as the edge runtime maintainer, I'm sorry I didn't meet your expectations 😞 With the user script code and bash script you posted in the description and assuming you're using default edge runtime policy settings in supabase/cli then, I can explain why the edge runtime is showing such low request throughput. The edge runtime has three main scheduling policies(per_worker, per_request, oneshot) for workers, and for developers convenience, supabase/cli defaults to whichever of these scheduling policies is not used by Supabase Edge Functions. (aka. oneshot policy) Unlike the other policies, the If you change the policy, I think you'll probably get a different result. I was able to reproduce your issue exactly locally on the Of course, my experience doesn't guarantee that you won't have the same issue with Supabase Edge Functions. Today, I came across an author on Reddit discussing this same topic, and it seemed that the author was also experiencing these issues with Supabase Edge Functions. My expectation is that these issues should be handled well by the I have opened PR-382 to better handle this situation, and once this is merged, they will be able to implement more specific request scheduling on top of the per_worker policy, which I believe will mitigate these issues. I will put this on my watchlist and will let you guys know if there are any updates on this issue in the future. Have a great day! |
Thanks for the detailed response! Yep, I have looked into the per_worker policy and while it might work fine for the simple edge function I provided above, it was failing for a more complex edge function that performs a read, text embedding, and write. I can't recall how many concurrent requests it was able to handle, it might have been a bit more than oneshot but it was still underwhelming unfortunately. Additionally, I was able to replicate this error on my remote DB (Supabase hosted) which makes me think it's not just a local hosting issue. Thanks for helping though! |
Hello @nyannyacha , thanks for your detailed response. As someone who self-hosts edge functions separately (not together with supabase docker compose), where should I go about changing the policies you mentioned? I suspect it is in the main function index.ts with forceCreate = true or false but I am not sure and I am still getting those 502 errors after 30-50 concurrent requests even with the forceCreate = false option. Can you help me figure out some other configurations in the main function where I can optimize for better scaling performance? I am running it in multiple replicas in my K8s deployment but the replicas still cannot pass the load test because the edge runtime container stop responding to requests and return 502 with the above error after a few concurrent requests. |
Can confirm I'm experiencing the same thing: working on running a data-intensive edge function and running into this along with some request hanging locally. I also have a low-bandwidth bottom of the line MacBook for what it's worth, but just confirming it's replicating on my end. |
i can also that i'm experiencing that, i'm trying it even with a small project after a couple requests with my colleagues saying : Can't reach database server at |
Bug report
Describe the bug
Making concurrent requests to a Supabase edge function will result in InvalidWorkerCreation errors or 502 errors.
To Reproduce
Steps to reproduce the behavior, please provide code snippets or a repository:
supabase functions new test_concurrency
. Here is an example of a function I have (I realize the createClient is not used):Run
supabase functions serve
In a new terminal tab, execute this bash script which sends 200 concurrent requests, replacing
SERVICE_ROLE_KEY
with your service role key:supabase functions serve
tab:with the following error message on the tab that executes the test script:
Expected behavior
I would expect the edge function to be able to handle concurrent requests to this degree.
Screenshots
System information
Additional context
From my understanding, edge functions can be used to serve API routes, and in a production application it is perfectly reasonable that you would have 200 users hit the same endpoint at the same time. This example uses an edge function with minimal computations. If you add database reads, a text embedding call using
Supabase.ai gte-small
, and a database write, it can handle even fewer concurrent requests (around 40 from my testing). I noticed this issue at first because I wanted to generate text embeddings on seed data consisting of only 40 users (which gets triggered on inserts to a table) but it failed to work for every user.I'm not entirely sure how edge functions work, maybe a worker is being re-used to handle multiple requests and then a CPU limit or similar is hit, resulting in failures - but I thought the idea of edge functions is to scale up with requests and a mere 200 requests is nothing.
At first I thought that this could be a problem with local Supabase running in Docker, but I also confirmed this occurs on a remote Supabase project (ran using Supabase to host) - where I get 502 errors after the first 50-100 requests or so.
The text was updated successfully, but these errors were encountered: