org.tranche.network
Class MultiServerRequestStrategy

java.lang.Object
  extended by org.tranche.network.MultiServerRequestStrategy

public class MultiServerRequestStrategy
extends java.lang.Object

Say a client has a request for many servers. If pick any server (randomly or using a heuristic), you can create this object to determine:

  1. Which servers will receive subsets of the total request (called 'partitions') so that all the requests are filled efficiently
  2. The 'depth' of the request, which is an approximation of the efficiency.

A simple strategy: if want to see best server to which to send a request, calculate this for all online servers and select the strategy with the smallest depth.

Note that a server receiving a multi-server request will also build a MultiServerRequestStategy object, using its host as the parameter. That way, it will know how to partition the request amongst servers to which it is connected.

Author:
Bryan Smith - bryanesmith@gmail.com

Field Summary
static int INFINITE_DEPTH
          Constant used for infinite depth--i.e., cannot solve.
 
Method Summary
static MultiServerRequestStrategy create(java.lang.String hostReceivingRequest, java.util.Collection<java.lang.String> serverHostsToRequest)
          Say a client has a request for many servers.
 boolean equals(java.lang.Object o)
           
 boolean equivalent(MultiServerRequestStrategy other)
          Test that strategy objects are similar.
static java.util.Collection<MultiServerRequestStrategy> findFastestStrategiesUsingConnectedCoreServers(java.util.Collection<java.lang.String> serverHostsToRequest, org.tranche.commons.Tertiary readable, org.tranche.commons.Tertiary writable)
          Finds set of strategies that have the smallest depth, which is a strong heuristic for speed.
 int getDepth()
          If this request is sent to the server host listed, this is the 'depth' of the request across the network for the requested servers when modeled as a tree.
 java.lang.String getHostReceivingRequest()
          The host name for the server to receive the request, per this strategy object.
 java.util.Map<java.lang.String,java.util.Set<java.lang.String>> getPartitionsMap()
          This is a map containing the following:
 java.util.Set<java.lang.String> getUnfulfillableHosts()
          All the hosts that are unfulfillable.
 int hashCode()
           
 void printStrategy(java.io.PrintStream out)
           
 boolean requestContains(java.lang.String host)
          Returns true if request contains a particular host.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

INFINITE_DEPTH

public static final int INFINITE_DEPTH

Constant used for infinite depth--i.e., cannot solve. If depth equal to this, then discard strategy.

See Also:
Constant Field Values
Method Detail

findFastestStrategiesUsingConnectedCoreServers

public static java.util.Collection<MultiServerRequestStrategy> findFastestStrategiesUsingConnectedCoreServers(java.util.Collection<java.lang.String> serverHostsToRequest,
                                                                                                              org.tranche.commons.Tertiary readable,
                                                                                                              org.tranche.commons.Tertiary writable)

Finds set of strategies that have the smallest depth, which is a strong heuristic for speed.

Uses as primary host only online, core servers to which the client is connected.

Uses in the tree of connections only online, core servers.

If caller would like to select strategy based on heuristics other than depth, can call create method for desired to get desired set of strategies.

Parameters:
serverHostsToRequest -
Returns:

create

public static MultiServerRequestStrategy create(java.lang.String hostReceivingRequest,
                                                java.util.Collection<java.lang.String> serverHostsToRequest)

Say a client has a request for many servers. If pick any server (randomly or using a heuristic), you can create this object to determine:

  1. Which servers will receive subsets of the total request (called 'partitions') so that all the requests are filled efficiently
  2. The 'depth' of the request, which is an approximation of the efficiency.

A simple strategy: if want to see best server to which to send a request, calculate this for all online servers and select the strategy with the smallest depth.

Note that a server receiving a multi-server request will also build a MultiServerRequestStategy object, using its host as the parameter. That way, it will know how to partition the request amongst servers to which it is connected.

Parameters:
hostReceivingRequest - Server to which to send a request for a set of servers
serverHostsToRequest - Set of all servers included in the request. Note that if hostReceivingRequest is not included in the set, then it can still be used to pass the requests on--but it won't be included in the request!

Returns:
The MultiServerRequestStrategy object

getHostReceivingRequest

public java.lang.String getHostReceivingRequest()

The host name for the server to receive the request, per this strategy object.

Returns:

getPartitionsMap

public java.util.Map<java.lang.String,java.util.Set<java.lang.String>> getPartitionsMap()

This is a map containing the following:

Say we want set of hosts in this request, H = { h1, h2, h3, ..., h12 }, |H| = 12. If sending this request to an arbitrary host, h1, this map shows how this server will partition up these requests amongst its connected servers so that the request is filled as quickly as possible.

Say our key set is this map is {h2, h3, h4}, which are servers connected directly to h1. Then, hypothetically:

All the requests were partitioned! Note that just because h2 -> { h2, h5, h6, h7 } doesn't mean that the server is connected to all four servers. The depth is a separate issue (and is available through this object); this is enough information to know where to send the requests next.

Returns:

getDepth

public int getDepth()

If this request is sent to the server host listed, this is the 'depth' of the request across the network for the requested servers when modeled as a tree.

I.e., assume the server being sent the request is the root node. The branches are the servers to which it sends the request. If they satisfy the requests, then they are leaves; otherwise, they'll branche, etc. This number is the depth of this tree.

This is a rough approximation of the efficiency--the lower the depth, the more efficient (likely) to be.

Before sending a request to a particular server, can create a number of these summary objects and select the one with lowest depth. Other heuristics might be helpful as well.

Returns:

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

printStrategy

public void printStrategy(java.io.PrintStream out)

getUnfulfillableHosts

public java.util.Set<java.lang.String> getUnfulfillableHosts()

All the hosts that are unfulfillable. Right now, this means because the server is offline. There might be additional future conditions.

Returns:

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

equivalent

public boolean equivalent(MultiServerRequestStrategy other)

Test that strategy objects are similar. Don't have to be exactly same, but must have the following in common:

Parameters:
other -
Returns:

equals

public boolean equals(java.lang.Object o)
Overrides:
equals in class java.lang.Object

requestContains

public boolean requestContains(java.lang.String host)

Returns true if request contains a particular host.

Parameters:
host -
Returns:


This code is free for use both commercially and non-commercially as stated in the project's license