IPC Speed

c++ / delphi package - dll injection and api hooking

IPC Speed

Postby VanRoie » Sun Sep 05, 2004 6:20 pm

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
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
Posts: 4
Joined: Sun Sep 05, 2004 6:11 pm

Postby madshi » Mon Sep 06, 2004 4:51 pm

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?
Site Admin
Posts: 9810
Joined: Sun Mar 21, 2004 5:25 pm

ipc speed

Postby VanRoie » Mon Sep 06, 2004 7:48 pm

Here are the two test procedure I used.

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

TProcessAuthorizationResponse = record
Authorized: boolean;
AuthorizationStatus: TAuthorizationStatus;

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

// Server side
procedure IpcCallback2(name: pchar; messageBuf : pointer; messageLen : dword; answerBuf : pointer; answerLen : dword); stdcall;
IPCQueueName: string;
ProcessAuthorizationRequestPtr: PProcessAuthorizationRequest;
ProcessAuthorizationResponsePtr: PProcessAuthorizationResponse;
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 :='';

// CLient Side
procedure TForm1.BtnSendClick(Sender: TObject);
StartTime, TotTime: DWORD;
ProcessAuthorizationRequest: TProcessAuthorizationRequest;
ProcessAuthorizationResponse: TProcessAuthorizationResponse;
i, Count: integer;
Avg: double;
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', [i]));



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

IPC Speed

Postby VanRoie » Thu Sep 09, 2004 10:24 am


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

Dominique Van Roie
Posts: 4
Joined: Sun Sep 05, 2004 6:11 pm

Postby madshi » Thu Sep 09, 2004 10:33 am

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.
Site Admin
Posts: 9810
Joined: Sun Mar 21, 2004 5:25 pm

Return to madCodeHook

Who is online

Users browsing this forum: Baidu [Spider] and 6 guests