Home > Articles

This chapter is from the book

This chapter is from the book

6.10 Sample Client-Server System Using RPCs

The supplied server4.cc and client4.cc implement a sample RPC system with logging. In addition, the supplied dumplogfile4.cc turns binary logs into JSON-formatted ASCII so you can see what they contain and so that they can be displayed easily.

The service provided by these programs is an in-memory key-value store (a simple database). The server program accepts RPCs that read or write key-value pairs in RAM, while the client sends such requests. The server-implemented methods are

  • Ping(data), returns a copy of data with no key-value action

  • Write(key, value), remembers the pair

  • Read(key), returns value

  • Chksum(key), returns an eight-byte checksum of the value

  • Delete(key), removes key and its value

  • Stats(), returns some statistics on server usage

  • Reset(), erases all key-value pairs

  • Quit(), stops the server and all its threads

This pair of programs should allow you to get into trouble in myriad ways. Sending a burst of 100 values of 1MB each will saturate a sample server’s 1Gb/sec Ethernet for at least a second. Doing two such actions independently between different machines should overload a sample four-port switch. Sending a burst of 100,000 one-byte values will saturate CPUs quite nicely and also clog up the logging system. Overlapping a heavy-duty burst with some more modest work will likely interfere with the modest work.

InformIT Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.