Wednesday, November 11, 2009

9.2 The Basic Idea



< BACK  NEXT >

[oR]


9.2
The Basic Idea


Once everything is set up and working properly, a remote procedure call looks very easy. In your code, you simply call a function just like you normally would. Looking at the code, there is no way to distinguish an RPC from a normal function. For example, in a graphics program you might have a function named CalcPixel that calculates the value for a pixel in a ray-traced image. In any ray-tracing application, CalcPixel would represent a fairly CPU-intensive function call. A typical call might look like this:





color = CalcPixel(x,y);



In a normal program, when you call the function, the program first branches off to execute the function, then calculates the result, and returns with the answer. In an RPC program, however, the computer instead acts as an
RPC client and sends a network packet containing the x and y parameters to another machine running the
RPC server for that function. The function executes on the second machine, and when it is done, that machine sends a network packet containing the function's result back to the caller. See Figure 9.1





Figure 9.1. Remote procedure calls send parameters to a remote machine, where the function executes. Any results are sent back to the caller through the network as well








There is nothing magical about RPCs. For example, it is possible for you to implement most of an RPC's functionality yourself using the network commands discussed in Chapter 8. However, it would take a lot of code, and it would not be nearly as clean as the RPC implementation is. The advantage of using RPCs is that the syntax is so delightfully simple. You just call a function like you always do, and everything else is automatic. All of the network details are hidden from view and you can ignore them.



The most important advantage of RPCs is the ability they give you to optimize use of the hardware resources available on your network. For example, if you have a machine that contains a board that is very good at calculating ray-traced pixels, you can put the RPC server for CalcPixel on that machine. Now anyone on the network, regardless of the type of machine they are using, can run the ray-tracing program and take advantage of the speed of that special board. RPCs give you an extremely powerful tool for creating client/server applications.





< BACK  NEXT >


No comments:

Post a Comment