Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Fast demands gives err 500
#11
(06-04-2019, 01:48 AM)Alexandre Machado Wrote:
(06-03-2019, 12:29 PM)ib elfving Wrote: I am not using any global IW-variables. My database (except for the firedac database connection) is accessed through variables in the usersession, so this should isolate the individual session data from each other, but I am using an ordinary delphi-unit for business routines. I will check this for variables that might cause the conflict, maybe try to move the database connection to the usersession instead to see if this makes a change.

Still - is it possible in an easy way to delay each call to the handler - e.g. 10 request arrives to the SA within 1 sec, but is "delay" so that each request starts with a delay of for instance 1 sec. (request 1 start at 1 sec, request 2 starts at 2 sec .. request 10 start at 10 sec)

You can serialize them using a critical section or a semaphore, but I find it weird that you want (or need) to do so. As long as you are not sharing things between threads you should be able to run "N" content handlers in  parallel with no issues.
Hi,
Just to answer some of the above questions.

The iw is an ultimate version.

The reason for asking for an easy delay method is that the application is in production, and i have daily complaints from the staff concerning this issue. My thoughts was to implement a fast, but wrong, solution in order to decrease this, in order to give me some time and peace to inspect and re-implement my business logic unit, as I am sure that the problem is in my use of the database units. I have been checking the database documentation, and I can see several possibilities that I need to check (fdmanager, pooled connections etc.) - This is not an "over night" task for me, as the application is rather complex (6 years old).

Regards Ib
Reply
#12
A quick and dirty way to implement it would be:

- Create a unit where you have a shared (global) variable which holds a TCriticalSection (let's name it HandlersCS).
- Create a TCriticalSection in unit initialization. Destroy it in unit finalization.
- In your TContentHandler.Execute() method do this:

HandlersCS.Enter;
try
// Do your thing here
finally
HandlersCS.Leave;
end;

All your current logic should be between Enter..Leave above.

This will effectively serialize all calls using that content handler class
Reply
#13
Have in mind that this is an emergency fix so you have time to find where the problem really is. Do *NOT* leave it running like this. Adding critical sections like that in multithreaded applications can lead to unpredictable side effects, the worse is a deadlock which would require you to restart your application.
Reply
#14
(06-04-2019, 03:51 AM)Alexandre Machado Wrote: Have in mind that this is an emergency fix so you have time to find where the problem really is. Do *NOT* leave it running like this. Adding critical sections like that in multithreaded applications can lead to unpredictable side effects, the worse is a deadlock which would require you to restart your application.

You just made my day. I have been programming in delphi for many years, but this one is new to me and will give me time to do the work correctly. Thank you for the advice.

Addendum: Preliminary test in the production was positive. Thanks God (and Alexander) - Finally time to do some proper programming  Big Grin
regards ib
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)