I want to create a cloud function with EXACT 1 INSTANCE ALWAYS...
I dont mind if some users get http 429, 500 or any crazy error code. But I do want to have always max one function online.
Google says that case functions tryes to escaolanate over the max-instances it will throw http 429 to the user... but that is FALSE.
I've doing plent of tests and always it get escalonate up when it reaches some request peak.... So since google ins't able to manage their own created parameters i would like to do by myself.
Is there any way i can get the number of active instances of a specific cloud function? this way i can check if the instance is higher than 1 and drop all requests bymyself
=================UPDATE==================
I've been asked why I want to ensure only single instance... Usually I dont comment archtecture decisions but i will try explain this one.
I don't like the way Firebase Realtime Database handle transactions, is inneficient and might lead to an unnecessary traffic. I've other questions here regarding this topic Android Firebase transaction having a simple counter problem and due this problem I thought is much easier use Cloud Functions as a State aware backeend (although I know it was clearly desingned to not be)
So I create a function that during warm up loads a branch from firebase with few nodes (each node being a counter) into a field...
Everytime a client needs to touch one of the counters it will call my function and, as it is loaded in memory and single threaded, the function will do atomically it and return http 200
(as simple and fast as possible)...
My client was built to the possibility of receiving a http 429
in which case it will wait a random amount of time and retry (untill sucess)
From time to time the function will synchronize with the database just to garantee things are fine. And as the function is now the only entity touching this branch of the database it is garanted to be incorrupt
I've deployed this function a few days ago and according to the dashboard it takes 100ms to reply with the peak of 600ms. so it is absolutelly fine for my standards, BUUUUUUT google is automatically scalonating it to peak of 5 instances... what breaks the integrity of the counters.