Waiting for Ready Channels
When I create a channel to a service, how do I know when the service is ready to process the data for that channel?
A channel doesn't really know what the service is doing. The service might be actively processing the data being sent over the channel. Or, the service might not.
There is a constant tension in the system between components that want to push data and components that want to pull data.
Components that push data actively work as long as there is data available until a back pressure builds up in the system that resists their ability to push. This back pressure is typically the result of some queue or buffer that has filled up and is no longer able to accept the things being pushed into it. Components that push include several transport and protocol channels, as well as the service dispatcher that pushes messages to the service implementation.
Components that pull data remain quiescent even if data is available until there is someone that actually wants to consume some data. Many transport and protocol channels pull messages rather than push.
A single implementation may feature both push and pull modes. For example, the TCP channel has a small portion that works in a push mode for connection establishment and transferring some initial data while the application portion of TCP works in a pull mode. Depending on the visibility of these push and pull modes, you might be able to tell from the behavior of a particular protocol what the service is doing.
For example, if you're using just TCP, then the initial transmissions needed to open a connection can only be completed once a little bit of pulling has been done on the receiving application side, thus telling you that the service is doing some active processing. On the other hand, if you're using a ReliableMessaging channel or a OneWay channel, then those protocols have a visible running state where they are in push mode. You can't actually tell whether the service is working until you fill up some of the buffers in the protocol stack and start getting push back in the form of rejected messages. That means the service is not working as fast as you're sending data. A queued channel would be an extreme example of push mode. A message queue allows you to push large amounts of data when the service is not even running.
Therefore, to know in the general case whether the service is ready to process for you, you need to be able to ask that question to the service rather than to the channel.
Next time: Composing Compression and Encryption
Comments
Anonymous
September 02, 2008
I was working on some services with recursive data structures when I noticed that there were a few casesAnonymous
October 29, 2008
WCF: Zen of performance and scale