Server

public final class Server

An in-process TensorFlow server, for use in distributed training.

A Server instance encapsulates a set of devices and a Session target that can participate in distributed training. A server belongs to a cluster (specified by a ClusterSpec), and corresponds to a particular task in a named job. The server can communicate with any other server in the same cluster. The server will not serve any requests until start() is invoked. The server will stop serving requests once stop() or close() is invoked. Be aware that close() method stops the server if it is running.

WARNING: A Server owns resources that must be explicitly freed by invoking close().

Instances of a Server are thread-safe.

Using example:

import org.tensorflow.Server;
 import org.tensorflow.distruntime.ClusterDef;
 import org.tensorflow.distruntime.JobDef;
 import org.tensorflow.distruntime.ServerDef;

 ClusterDef clusterDef = ClusterDef.newBuilder()
   .addJob(JobDef.newBuilder()
   .setName("worker")
   .putTasks(0, "localhost:4321")
   .build()
 ).build();

 ServerDef serverDef = ServerDef.newBuilder()
   .setCluster(clusterDef)
   .setJobName("worker")
   .setTaskIndex(0)
   .setProtocol("grpc")
 .build();

 try (Server srv = new Server(serverDef)) {
   srv.start();
   srv.join();
 
 }

Public Constructors

Server(ServerDef serverDef)
Constructs a new instance of server.

Public Methods

synchronized void
close()
Destroy an in-process TensorFlow server, frees memory.
void
join()
Blocks until the server has been successfully stopped.
synchronized void
start()
Starts an in-process TensorFlow server.
synchronized void
stop()
Stops an in-process TensorFlow server.

Inherited Methods

Public Constructors

public Server (ServerDef serverDef)

Constructs a new instance of server.

Parameters
serverDef Server definition specified as a ServerDef protocol buffer.

Public Methods

public synchronized void close ()

Destroy an in-process TensorFlow server, frees memory.

Throws
InterruptedException

public void join ()

Blocks until the server has been successfully stopped.

public synchronized void start ()

Starts an in-process TensorFlow server.

public synchronized void stop ()

Stops an in-process TensorFlow server.