Many records in one transaction

118 views
Skip to first unread message

Константин Комков

unread,
Feb 17, 2020, 1:09:57 AM2/17/20
to web2py-users
Hello! I do import timetables from templates. It's templates for all group on faculty. After import I have error or success with probability 50%.
Count of records to database is 3863 and it can be more for another faculties. I think that reason of error is time of answer from server. That time is too much.
What I need to do in that case? I don't have web2py ticket.

Clemens

unread,
Feb 17, 2020, 4:46:27 AM2/17/20
to web2py-users
Hello!

I guess that your mean by importing, reading data from the database. if so, without any further information I can only suggest the following workaround:
If your problem is a timeout while reading the database, this could be a solution.

Best regards
Clemens

Константин Комков

unread,
Feb 17, 2020, 7:20:02 AM2/17/20
to web2py-users
It's unique 3863 rows for insert to database.
Example of my template:
DC_WEEK  DC_DAY  DC_NUMBER  SUBGROUP  DC_TYPE  SUBJECT_ID  TEACHER_ID  CLASS_ROOM_ID  DC_QUEUE  LC_HOURS  SM_HOURS  LB_HOURS  FULL_NAME
      0       4          2         0        0     126 300      18 550             76         1        16        16         0  Экономическая теория                                                                    
      0       2          2         0        1     126 300      18 550            555         1        16        16         0  Экономическая теория                                                                    
      0       4          4         0        1     126 301      18 426            538         1        16        34         0  Морфология и физиология сельскохозяйственных животных                                   
      1       4          3         0        1     126 301      18 426            538         1        16        34         0  Морфология и физиология сельскохозяйственных животных                                   
      2       5          3         0        1     126 301      19 132            590         1        16        34         0  Морфология и физиология сельскохозяйственных животных                                   
      0       1          4         0        0     126 301      17 633             80         2        16        34         0  Морфология и физиология сельскохозяйственных животных                                   
      0       1          4         0        0     126 301      18 059             80         2        16        34         0  Морфология и физиология сельскохозяйственных животных                                   
      0       5          4         2        0     126 302      18 412            564         1        16        16         0  Основы ветеринарии и биотехника размножения животных                                    
      1       4          4         2        2     126 302      18 412          1 013         1        16        16         0  Основы ветеринарии и биотехника размножения животных                                    
      0       5          4         1        0     126 302      17 951            596         1        16        16         0  Основы ветеринарии и биотехника размножения животных                                    
      1       4          4         1        2     126 302      17 951            595         1        16        16         0  Основы ветеринарии и биотехника размножения животных                                    
      2       3          5         2        1     126 303      17 987            589         1        34        34         0  Производство продукции растениеводства                                                  
      2       3          5         1        1     126 303      18 090            588         1        34        34         0  Производство продукции растениеводства                                                  
      2       3          4         0        0     126 303      18 090            592         1        34        34         0  Производство продукции растениеводства                                                  
      0       2          3         0        0     126 306      17 776             76         1        16        34         0  Стандартизация и сертификация сельскохозяйственной продукции                            
      2       3          3         0        1     126 306      17 776            593         1        16        34         0  Стандартизация и сертификация сельскохозяйственной продукции                            
      0       1          3         0        0     126 313      19 158             82         1        16        34         0  Оборудование перерабатывающих производств                                               
      2       1          1         0        1     126 313      19 158            562         1        16        34         0  Оборудование перерабатывающих производств                                               
      0       5          2         0        0     126 315      18 116             77         1        16        16         0  Психология                                                                              
      1       5          2         0        1     126 315      18 116            585         1        16        16         0  Психология                                                                              
      2       3          2         0        1     126 355           0             98         1         0        64         0  Элективные курсы по физической культуре и спорту                                        
      2       5          1         0        1     126 355           0             98         1         0        64         0  Элективные курсы по физической культуре и спорту                                        
      0       4          1         0        0     126 363      17 943            593         2        16        16         0  Механизация и автоматизация технологических процессов растениеводства и животноводства  
      0       4          1         0        0     126 363      18 392            593         2        16        16         0  Механизация и автоматизация технологических процессов растениеводства и животноводства  
      1       2          2         0        1     126 363      17 943            587         2        16        16         0  Механизация и автоматизация технологических процессов растениеводства и животноводства  
      1       2          2         0        1     126 363      18 392            587         2        16        16         0  Механизация и автоматизация технологических процессов растениеводства и животноводства  
      2       2          1         0        0     126 364      19 203            559         1        34        18        16  Процессы и аппараты перерабатывающих производств                                        
      2       1          2         0        1     126 364      19 203            586         1        34        18        16  Процессы и аппараты перерабатывающих производств                                        
