1

After 5s Azure Cosmos DB isn't allowing you to perform any database operations within a stored procedure anymore.

Two questions:

a) Am I allowed to perform other operations that take longer than 5s? E.g., some postprocessing of queried data and then return to the user later on?

b) Do I pay RUs only for the actual database operations within a stored procedure or also for some kind of "JavaScript execution time" as well?

D.R.
  • 20,268
  • 21
  • 102
  • 205
  • Are you using stored procs for long running queries? Generally it is recommended to not use stored procedures for queries but more for large batch writes. Here is an example [bounded execution for stored procs](https://learn.microsoft.com/en-us/azure/cosmos-db/how-to-write-stored-procedures-triggers-udfs#bounded-execution). – Mark Brown Apr 06 '20 at 19:22
  • Hi,any updates here? – Jay Gong Apr 13 '20 at 01:32
  • @MarkBrown: No, I'm asking from a theoretical standpoint. – D.R. Apr 13 '20 at 15:41

1 Answers1

0

a) Am I allowed to perform other operations that take longer than 5s? E.g., some postprocessing of queried data and then return to the user later on?

I think the 5s limitation can't be breached so far.As @Mark mentioned in the comment and follow my previous case:Delete Documents from Cosmos using Query without Partition Key Specification procedures are best suited for operations that are write-heavy,not read or delete heavy,even long time execution of API.

b) Do I pay RUs only for the actual database operations within a stored procedure or also for some kind of "JavaScript execution time" as well?

Based on the Cosmos DB pricing page, cost is only affected by Storage Capacity and throughput.In fact, any operations are based on the REST API,even for JS Server features here. So,i think you don't need to pay more for JS execution time.


Update Answer:

If i don't misunderstanding here,you access cosmos db for a single query in the SP and then do more workloads which have nothing with cosmos db. You just wonder if this scenario costs you more,in other words,you can use the most of the resources allocated to you by SP.

Per my research,no any special billing policy for SP.So, everything is determined by RUs.For your scenario,maybe you could calculate RUs of SP with or without custom code to compare them.

StoredProcedureResponse response = documentClient.executeStoredProcedure(collectionLink + "/sprocs/test", requestOptions, null);
System.out.println(response.getRequestCharge());
Jay Gong
  • 23,163
  • 2
  • 27
  • 32
  • You say "the 5s limitation can't be breached so far", however, to my knowledge it is only checked when performing a database operation. So when I don't perform any actual database computations but do some heavy lifting JS operations outside of my hardware on Azure CosmosDB - what's stopping me? Is there a hard limit after which my query is killed off? 5s isn't it, because after 5s it just starts to return errors when I perform database operations but the script seems to run along. – D.R. Apr 13 '20 at 15:42
  • @D.R. Sorry, i don't understand your scenario.You mean you have no operations on cosmos db in your js SP script?Then why use cosmos db SP? Maybe Azure Function is more suitable. – Jay Gong Apr 14 '20 at 01:20
  • I have a single short query in the beginning, but afterwards I just want to make use of the free (?) JS computation power there instead of performing the same work on my VMs. – D.R. Apr 14 '20 at 06:21
  • Not yet, will check this out on the weekend. – D.R. Apr 16 '20 at 06:38
  • @D.R. Sure,sure. Please take your time. – Jay Gong Apr 16 '20 at 08:33