Github user tweise commented on a diff in the pull request:
https://github.com/apache/incubator-apex-core/pull/324#discussion_r62100615
--- Diff: docs/application_development.md ---
@@ -1732,6 +1732,84 @@ the network card.
THREAD_LOCAL and CONTAINER_LOCAL streams do not use a buffer
server as this stream is in a single process. The other two do.
+Affinity Rules
+------------------
+Affinity Rules in Apex provide a way to specify hints on how operators
should be deployed in a cluster. Sometimes you may want to allocate certain
operators on the same or different nodes for performance or other reasons.
Affinity rules can be used in such cases to make sure these considerations are
honored by platform.
+
+There can be two types of rules: Affinity and Anti-affinity rules.
Affinity rule indicates that group of operators in the rule should be allocated
together. On the other hand, anti-affinity rule indicates that the group of
operators should be allocated separately.
+
+### Specifying Affinity Rules
+A list of Affinity Rules can be specified for an application by setting
attribute: DAGContext.AFFINITY_RULES_SET.
+Here is code snippet for setting Affinity rules for an application in
populateDag method:
+```java
+AffinityRulesSet ruleSet = new AffinityRulesSet();
+List<AffinityRule> rules = new ArrayList<>();
+// Add Affinity rules as per requirement
+rules.add(new AffinityRule(Type.ANTI_AFFINITY, Locality.NODE_LOCAL, false,
"rand", "operator1", "operator2"));
+rules.add(new AffinityRule(Type.AFFINITY, Locality.CONTAINER_LOCAL, false,
"console", "rand"));
+ruleSet.setAffinityRules(rules);
+dag.setAttribute(DAGContext.AFFINITY_RULES_SET, ruleSet);
+```
+
+As shown in the example above, each rule has a type Affinity or
Anti_Affinity indicating whether operators in group should be allocated
together or separate. These can be applied on any operators in DAG.
--- End diff --
Please either use "affinity" or "anti-affiity" or the literal constants as
seen in the code snippet.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---