It's template of timetable for one group. Template of timetable is importing to timetable. I do circle for every day in semestr and if day is not Saturday or Sunday or holiday and count of hours for that subject > 0 I do insert to database. As a result I have about 400 or 500 rows for insert in one group. It's part of result of timetable (see picture).




21.png

Константин Комков

unread,
Feb 18, 2020, 12:33:31 PM2/18/20
to web2py-users
I can't solve that problem still. I have additional information also. Maximum count of unique rows for insert can be 25000, and before I need to delete maximum 25000 rows in database. Seems like it's IIS settings, becouse if I work with 5000 unique rows and Rocket server on local I don't have error. When I'm trying do that on IIS I have error. I think about executionTimeout in IIS config. By default that time is 110 seconds, but I have error after 60, 70 secons. If someone have assumptions share them, please. It's not normal situation becouse it is import of timetable, and if user will wait 5 or 10 minutes it is OK.

villas

unread,
Feb 22, 2020, 7:01:30 AM2/22/20
to web2py-users
You do not explain why you would need to delete and then insert 25K records to prepare a timetable. 
It seems that you are creating a temporary table and that is seldom the correct approach. 
  • If all the data is already available in the tables,  then you should be able to write SQL which only selects the rows you require.  Iterate those rows to produce your timetable.
  • If the select is taking too long,  then try using pure SQL using db.executesql().  Compare the times. Experiment and optimise the SQL.
  • If the select is still very slow even using pure SQL,  optimise your table schema and use indexes.
  • Avoid creating temporary tables! 


Константин Комков

unread,
Feb 24, 2020, 3:13:22 AM2/24/20
to web2py-users
Villas, I can explain why I need to delete many records. I have template of timetable (example upper in my post). There is templates for each group for each faculty in university. ~40 groups = 40 templates for each faculty.
When I do timetable I need to do next operations:
  • Select all active groups for faculty (1 query);
  • Select holidays from production calendar (directory table in database, 1 query);
  • Get template for each group (start cycle, no query becouse get from sessions);
  • Delete previous timetable becouse I don't know what is new in template and I don't know it is new template or old (~400 record);
  • Select all subjects, hours for subjects and schedule of educational process in a group (1 procedure);
  • Find period of teoretical occupations in a schedule;
  • There is two check of template and correct it if it is necessary (updating rule in template ~2 rows);
  • Insert lesson to database in cycle start with first date of teoretical occupations if date corresponds all rules in a template and not holidays and hours for a subject > 0 (~400 record);
  • Create report about group (see picture).
As result we have 40 * 400 = 16000 rows for deleting and 16000 rows for inserting. But there is fuculty with 56 groups then ~22400 rows for delete and insert. Becouse I told 25000 rows it is max.
Let's talk about IIS settings, becouse if I do that on Rocket server all work. But on IIS without deleting at all I have problem with inserting 5000 rows.
Thank you for attention!
1.png

villas

unread,
Feb 28, 2020, 4:29:21 PM2/28/20
to web2py-users
It seems this is a complex routine and I can only talk in general terms.
Perhaps you do need a temporary table, and it should not be a problem to create one.
However, it still seems strange that you think the problem might be the webserver rather than the DB. 
I do not know how to help with your IIS settings,  but webservers can timeout with long processes so I would look for a timeout setting in the configuration files.
Sorry I am not helping you much.  Best wishes.

Carlos Correia

unread,
Mar 2, 2020, 11:17:44 AM3/2/20
to web...@googlegroups.com
Às 08:13 de 24/02/20, Константин Комков escreveu:

Hi,

I would suggest you try to optimize all those queries in the database first in order to optimize the process. In any case, it surely is a database issue and not a Web2py one.

Regards,

Carlos Correia
=========================
MEMÓRIA PERSISTENTE
GSM:  917 157 146
e-mail: ge...@memoriapersistente.pt
URL: http://www.memoriapersistente.pt
XMPP (Jabber): car...@memoriapersistente.pt
GnuPG: wwwkeys.eu.pgp.net
Reply all
Reply to author
Forward
0 new messages