IPC Speed

c++ / delphi package - dll injection and api hooking
Post Reply
VanRoie
Posts: 4
Joined: Sun Sep 05, 2004 6:11 pm

IPC Speed

Post by VanRoie »

I test today the IPC speed between two exe.
I found the speed quite slow : round 200 messages per second.
But at each test of 100 messages, the speed slow down 180/sec, ...160, ... 120 ...

My PC is a AMD 2 GHz, 512 Mb ram
I use Delphi 7
MadCollection 2.1.3.0
The IPCCallBack does nothing

My questions are
1) why is the speed quite slow
2) why is it decreasing when the total number of message grow

thanks for help
Dominique Van Roie
madshi
Site Admin
Posts: 10754
Joined: Sun Mar 21, 2004 5:25 pm

Post by madshi »

The speed is low because I never tested or optimized speed yet. The IPC messages were meant to be used for a message now and then and not for a few hundreds messages per second.

However, I've on my to do list to improve the IPC speed - and the improvement will be quite dramatic. But I can't say when I'll have it finished. May take some weeks (months?).

I don't know why the speed goes down with total number of messages. How did you test this? Can you post your test code here, please?
VanRoie
Posts: 4
Joined: Sun Sep 05, 2004 6:11 pm

ipc speed

Post by VanRoie »

Here are the two test procedure I used.

// Structure used
TProcessAuthorizationRequest = record
UserName: ShortString;
ComputerName: ShortString;
ProcessFileName: ShortString;
end;
PProcessAuthorizationRequest = ^TProcessAuthorizationRequest;

TProcessAuthorizationResponse = record
Authorized: boolean;
AuthorizationStatus: TAuthorizationStatus;

RequestNumber: integer;
ErrorMessage: ShortString;
end;
PProcessAuthorizationResponse = ^TProcessAuthorizationResponse;


// Server side
procedure IpcCallback2(name: pchar; messageBuf : pointer; messageLen : dword; answerBuf : pointer; answerLen : dword); stdcall;
var
IPCQueueName: string;
ProcessAuthorizationRequestPtr: PProcessAuthorizationRequest;
ProcessAuthorizationResponsePtr: PProcessAuthorizationResponse;
begin
IPCQueueName := String(name);
if ( SameText(IPCQueueName, PROCESS_AUTHORIZATION_QUEUE_NAME) and (messageLen = sizeOf(TProcessAuthorizationRequest)) ) then begin
ProcessAuthorizationRequestPtr := messageBuf;
ProcessAuthorizationResponsePtr := answerBuf;

ProcessAuthorizationResponsePtr^.Authorized := True;
ProcessAuthorizationResponsePtr^.AuthorizationStatus := asasAuthorizedByDefault;
ProcessAuthorizationResponsePtr^.RequestNumber := -1;
ProcessAuthorizationResponsePtr^.ErrorMessage :='';
end;
end;


// CLient Side
procedure TForm1.BtnSendClick(Sender: TObject);
var
StartTime, TotTime: DWORD;
ProcessAuthorizationRequest: TProcessAuthorizationRequest;
ProcessAuthorizationResponse: TProcessAuthorizationResponse;
i, Count: integer;
Avg: double;
begin
LogMsg('Start');
ProcessAuthorizationResponse.Authorized := False;

StartTime := GetTickCount;
Count := StrToInt(EdtCount.Text); // 100
for i := 0 to Count -1 do begin
ProcessAuthorizationRequest.UserName := EdtUserName.Text;
ProcessAuthorizationRequest.ComputerName := 'PoCo';
ProcessAuthorizationRequest.ProcessFileName := ChangeFileExt(Application.ExeName, Format('%d.exe', ));

SendIpcMessage(PROCESS_AUTHORIZATION_QUEUE_NAME,
@ProcessAuthorizationRequest,
SizeOf(TProcessAuthorizationRequest),
@ProcessAuthorizationResponse,
SizeOf(TProcessAuthorizationResponse),
5000,
False);

end;

TotTime := (GetTickCount - StartTime);
if ( TotTime > 0 ) then begin
Avg := (count * 1000) / TotTime;
end;
LogMsg(Format('%d ms for %d messages => %f msg/sec', [TotTime, Count, Avg]));
LogMsg('');
end;
VanRoie
Posts: 4
Joined: Sun Sep 05, 2004 6:11 pm

IPC Speed

Post by VanRoie »

Hi,

The context of the projet is:

For Citrix server, we want to authorize process execution.
We plan to make a system wide CreateProcess hook and ask a service via IPC messages if the process is authorized for the logged user.

The speed is important for the response time to the user.
If the server run 30 to 40 session, the total number of message after a day may be suite large. At login time, the concurent request may be round 100 /Sec.

The Beta of this project must be ready for end of september. So If you don't have time, would you please give me some information on the best way to build a faster IPC

Thanks
Dominique Van Roie
madshi
Site Admin
Posts: 10754
Joined: Sun Mar 21, 2004 5:25 pm

Post by madshi »

I don't think I can offer a much faster solution until the end of September. I have some other things which I have to do first. So the time is too short.

You can try to realize something faster yourself by using a combination of memory mapped files and events and mutexes. E.g. your application could offer a memory buffer to which the dlls may write directly. You could publish this memory buffer by writing the processID and buffer address to a memory mapped file. The dlls can then use OpenProcess + WriteProcessMemory to directly write to the buffer. After writing they probably should signal an event so that the application wakes up and reads the information. Everything must be synchronized, of course, so that this is thread safe.
Post Reply