apache-ignite

Форк
0
/
partition-based-dataset.adoc 
96 строк · 5.2 Кб
1
// Licensed to the Apache Software Foundation (ASF) under one or more
2
// contributor license agreements.  See the NOTICE file distributed with
3
// this work for additional information regarding copyright ownership.
4
// The ASF licenses this file to You under the Apache License, Version 2.0
5
// (the "License"); you may not use this file except in compliance with
6
// the License.  You may obtain a copy of the License at
7
//
8
// http://www.apache.org/licenses/LICENSE-2.0
9
//
10
// Unless required by applicable law or agreed to in writing, software
11
// distributed under the License is distributed on an "AS IS" BASIS,
12
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
// See the License for the specific language governing permissions and
14
// limitations under the License.
15
= Partition Based Dataset
16

17
== Overview
18

19
Partition-Based Dataset is an abstraction layer on top of the Apache Ignite storage and computational capabilities that allow us to build algorithms in accordance with link:machine-learning/machine-learning#section-zero-etl-and-massive-scalability[zero ETL] and link:machine-learning/machine-learning#section-fault-tolerance-and-continuous-learning[fault tolerance] principles.
20

21
A main idea behind the partition-based datasets is the classic MapReduce approach implemented using the Compute Grid in Ignite.
22

23
The most important advantage of MapReduce is the ability to perform computations on data distributed across the cluster without involving significant data transfers over the network. This idea is adopted in the partition-based datasets in the following way:
24

25
  * Every dataset is spread across partitions;
26
  * Partitions hold a persistent *training context* and recoverable *training data* stored locally on every node;
27
  * Computations needed to be performed on a dataset splits on *Map* operations which executes on every partition and *Reduce* operations which reduces results of *Map* operations to one final result.
28

29
**Training Context (Partition Context)** is a persistent part of the partition which is kept in an Apache Ignite, so that all changes made in this part will be consistently maintained until a partition-based dataset is closed. Training context survives node failures but requires additional time to read and write, so it should be used only when it's not possible to use partition data.
30

31
**Training Data (Partition Data)** is a part of the partition that can be recovered from the upstream data and context at any time. Because of this, it is not necessary to maintain partition data in some persistent storage, so that partition data is kept on every node in local storage (On-Heap, Off-Heap or even in GPU memory) and in case of node failure is recovered from upstream data and context on another node.
32

33
Why have partitions been selected as dataset and learning building blocks instead of cluster nodes?
34

35
One of the fundamental ideas of an Apache Ignite is that partitions are atomic, which means that they cannot be split between multiple nodes for more details). As a result in the case of rebalancing or node failure, a partition will be recovered on another node with the same data it contained on the previous node.
36

37
In case of a machine learning algorithm, it's vital​ because most of the ML algorithms are iterative and require some context maintained between iterations. This context cannot be split or merged and should be maintained in a consistent state during the whole learning process.
38

39
== Usage
40

41
To build a partition-based dataset you need to specify:
42

43
* Upstream Data Source which can be an Ignite Cache or just a Map with data;
44
* Partition Context Builder that defines how to build a partition context from upstream data rows corresponding to this partition;
45
* Partition Data Builder that defines how to build partition data from upstream data rows corresponding to this partition.
46

47

48
.Cache-based Dataset
49
[source, java]
50
----
51
Dataset<MyPartitionContext, MyPartitionData> dataset =
52
    new CacheBasedDatasetBuilder<>(
53
        ignite,                            // Upstream Data Source
54
        upstreamCache
55
    ).build(
56
        new MyPartitionContextBuilder<>(), // Training Context Builder
57
        new MyPartitionDataBuilder<>()     // Training Data Builder
58
    );
59
----
60

61

62
.Local Dataset
63
[source, java]
64
----
65
Dataset<MyPartitionContext, MyPartitionData> dataset =
66
    new LocalDatasetBuilder<>(
67
        upstreamMap,                       // Upstream Data Source
68
        10
69
    ).build(
70
        new MyPartitionContextBuilder<>(), // Partition Context Builder
71
        new MyPartitionDataBuilder<>()     // Partition Data Builder
72
    );
73
----
74

75
After this you are able to perform different computations on this dataset in a MapReduce manner.
76

77

78
[source, java]
79
----
80
int numerOfRows = dataset.compute(
81
    (partitionData, partitionIdx) -> partitionData.getRows(),
82
    (a, b) -> a == null ? b : a + b
83
);
84
----
85

86
And, finally, when all computations are completed it's important to close the dataset and free resources.
87

88

89
[source, java]
90
----
91
dataset.close();
92
----
93

94
== Example
95

96
To see how the Partition Based Dataset can be used in practice, try this https://github.com/apache/ignite/blob/master/examples/src/main/java/org/apache/ignite/examples/ml/dataset/AlgorithmSpecificDatasetExample.java[example] that is available on GitHub and delivered with every Apache Ignite distribution.
97

98

99

100

101

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.