-1

Here's the test scenario, I have multiple asynchronous requests in a JavaScript Application that:

  1. creates an object and saves it in the database.
  2. queries that object and make changes to it and saves it to the database (this step is done 2 or 3 times to add new items to the object)

steps 1 and 2 are repeated for every new object, for a long test scenario.

Upon investigation, it turns out some selects and inserts are taking up to 11 seconds, and more over time, which is probably expected when you are doing that many inserts for the same table, and each insert has to wait for the other one to be finished.

My question is, how to mitigate this issue or maybe even get rid of it without losing its asynchronous ability?

I know a multi-value insert is much faster than a single one, but how would you do such a thing in an asynchronous application?

Gabriel
  • 19
  • 3
  • If you had searched for questions with the similar topic on SO. You shude've known that the question is ambiguous. The DBMS only questions do start long discussions. And this one mixes in some async data transfer. – user14063792468 Aug 11 '22 at 01:22

1 Answers1

1

you might want to refactor how you are doing things. instead of inserting one at a time post an array of objects to your backend and then insert them all at once. something like

https://livesql.oracle.com/apex/livesql/file/content_BM1LJQ87M5CNIOKPOWPV6ZGR3.html

INSERT INTO people (person_id, given_name, family_name, title) 
  WITH names AS ( 
    SELECT 4, 'Ruth',     'Fox',      'Mrs'    FROM dual UNION ALL 
    SELECT 5, 'Isabelle', 'Squirrel', 'Miss'   FROM dual UNION ALL 
    SELECT 6, 'Justin',   'Frog',     'Master' FROM dual UNION ALL 
    SELECT 7, 'Lisa',     'Owl',      'Dr'     FROM dual 
  ) 
  SELECT * FROM names

you might also want to look into the merge statement it can update and insert into a single table with one statement

Bryan Dellinger
  • 4,724
  • 7
  • 33
  • 79