Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ISSUE#89]Add nats driver #98

Merged
merged 5 commits into from
Oct 19, 2018
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions benchmark-framework/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,11 @@
<artifactId>driver-bookkeeper</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>driver-nats</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>org.apache.bookkeeper.stats</groupId>
Expand Down
3 changes: 3 additions & 0 deletions driver-nats/deploy/ansible.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[defaults]
host_key_checking=false
private_key_file=alicloud.pem
123 changes: 123 additions & 0 deletions driver-nats/deploy/deploy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
#
# 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.
#


- name: Install NATS Cluster
hosts: nats
connection: ssh
tasks:
- set_fact:
natsHostUrl: "{{ hostvars[groups['nats'][0]].private_ip }}"
- name: Install RPM packages
yum: pkg={{ item }} state=latest
with_items:
- wget
- unzip

- file: path=/opt/nats state=absent
- file: path=/opt/nats state=directory
- name: Install Nats Server
unarchive:
src: "https://github.com/nats-io/gnatsd/releases/download/v1.3.0/gnatsd-v1.3.0-linux-amd64.zip"
remote_src: yes
dest: /opt/nats
# extra_opts: ["--strip-components=1"]
- template:
src: "templates/cluster.conf"
dest: "/opt/nats/cluster.conf"
- template:
src: "templates/nats-server.service"
dest: "/etc/systemd/system/nats-server.service"
- replace:
dest: /opt/nats/cluster.conf
regexp: 'natsHostUrl'
replace: '{{natsHostUrl}}'
- replace:
dest: /opt/nats/cluster.conf
regexp: 'localhost'
replace: '{{natsHostUrl}}'
- systemd:
state: started
daemon_reload: yes
name: "nats-server"


