This is the first tip in the series which purpose is to show practical programming techniques for YAMI4 users.
What makes distributed system different from a monolithic application is that integration and connectivity failures can become part of the game even if the program is written correctly. The additional factors come from the fact that in many cases the programmer does not control the whole system environment - is the remote server running and is the whole network infrastructure properly set up to allow all communication to take place?
In many cases we cannot be sure about that and it can be possible that the program will not be able to connect to the given server. Then, depending on many factors such as network latencies and firewall settings we will either immediately see that the connection cannot be established or the program will block for some time, which might be longer than is acceptable.
In YAMI4 it is possible to control how much time the program is allowed to wait while creating new connections and this can be done with appropriate configuration options. Additionally, YAMI4 tries very hard to establish the given connection and attempts to do it several times before giving up, so this can also add to the time that the program has to wait. The number of such attempts can be controlled with other config options.
In a local network, where everything happens very quickly, establishing new connections can be simplified: we can assume that it either succeeds in a short time (check the
ping statistics to get the idea how fast any given machine can be reached in your network) or it will fail and there is no reason to wait too long. Use configuration options to make your program fail fast when connection cannot be established:
// C++: yami::parameters options; options.set_integer(yami::option_names::connection_retries, 1); // try only once options.set_integer(yami::option_names::tcp_connect_timeout, 100); // wait only 100 ms yami::agent my_agent(options); // ...
With such settings your client program will not wait unnecessarily when connection to the server cannot be established. These settings are useful in a local network.
The code will follow a similar pattern in all other supported languages. You can use strings (like
"connection_retries" instead of constants, but beware typos - unknown option names will not be reported!).
Next tip: Default Objects
Did you find this article interesting? Share it!