You are not logged in.
Hi,
on Windows Server 2019 my console-application has constant 25% CPU load, conhost.exe another 25%.
On Windows 7, everything is just fine (< 1% during idle).
I'm using the function ConsoleWaitForEnterKey.
Can you give me a hint?
Thanks in advance!
Offline
Just thought as a hint. I have had good experience with TSynDaemon as a starting point.
TMyServerSettings = class(TSynDaemonSettings);
TMyServerDaemon = class(TSynDaemon)
private
FMain: TMyServerMain;
public
constructor Create; reintroduce;
procedure Start; override;
procedure Stop; override;
end;
constructor TMyServerDaemon.Create;
begin
inherited Create(TMyServerSettings,
IncludeTrailingPathDelimiter(ExeVersion.ProgramFilePath),
TFileUtils.MainDataFolder,
TFileUtils.GetLogFileFolder);
...
end;
procedure TMyServerDaemon.Start;
begin
if FMain = Nil then
FMain := TMyServerMain.Create;
end;
procedure TMyServerDaemon.Stop;
begin
FreeAndNil(FMain);
end;
// Main MyServer.dpr
begin
with TMyServerDaemon.Create do
try
CommandLine(True);
finally
Free;
end;
end.
Then I can start the server e.g. with "MyServer.exe -c".
With best regards
Thomas
Offline
Thanks Thomas for your hint!
I successfully used your approach with mORMotService.TSynDaemon - High CPU-Load is gone.
But i had to use ConsoleWaitForEnterKey() instead of readln() in procedure TSynDaemon.CommandLine, else the mainthread was blocked and we currently use some Timers and Services running in Mainthread.
Offline
I believe that when using the Daemon all processes must be running inside the daemon.
TSynBackgroundTimer allows you to perform tasks at defined intervals.
Offline
macfly has already written the solution. In my source code I use it as follows:
TMyRestServer = class(TSQLRestServerDB)
protected
procedure DownloadData(pmSender: TSynBackgroundTimer; pmEvent: TWaitResult; const pmcMsg: RawUTF8);
public
procedure Start;
procedure Stop;
end;
procedure TMyRestServer.Start;
var
timer: TSynBackgroundTimer;
begin
timer := TimerEnable(DownloadData, FRestServiceSettings.DataUpdateInterval);
if Assigned(timer) then
timer.ExecuteNow(DownloadData);
end;
procedure TMyRestServer.Stop;
begin
TimerDisable(DownloadData);
end;
With best regards
Thomas
Offline