Share via


Why does the NdrClientCall2() API call takes more then 4-5 milliseconds to complete?

Question:

Why does the NdrClientCall2() API call takes more then 4-5 milliseconds to complete in my application? In rare cases I even see hundreds of milliseconds (57 millisecond at one time) just for the NdrClientCall2() API call to complete.

In my application no server side processing is involved. My client and server both are running on the same machine. In either case it is a ncacn_np operation, both sides are already connected, all the calls should complete with the same (or about same) delays.

Is it possible to explain what kinds of things might be involved in this delay?

Answer:

For local RPC calls, it is highly recommend that users to use ncalrpc and not ncacn_np. Ncacn_np is primarily for backwards compatibility and new applications should be using ncacn_ip_tcp for remote traffic. If you are using Vista or later, it is recommended to switch to the lower latency fast binding handle path for LRPC. This removes some significant sources of lock contention in the client path, potentially leading to a reduction in delays.

Please check the links below to know more about the fast RPC binding handle.

RpcBindingCreate
https://msdn.microsoft.com/en-us/library/aa375587(VS.85).aspx

RpcBindingBind
https://msdn.microsoft.com/en-us/library/aa375583(VS.85).aspx

RpcBindingUnbind
https://msdn.microsoft.com/en-us/library/aa375613(VS.85).aspx

RpcBindingFree
https://msdn.microsoft.com/en-us/library/aa375588(VS.85).aspx

On the other hand, the occasional delay is not all that odd. A DPC firing, while the test is executing, can easily cause a 3-4ms delay.

Also please remember, Windows is not a real time operating system and there is no way to give any upper bound guarantee for NdrClientCall2() API call.