How to increase the performance of programs on .net 4.5 uses 50,000 queries to the database?

Task: write a program consider many different statistics, about 50 000 queries to the database in a particularly perverse form, and outputs them for viewing in the program using the FlowDocumentReader in the form of tables.
Workstation configuration: Intel core i5 2.4 GHz, 8 GB RAM, 256 GB SSD (fluent 60). I use MS SQLServer Express 2012, Windows 10 pro, the program itself is on .net 4.5 WPF.
In the formation of the first hundreds of requests began brake - on ssd the result of the query is performed for about 5 seconds (previously was 1 second), I think it will be worse. Here is the code to generate each line:
// String 8.2
 this.FormN.RowGroups[0].Rows.Add(new TableRow());
 this.FormN.RowGroups[0].Rows[70].FontSize = 14;
 this.FormN.RowGroups[0].Rows[70].Cells.Add(new TableCell(new Paragraph(new Run(""))));
 this.FormN.RowGroups[0].Rows[70].Cells.Add(new TableCell(new Paragraph(new Run("8.2"))));
 this.FormN.RowGroups[0].Rows[70].Cells.Add(new TableCell(new Paragraph(new Run("H16"))));
 this.FormN.RowGroups[0].Rows[70].Cells.Add(new TableCell(new Paragraph(new Run(CF12.Str8_2_4()))));
 this.FormN.RowGroups[0].Rows[70].Cells.Add(new TableCell(new Paragraph(new Run(CF12.Str8_2_5()))));
 this.FormN.RowGroups[0].Rows[70].Cells.Add(new TableCell(new Paragraph(new Run(CF12.Str8_2_6()))));
 this.FormN.RowGroups[0].Rows[70].Cells.Add(new TableCell(new Paragraph(new Run("8"))));
 this.FormN.RowGroups[0].Rows[70].Cells.Add(new TableCell(new Paragraph(new Run("9"))));
 this.FormN.RowGroups[0].Rows[70].Cells.Add(new TableCell(new Paragraph(new Run("10"))));
 this.FormN.RowGroups[0].Rows[70].Cells.Add(new TableCell(new Paragraph(new Run("11"))));
 this.FormN.RowGroups[0].Rows[70].Cells.Add(new TableCell(new Paragraph(new Run("14"))));
 this.FormN.RowGroups[0].Rows[70].Cells.Add(new TableCell(new Paragraph(new Run("15"))));
 this.FormN.RowGroups[0].Rows[70].Cells.Add(new TableCell(new Paragraph(new Run("16"))));


and then not all columns are filled. Methods that return the result of each cell, is sql queries.
How can I accelerate all this construction? Maybe I'm wrong, form a line and there is an easier way to display this table? Whether to make asynchronous requests or it will not affect the work? This is my first serious programming.
July 2nd 19 at 18:18
3 answers
July 2nd 19 at 18:20
Solution
I think that:
  • without asynchronous queries are not necessary. At least in a separate thread(s). (although if there are slices, optional)
  • There will be extra DB optimization. Statistics update triggers/hranimye if not frequently updated (from an hour), if more then keep slice and recalculate periodically.
  • Don't forget about indexes, denormalization sometimes saves, but the base will podrozujac.
  • Optimize queries, build execution plans, see bottlenecks.


The principle of acceleration is always the same, or you need to consider in advance, or somewhere to store part of the calculation is memory, whether it is operative or drive...
PS: listen to , writes business.
July 2nd 19 at 18:22
Solution
Obviously.
You yourself have already given yourself the answer to the question.
To do all this in a SINGLE query.
It will speed up radically.

And read cache to the maximum in the RAM.
If the user one is a RAM in the app.

If the set of users to get a separate server for caching.
For Instance, Tarantool. Look for it first.
If not Tarantool'cache and data then to download from SQL, then pour on a copy of the Tarantool cached for later reading.
When changes are made to duplicate for Tarantool.
July 2nd 19 at 18:24
The author, from the point of view of collection of statistics using complex queries and even entire chains, no need to change the program and the type of database you are using, the problem is relational in that they support the integrity of the data structures, they just lack flexibility. For statistics I would take a graph database.

PS
Do you have enough RAM lift data back, the DB itself will take care of resetting the changes to disk.

Find more questions by tags SQLC#.NET