- name: benchmarking client setup
hosts: client
connection: ssh
become: true
tasks:
- set_fact:
natsHostUrl: "{{ hostvars[groups['nats'][0]].private_ip }}"
- name: Install RPM packages
yum: pkg={{ item }} state=latest
with_items:
- java
- name: Copy benchmark code
unarchive:
src: ../../package/target/openmessaging-benchmark-0.0.1-SNAPSHOT-bin.tar.gz
dest: /opt
- shell: rm -rf /opt/benchmark/
- shell: mv /opt/openmessaging-benchmark-0.0.1-SNAPSHOT /opt/benchmark
- shell: tuned-adm profile latency-performance
- template:
src: "templates/workers.yaml"
dest: "/opt/benchmark/workers.yaml"
- name: Get list of driver config files
raw: ls -1 /opt/benchmark/driver-rabbitmq/*.yaml
register: drivers_list
- template:
src: "templates/nats.yaml"
dest: "/opt/benchmark/driver-nats/nats.yaml"
- name: Configure natsHost URL
lineinfile:
dest: /opt/benchmark/driver-nats/nats.yaml
regexp: '^natsHostUrl\: '
line: 'natsHostUrl: nats://{{natsHostUrl}}:4222'
- name: Configure memory
lineinfile:
dest: /opt/benchmark/bin/benchmark-worker
regexp: '^JVM_MEM='
line: 'JVM_MEM="-Xms12G -Xmx12G -XX:+UseG1GC -XX:MaxGCPauseMillis=10 -XX:+ParallelRefProcEnabled -XX:+UnlockExperimentalVMOptions -XX:+AggressiveOpts -XX:+DoEscapeAnalysis -XX:ParallelGCThreads=32 -XX:ConcGCThreads=32 -XX:G1NewSizePercent=50 -XX:+DisableExplicitGC -XX:-ResizePLAB -XX:+PerfDisableSharedMem -XX:+AlwaysPreTouch -XX:-UseBiasedLocking"'
- name: Configure memory
lineinfile:
dest: /opt/benchmark/bin/benchmark
regexp: '^JVM_MEM='
line: 'JVM_MEM="-Xmx4G"'
- name: Install benchmark systemd service
template:
src: "templates/benchmark-worker.service"
dest: "/etc/systemd/system/benchmark-worker.service"
- systemd:
state: restarted
daemon_reload: yes
name: "benchmark-worker"


- name: List host addresses
hosts: localhost
become: false
tasks:
- debug:
msg: "nats brokers {{ item }}"
with_items: "{{ groups['nats'] }}"
- debug:
msg: "Benchmark client {{ item }}"
with_items: "{{ groups['client'] }}"

109 changes: 109 additions & 0 deletions driver-nats/deploy/provision-rabbitmq-aws.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
provider "alicloud" {
region = "${var.region}"
}

variable "region" {}
variable "private_key_file" {}
variable "key_name" {}
variable "image_id" {}
variable "availability_zone" {}
variable "instance_types" {
type = "map"
}

variable "num_instances" {
type = "map"
}

resource "alicloud_vpc" "vpc" {
name = "vpc_for_nats"
cidr_block = "172.16.0.0/12"
}

resource "alicloud_vswitch" "vswitch" {
name = "subnet_for_nats"
vpc_id = "${alicloud_vpc.vpc.id}"
cidr_block = "172.16.0.0/21"
availability_zone = "${var.availability_zone}"
}

# Create security group
resource "alicloud_security_group" "default" {
name = "group_for_nats"
provider = "alicloud"
description = "default"
vpc_id = "${alicloud_vpc.vpc.id}"
}

resource "alicloud_security_group_rule" "allow_all_tcp" {
type = "ingress"
ip_protocol = "tcp"
nic_type = "intranet"
policy = "accept"
port_range = "1/65535"
priority = 1
security_group_id = "${alicloud_security_group.default.id}"
cidr_ip = "0.0.0.0/0"
}
resource "alicloud_security_group_rule" "allow_all_tcp1" {
type = "ingress"
ip_protocol = "tcp"
nic_type = "intranet"
policy = "accept"
port_range = "1/65535"
priority = 1
security_group_id = "${alicloud_security_group.default.id}"
cidr_ip = "0.0.0.0/0"
}
resource "alicloud_instance" "nats" {
provider = "alicloud"
image_id = "${var.image_id}"
availability_zone = "${var.availability_zone}"

internet_charge_type = "PayByBandwidth"

instance_type = "${var.instance_types["nats"]}"
security_groups = ["${alicloud_security_group.default.id}"]
vswitch_id = "${alicloud_vswitch.vswitch.id}"
internet_max_bandwidth_out = "1"
system_disk_category = "cloud_ssd"
system_disk_size = "500"
count = "${var.num_instances["nats"]}"
key_name = "${alicloud_key_pair.key_pair.id}"
instance_name = "nats-${count.index}"
password = "Ali123456"
}

resource "alicloud_instance" "client" {
provider = "alicloud"
image_id = "${var.image_id}"
internet_charge_type = "PayByBandwidth"
availability_zone = "${var.availability_zone}"
instance_type = "${var.instance_types["client"]}"
security_groups = ["${alicloud_security_group.default.id}"]
vswitch_id = "${alicloud_vswitch.vswitch.id}"
internet_max_bandwidth_out = "1"
count = "${var.num_instances["client"]}"
key_name = "${alicloud_key_pair.key_pair.id}"
system_disk_category = "cloud_ssd"
instance_name = "nats-client-${count.index}"
}


resource "alicloud_key_pair" "key_pair" {
key_name = "${var.key_name}"
key_file = "${var.private_key_file}"
}

output "broker_host" {
value = "${alicloud_instance.nats.*.public_ip}"
}


output "client_host" {
value = "${alicloud_instance.client.*.public_ip}"
}

output "client_ssh_host" {
value = "${alicloud_instance.client.0.public_ip}"
}
14 changes: 14 additions & 0 deletions driver-nats/deploy/templates/benchmark-worker.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[Unit]
Description=benchmark worker
After=network.target

[Service]
ExecStart=/opt/benchmark/bin/benchmark-worker
WorkingDirectory=/opt/benchmark
RestartSec=1s
Restart=on-failure
Type=simple
LimitNOFILE=300000

[Install]
WantedBy=multi-user.target
26 changes: 26 additions & 0 deletions driver-nats/deploy/templates/cluster.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

#
# 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.
#

# Cluster Seed Node
listen: localhost:4222
http: 8222
cluster {
listen: natsHostUrl:4248
}
14 changes: 14 additions & 0 deletions driver-nats/deploy/templates/nats-server.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[Unit]
Description=nats broker
After=network.target

[Service]
ExecStart=/opt/nats/gnatsd-v1.3.0-linux-amd64/gnatsd -c /opt/nats/cluster.conf
WorkingDirectory=/opt/nats/
RestartSec=1s
Restart=on-failure
Type=simple
LimitNOFILE=300000

[Install]
WantedBy=multi-user.target
31 changes: 31 additions & 0 deletions driver-nats/deploy/templates/nats.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#
# 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.
#


name: Nats
driverClass: io.openmessaging.benchmark.driver.nats.NatsBenchmarkDriver

# RabbitMq client specific configurations

workers:
{% for worker in groups['nats'] %}
- nats://{{ hostvars[worker].private_ip }}:4222
{% endfor %}

natsHostUrl: nats://localhost:4222
24 changes: 24 additions & 0 deletions driver-nats/deploy/templates/workers.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#
# 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.
#


workers:
{% for worker in groups['client'] %}
- http://{{ hostvars[worker].private_ip }}:8080
{% endfor %}
15 changes: 15 additions & 0 deletions driver-nats/deploy/terraform.tfvars
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
region = "cn-shenzhen"
availability_zone = "cn-shenzhen-c"
private_key_file = "alicloud.pem"
key_name = "key-pair-from-terraform-nats"
image_id = "centos_7_04_64_20G_alibase_201701015.vhd"

instance_types = {
"nats" = "ecs.se1.4xlarge" #4c16g
"client" = "ecs.n4.4xlarge"
}

num_instances = {
"nats" = 1
"client" = 2
}