public final class Server extends Object implements AutoCloseable
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.toByteArray())) {
srv.start();
srv.join();
}
Constructor and Description |
---|
Server(byte[] serverDef)
Constructs a new instance of server.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Destroy an in-process TensorFlow server, frees memory.
|
void |
join()
Blocks until the server has been successfully stopped.
|
void |
start()
Starts an in-process TensorFlow server.
|
void |
stop()
Stops an in-process TensorFlow server.
|
public Server(byte[] serverDef)
serverDef
- Server definition specified as a serialized ServerDef
protocol buffer.public void start()
public void stop()
public void join()
public void close() throws InterruptedException
close
in interface AutoCloseable
InterruptedException
Copyright © 2022. All rights reserved.