[eluser]ciuser99[/eluser]
So here is the logic behind the code. There are two processes that can run at the same time. One is the update process where the tables are truncated and new data is bulk inserted. The other is a page view, which queries whichever set of tables that are not being currently updated by the bulk insert process.
Bulk Insert
-----------
Switch database flag in database to table set 2 (live site will pull data from table set 2 (b) while table set 1 (a) is being bulk updated)
Truncate table a1
Truncate table a2
Truncate table a3
Truncate table a4
Loop
Grab 100 records from JSON API feed from external site (the feed allows a max of 100 records to be downloaded at a time, so this loops until all records are downloaded)
Attach to SQL INSERT query string
Loop (through array of items)
Attach to a different SQL INSERT query string
End Loop
End Loop
Execute 1st SQL query string -> inserts data into table a1
Execute 2nd SQL query string -> inserts data into table a2
Loop
Grab 100 records from JSON API feed from external site (the feed allows a max of 100 records to be downloaded at a time, so this loops until all records are downloaded)
Attach to SQL INSERT query string
Loop (through array of items)
Attach to a different SQL INSERT query string
End Loop
End Loop
Execute 1st SQL query string -> inserts data into table a3
Execute 2nd SQL query string -> inserts data into table a4
Switch database flag in database to table set 1 (live site will pull data from table set 1 (a) while table set 2 (b) is being bulk updated)
Truncate table b1
Truncate table b2
Truncate table b3
Truncate table b4
Loop
Grab 100 records from JSON API feed from external site (the feed allows a max of 100 records to be downloaded at a time, so this loops until all records are downloaded)
Attach to SQL INSERT query string
Loop (through array of items)
Attach to a different SQL INSERT query string
End Loop
End Loop
Execute 1st SQL query string -> inserts data into table b1
Execute 2nd SQL query string -> inserts data into table b2
Loop
Grab 100 records from JSON API feed from external site (the feed allows a max of 100 records to be downloaded at a time, so this loops until all records are downloaded)
Attach to SQL INSERT query string
Loop (through array of items)
Attach to a different SQL INSERT query string
End Loop
End Loop
Execute 1st SQL query string -> inserts data into table b3
Execute 2nd SQL query string -> inserts data into table b4
Page View
----------
Check flag to see which database to use
Make multiple queries to table set a or table set b to display data on page
I spoke with the database administrator and the SQL Server did not show any heavy strain on CPU or memory resources during this bulk insert process. Like I said before, I tried running a simple script that grabs all of table a1 and displays while the bulk insert is running and it runs fine without stalling. But Any page running on Code Igniter stalls until the entire bulk insert process is completed. I even checked the database directly to make sure that the database flag/selected database was the correct one as the bulk insert was occurring. This was working fine. So I am trying to figure out what could be the source of this issue. The stall happens somewhere between the controller constructor is being processed and the index() function of the controller is being processed.
I want the pages to display without stalling as the database is being bulk inserted into.