Skip to content

Commit

Permalink
more performance / validation time out issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Grahame Grieve committed Sep 24, 2024
1 parent 25c68bc commit 61ec58f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 17 deletions.
41 changes: 25 additions & 16 deletions library/fhir/fhir_tx.pas
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ TTerminologyOperationContext = class (TFslObject)
FContexts : TStringList;
FLangList : THTTPLanguageList;
FI18n : TI18nSupport;
FDeadTime : Cardinal;
FTimeLimit : Cardinal;
FNotes : TStringList;
FOwnsNotes : boolean;
FOnGetCurrentRequestCount: TGetCurrentRequestCountEvent;
public
constructor Create(i18n : TI18nSupport; id : String; langList : THTTPLanguageList; deadTime : cardinal; getRequestCount : TGetCurrentRequestCountEvent);
constructor Create(i18n : TI18nSupport; id : String; langList : THTTPLanguageList; timeLimit : cardinal; getRequestCount : TGetCurrentRequestCountEvent);
destructor Destroy; override;

property reqId : String read FId;
Expand Down Expand Up @@ -246,7 +246,7 @@ implementation

{ TTerminologyOperationContext }

constructor TTerminologyOperationContext.Create(i18n: TI18nSupport; id : String; langList : THTTPLanguageList; deadTime : cardinal; getRequestCount : TGetCurrentRequestCountEvent);
constructor TTerminologyOperationContext.Create(i18n: TI18nSupport; id : String; langList : THTTPLanguageList; timeLimit : cardinal; getRequestCount : TGetCurrentRequestCountEvent);
begin
inherited create;
FI18n := i18n;
Expand All @@ -255,7 +255,7 @@ constructor TTerminologyOperationContext.Create(i18n: TI18nSupport; id : String;
FContexts := TStringList.create;
FStartTime := GetTickCount64;
FOnGetCurrentRequestCount := getRequestCount;
FDeadTime := deadTime;
FTimeLimit := timeLimit;
FNotes := TStringList.create;
FOwnsNotes := true;
end;
Expand All @@ -272,7 +272,7 @@ destructor TTerminologyOperationContext.Destroy;

function TTerminologyOperationContext.copy: TTerminologyOperationContext;
begin
result := TTerminologyOperationContext.create(FI18n.link, FId, FLangList.link, FDeadTime, OnGetCurrentRequestCount);
result := TTerminologyOperationContext.create(FI18n.link, FId, FLangList.link, FTimeLimit, OnGetCurrentRequestCount);
result.FContexts.assign(FContexts);
result.FStartTime := FStartTime;
result.FNotes.free;
Expand All @@ -282,19 +282,27 @@ function TTerminologyOperationContext.copy: TTerminologyOperationContext;

function TTerminologyOperationContext.deadCheck(var time : integer): boolean;
var
dt : UInt64;
timeToDie : UInt64;
rq : integer;
begin
time := FDeadTime;
if UnderDebugger then
exit(false);
time := FTimeLimit;
//if UnderDebugger then
// exit(false);

// once timelimit is hit, living on borrowed time until request counts build
if assigned(OnGetCurrentRequestCount) and (OnGetCurrentRequestCount > 10) then
time := time * 5;

dt := FStartTime + (time * 1000);
result := GetTickCount64 > dt;
timeToDie := FStartTime + (time * 1000);
if (GetTickCount64 > timeToDie) then
exit(true)
else
begin
if assigned(OnGetCurrentRequestCount) and (OnGetCurrentRequestCount < 10) then
begin
// once timelimit is hit, living on borrowed time until request counts build
time := time + (time div 2);
// but we only give it so much time
end;
timeToDie := FStartTime + (time * 1000);
result := GetTickCount64 > timeToDie;
end;
end;

procedure TTerminologyOperationContext.seeContext(vurl: String);
Expand Down Expand Up @@ -322,7 +330,7 @@ procedure TTerminologyOperationContext.addNote(vs : TFHIRValueSetW; note: String
s : string;
begin
s := DescribePeriodMS(GetTickCount64 - FStartTime)+' '+vs.vurl+': '+note;
if UnderDebugger then
if false and UnderDebugger then
Logging.log(s);
FNotes.add(s);
end;
Expand Down Expand Up @@ -542,6 +550,7 @@ procedure TTerminologyWorker.deadCheck(place: String);
if FOpContext.deadCheck(time) then
begin
FOpContext.addNote(vsHandle, 'Operation took too long @ '+place+' ('+className+')');
Logging.log('Operation took too long @ '+place+' ('+className+')');
raise costDiags(ETooCostly.create(FI18n.translate('VALUESET_TOO_COSTLY_TIME', FParams.HTTPlanguages, ['??', inttostr(time), opName])));
end;
end;
Expand Down
3 changes: 2 additions & 1 deletion library/ftx/fhir_valuesets.pas
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ interface
FHIR_VERSION_CANONICAL_SPLIT_3p = '|';

EXPANSION_DEAD_TIME_SECS = 30;
VALIDATION_DEAD_TIME_SECS = 30;
VALIDATION_DEAD_TIME_SECS = 60;


Type
Expand Down Expand Up @@ -2569,6 +2569,7 @@ function TFHIRValueSetExpander.expand(source: TFHIRValueSetW;

if (offset + count < 0) and (FFullList.count > limit) then
begin
Logging.log('Operation took too long @ expand ('+className+')');
raise costDiags(ETooCostly.create(FI18n.translate('VALUESET_TOO_COSTLY_COUNT', FParams.HTTPLanguages, [source.vurl, '>'+inttostr(limit), inttostr(FFullList.count)])));
end
else
Expand Down

0 comments on commit 61ec58f

Please sign in to comment.