Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Znav
nextExample of a File System Server in C++
prevObject Incarnation in C++

The number of simultaneous synchronous requests a server is capable of supporting is determined by the number of threads in the server's thread pool. If all of the threads are busy dispatching long-running operations, then no threads are available to process new requests and therefore clients may experience an unacceptable lack of responsiveness.

...

An alternate use case for AMD is an operation that requires further processing after completing the client's request. In order to minimize the client's delay, the operation returns the results while still in the dispatch thread, and then continues using the dispatch thread for additional work.

On this page:

Table of Contents
maxLevel3

Enabling AMD with Metadata in C++

...

Specifying metadata at the operation level (rather than at the interface or class level) minimizes the amount of generated code and, more importantly, minimizes complexity: although the asynchronous model is more flexible, it is also more complicated to use. It is therefore in your best interest to limit the use of the asynchronous model to those operations that need it, while using the simpler synchronous model for the rest.

Ztop

AMD Mapping in C++

The C++ mapping emits the following code for each AMD operation:

  1. A callback class used by the implementation to notify the Ice run time about the completion of an operation. The name of this class is formed using the pattern AMD_class_op. For example, an operation named foo defined in interface I results in a class named AMD_I_foo. The class is generated in the same scope as the interface or class containing the operation. Several methods are provided:

    Neither ice_response nor ice_exception throw any exceptions to the caller.

  2. The dispatch method, whose name has the suffix _async. This method has a void return type. The first parameter is a smart pointer to an instance of the callback class described above. The remaining parameters comprise the in-parameters of the operation, in the order of declaration.

...

Wiki Markup
{zcode:cpp}
void foo_async(const AMD_I_fooPtr&, Ice::Short);
{zcode}

Ztop

AMD Exceptions in C++

There are two processing contexts in which the logical implementation of an AMD operation may need to report an exception: the dispatch thread (the thread that receives the invocation), and the response thread (the thread that sends the response).

...

Whether raised in a dispatch thread or reported via the callback object, user exceptions are validated and local exceptions may undergo translation.

Ztop

AMD Example in C++

To demonstrate the use of AMD in Ice, let us define the Slice interface for a simple computational engine:

...

Wiki Markup
{zcode:cpp}
Job::Job(const Demo::AMD_Model_interpolatePtr& cb, const Demo::Grid& grid, Ice::Float factor) :
    _cb(cb), _grid(grid), _factor(factor)
{
}

void Job::execute()
{
    if (!interpolateGrid()) {
        _cb?->ice_exception(Demo::RangeError());
        return;
    }
    _cb?->ice_response(_grid);
}
{zcode}

...

If interpolation was successful, ice_response is called to send the modified grid back to the client.

Ztop

See Also

Zret
Znav
nextExample of a File System Server in C++
prevObject Incarnation in C++