You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by ag...@apache.org on 2022/06/07 17:11:20 UTC

[ignite-3] branch main updated: IGNITE-17113 Distributed computing documentation added

This is an automated email from the ASF dual-hosted git repository.

agura pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/ignite-3.git


The following commit(s) were added to refs/heads/main by this push:
     new 7facb4e9d IGNITE-17113 Distributed computing documentation added
7facb4e9d is described below

commit 7facb4e9d7005929b209d2589ddc67cf4b161f64
Author: IgGusev <de...@mail.ru>
AuthorDate: Tue Jun 7 20:10:57 2022 +0300

    IGNITE-17113 Distributed computing documentation added
    
    Signed-off-by: Andrey Gura <ag...@apache.org>
---
 docs/_data/toc.yaml             |   2 +
 docs/_docs/compute/compute.adoc | 106 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 108 insertions(+)

diff --git a/docs/_data/toc.yaml b/docs/_data/toc.yaml
index 9b7c5b29c..18d8fe04a 100644
--- a/docs/_data/toc.yaml
+++ b/docs/_data/toc.yaml
@@ -34,6 +34,8 @@
       url: sql-reference/operators-and-functions
 - title: REST API
   url: rest/rest-api
+- title: Distributed Computing
+  url: compute/compute
 - title: Data Region Configuration
   url: config/data-region
 - title: Binary Client Protocol
diff --git a/docs/_docs/compute/compute.adoc b/docs/_docs/compute/compute.adoc
new file mode 100644
index 000000000..f9c872da2
--- /dev/null
+++ b/docs/_docs/compute/compute.adoc
@@ -0,0 +1,106 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements.  See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License.  You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+= Distributed Computing
+
+Apache Ignite 3 provides an API for distributing computations across cluster nodes in a balanced and fault-tolerant manner. You can submit individual tasks for execution from Java and .NET clients.
+
+You can use Java or .NET client to execute compute jobs. Make sure the required classes are deployed to the cluster before executing code.
+
+Here is how you can execute a simple compute job:
+
+
+[tabs]
+--
+tab:Java[]
+[source, java]
+----
+private void example() {
+    IgniteClient client = client();
+    IgniteCompute compute = client.compute();
+    Set<ClusterNode> nodes = new HashSet<>(client.clusterNodes());
+
+    compute.execute(nodes, NodeNameJob.class, "Hello");
+}
+
+private static class NodeNameJob implements ComputeJob<String> {
+    @Override
+    public String execute(JobExecutionContext context, Object... args) {
+        return context.ignite().name() + "_" + args[0];
+    }
+}
+----
+
+
+NOTE: Unlike Ignite 2, jobs are not serialized. Only the class name and arguments are sent to the node.
+
+tab:.NET[]
+[source, csharp]
+----
+IIgniteClient client = Client;
+ICompute compute = client.Compute;
+IList<IClusterNode> nodes = await Client.GetClusterNodesAsync();
+string res = await compute.ExecuteAsync<string>(nodes, jobClassName: "org.foo.bar.NodeNameJob", "Hello!");
+----
+--
+
+
+== Colocated Computations
+
+In Apache Ignite 3 you can execute colocated computation with `executeColocated` method. When you do it, the compute task is guaranteed to be executed on the nodes that hold the specified key. This can significantly reduce execution time if your tasks require data.
+
+In this example we will need a table to colocate:
+
+
+
+[source, java]
+----
+executeSql("CREATE TABLE test (k int, v int, CONSTRAINT PK PRIMARY KEY (k))");
+executeSql("INSERT INTO test(k, v) VALUES (1, 101)");
+----
+
+And we will execute a simple task:
+
+----
+class GetNodeNameJob implements ComputeJob<String> {
+    @Override
+    public String execute(JobExecutionContext context, Object... args) {
+        return context.ignite().name();
+    }
+}
+----
+
+
+[tabs]
+--
+tab:Tuple[]
+[source, java]
+----
+String actualNodeName = ignite.compute()
+        .executeColocated("PUBLIC.test", Tuple.create(Map.of("k", 1)), GetNodeNameJob.class)
+        .get(1, TimeUnit.SECONDS);
+
+System.out.println(actualNodeName);
+----
+
+tab:Mapper[]
+[source, java]
+----
+String actualNodeName = ignite.compute()
+        .executeColocated("PUBLIC.test", 1, Mapper.of(Integer.class), GetNodeNameJob.class)
+        .get(1, TimeUnit.SECONDS);
+
+System.out.println(actualNodeName);
+----
+--
\ No newline at end of file