ruby-kafka-ec2 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d731fe0da3282726a8bb898f98f0ab3fe0133463662d9e7bc3c536c965bfc278
|
4
|
+
data.tar.gz: e260eb39399056cc48cdf8b7b985b037cdb60eafc8f495771d7949e7eb581a52
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3f31a1d280d2f49b864fbc4068a4f198952180101973d2a93c708ff621238f83476dac72e8c302427f3413a6a9761f81b5a703b8020aee3edba5bf2a42e0a967
|
7
|
+
data.tar.gz: 9d4cda171d25754e42bda7a90c4d7b9c8a77fa8fc984a5546ccb1cbc10b4ccf10999f75c6dbaa7ecd4fdecdde285a3ccec0ead4071326564f6527382853edbe0
|
data/README.md
CHANGED
@@ -77,6 +77,48 @@ consumer = Kafka::EC2.with_assignment_strategy_factory(assignment_strategy_facto
|
|
77
77
|
end
|
78
78
|
```
|
79
79
|
|
80
|
+
You can also specify weights for each combination of availability zones and instance families:
|
81
|
+
|
82
|
+
```ruby
|
83
|
+
assignment_strategy_factory = Kafka::EC2::MixedInstanceAssignmentStrategyFactory.new(
|
84
|
+
weights: ->() {
|
85
|
+
db_cluster = rds.describe_db_clusters(filters: [
|
86
|
+
{ name: "db-cluster-id", values: [ENV["RDS_CLUSTER"]] },
|
87
|
+
]).db_clusters.first
|
88
|
+
db_instance_id = db_cluster.db_cluster_members.find { |m| m.is_cluster_writer }.db_instance_identifier
|
89
|
+
db_instance = rds.describe_db_instances(filters: [
|
90
|
+
{ name: "db-cluster-id", values: [ENV["RDS_CLUSTER"]] },
|
91
|
+
{ name: "db-instance-id", values: [db_instance_id] },
|
92
|
+
]).db_instances.first
|
93
|
+
|
94
|
+
weights_for_writer_az = {
|
95
|
+
"r4" => 1.00,
|
96
|
+
"r5" => 1.20,
|
97
|
+
"m5" => 1.35,
|
98
|
+
"c5" => 1.50,
|
99
|
+
}
|
100
|
+
weights_for_other_az = {
|
101
|
+
"r4" => 0.40,
|
102
|
+
"r5" => 0.70,
|
103
|
+
"m5" => 0.80,
|
104
|
+
"c5" => 1.00,
|
105
|
+
}
|
106
|
+
if db_instance.availability_zone == "ap-northeast-1a"
|
107
|
+
{
|
108
|
+
"ap-northeast-1a" => weights_for_writer_az,
|
109
|
+
"ap-northeast-1c" => weights_for_other_az,
|
110
|
+
}
|
111
|
+
else
|
112
|
+
{
|
113
|
+
"ap-northeast-1a" => weights_for_other_az,
|
114
|
+
"ap-northeast-1c" => weights_for_writer_az,,
|
115
|
+
}
|
116
|
+
end
|
117
|
+
},
|
118
|
+
)
|
119
|
+
```
|
120
|
+
|
121
|
+
|
80
122
|
## Development
|
81
123
|
|
82
124
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
@@ -18,10 +18,16 @@ module Kafka
|
|
18
18
|
# is the availability zone and whose value is the weight. If the object is a proc,
|
19
19
|
# it must returns such a hash and the proc is called every time the method "assign"
|
20
20
|
# is called.
|
21
|
-
|
21
|
+
# @param weights [Hash{String => Hash{String => Numeric}}, Proc] a hash whose the key
|
22
|
+
# is the availability zone or the instance family and whose value is the hash like
|
23
|
+
# instance_family_weights or availability_zone_weights. If the object is a proc,
|
24
|
+
# it must returns such a hash and the proc is called every time the method "assign"
|
25
|
+
# is called.
|
26
|
+
def initialize(cluster:, instance_family_weights: {}, availability_zone_weights: {}, weights: {})
|
22
27
|
@cluster = cluster
|
23
28
|
@instance_family_weights = instance_family_weights
|
24
29
|
@availability_zone_weights = availability_zone_weights
|
30
|
+
@weights = weights
|
25
31
|
end
|
26
32
|
|
27
33
|
# Assign the topic partitions to the group members.
|
@@ -38,12 +44,13 @@ module Kafka
|
|
38
44
|
|
39
45
|
instance_family_to_capacity = @instance_family_weights.is_a?(Proc) ? @instance_family_weights.call() : @instance_family_weights
|
40
46
|
az_to_capacity = @availability_zone_weights.is_a?(Proc) ? @availability_zone_weights.call() : @availability_zone_weights
|
47
|
+
weights = @weights.is_a?(Proc) ? @weights.call() : @weights
|
41
48
|
members.each do |member_id|
|
42
49
|
group_assignment[member_id] = Protocol::MemberAssignment.new
|
43
50
|
|
44
51
|
instance_id, instance_type, az = member_id_to_metadata[member_id].split(",")
|
45
52
|
instance_id_to_member_ids[instance_id] << member_id
|
46
|
-
capacity = calculate_capacity(instance_type, az, instance_family_to_capacity, az_to_capacity)
|
53
|
+
capacity = calculate_capacity(instance_type, az, instance_family_to_capacity, az_to_capacity, weights)
|
47
54
|
instance_id_to_capacity[instance_id] += capacity
|
48
55
|
total_capacity += capacity
|
49
56
|
end
|
@@ -86,9 +93,11 @@ module Kafka
|
|
86
93
|
|
87
94
|
private
|
88
95
|
|
89
|
-
def calculate_capacity(instance_type, az, instance_family_to_capacity, az_to_capacity)
|
96
|
+
def calculate_capacity(instance_type, az, instance_family_to_capacity, az_to_capacity, weights)
|
90
97
|
instance_family, _ = instance_type.split(".")
|
91
|
-
|
98
|
+
|
99
|
+
capacity = weights.dig(az, instance_family) || weights.dig(instance_family, az)
|
100
|
+
capacity || instance_family_to_capacity.fetch(instance_family, 1) * az_to_capacity.fetch(az, 1)
|
92
101
|
end
|
93
102
|
end
|
94
103
|
end
|
@@ -7,7 +7,9 @@ module Kafka
|
|
7
7
|
class MixedInstanceAssignmentStrategyFactory
|
8
8
|
# @param instance_family_weights [Hash, Proc]
|
9
9
|
# @param availability_zone_weights [Hash, Proc]
|
10
|
-
|
10
|
+
# @param weights [Hash, Proc]
|
11
|
+
# @see Kafka::EC2::MixedInstanceAssignmentStrategy#initialize
|
12
|
+
def initialize(instance_family_weights: {}, availability_zone_weights: {}, weights: {})
|
11
13
|
@instance_family_weights = instance_family_weights
|
12
14
|
@availability_zone_weights = availability_zone_weights
|
13
15
|
end
|
data/lib/kafka/ec2/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-kafka-ec2
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- abicky
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-07-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ruby-kafka
|