Skip to content

Commit

Permalink
Add playbooks for HammerDB
Browse files Browse the repository at this point in the history
These playbooks will set up servers to allow testing with HammerDB.
  • Loading branch information
mw2q committed Mar 2, 2021
1 parent 2ec629c commit 2573204
Show file tree
Hide file tree
Showing 22 changed files with 516 additions and 0 deletions.
5 changes: 5 additions & 0 deletions inventory.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,8 @@ all:
barman: true
barman_server_private_ip: xxx.xxx.xxx.xxx
barman_backup_method: postgres
hammerdbserver:
hosts:
hammerdb1:
ansible_host: xxx.xxx.xxx.xxx
private_ip: xxx.xxx.xxx.xxx
71 changes: 71 additions & 0 deletions plugins/lookup/hammerdb_server.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type

DOCUMENTATION = """
name: hammerdb_server
author: Mark Wong
short_description: Lookup HammerDB server, based on its private_ip
description:
- "Lookup HammerDB server, based on its private_ip"
options:
_terms:
description: Private IP of the HammerDB server.
required: False
default:
description: hammerdb_server_private_ip of the current node.
"""

EXAMPLES = """
- name: Show HammerDB server informations
debug: msg="{{ lookup('hammerdb_server') }}"
"""

RETURN = """
_value:
description:
- List of HammerDB server nodes
type: list
elements:
- dict: node_type, hostname, ansible_host (public IP address), private_ip
"""

from ansible.plugins.lookup import LookupBase


class LookupModule(LookupBase):
def run(self, terms, variables=None, **kwargs):

myvars = getattr(self._templar, '_available_variables', {})
inventory_hostname = variables['inventory_hostname']

# If no terms, we'll used the current HammerDB server private IP
if len(terms) == 0:
if 'hammerdb_server_private_ip' not in myvars['hostvars'][inventory_hostname]:
# hammerdb_server_private_ip not set, return None
return []
hammerdb_server_private_ip = myvars['hostvars'][inventory_hostname]['hammerdb_server_private_ip']
else:
hammerdb_server_private_ip = terms[0]

# If no hammerdbserver found in the inventory file, just return None
if 'hammerdbserver' not in variables['groups']:
return []
if len(variables['groups']['hammerdbserver']) == 0:
return []

# Lookup for hammerdb servers with a matching private_ip
for host in variables['groups']['hammerdbserver']:
hostvars = myvars['hostvars'][host]

if hostvars['private_ip'] != hammerdb_server_private_ip:
continue

return [
dict(
node_type='hammerdbserver',
ansible_host=hostvars['ansible_host'],
hostname=hostvars.get('hostname', hostvars['ansible_hostname']),
private_ip=hostvars['private_ip'],
inventory_hostname=hostvars['inventory_hostname']
)
]
12 changes: 12 additions & 0 deletions plugins/lookup/supported_roles.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@
'setup_repo',
'setup_barmanserver',
'install_dbserver'
],
'hammerdbserver': [
'setup_repo',
'setup_hammerdbserver'
]
}

Expand Down Expand Up @@ -106,4 +110,12 @@ def run(self, terms, variables=None, **kwargs):
set(supported_roles)
| set(['setup_barman'])
)
# Special case for the primary nodes when the host variable
# hammerdb is set to true.
if (group in ['primary']
and myvars['hostvars'][hostname].get('hammerdb', False)):
supported_roles = list(
set(supported_roles)
| set(['setup_hammerdb'])
)
return supported_roles
22 changes: 22 additions & 0 deletions roles/setup_hammerdb/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# setup_hammerdb

This role is for installing HammerDB.

## Requirements

Following are the requirements of this role.
1. Ansible
2. `edb_devops.edb_postgres` -> `setup_repo` role for setting the repository on
the systems.

## License

BSD

## Author information

Author:

* Mark Wong
* EDB Postgres
* [email protected] www.enterprisedb.com
5 changes: 5 additions & 0 deletions roles/setup_hammerdb/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---

supported_os:
- CentOS8
- RHEL8
22 changes: 22 additions & 0 deletions roles/setup_hammerdb/meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
galaxy_info:
author: EDB
description: Setup HammerDB
company: "EnterpriseDB"

license: BSD

min_ansible_version: 2.8

platforms:
- name: CentOS
versions:
- 8
- name: Red Hat
versions:
- 8

galaxy_tags:
- database

dependencies: []
35 changes: 35 additions & 0 deletions roles/setup_hammerdb/tasks/configure_postgres_params.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---

- name: Update PostgreSQL parameters for TPROC-C
include_role:
name: manage_dbserver
tasks_from: manage_postgres_params
vars:
pg_postgres_conf_params:
- name: max_connections
value: 300
- name: shared_buffers
value: "16384MB"
- name: work_mem
value: "64MB"
- name: maintenance_work_mem
value: "620MB"
- name: effective_cache_size
value: "45 GB"
- name: random_page_cost
value: 1.25
- name: effective_io_concurrency
value: 200
- name: checkpoint_timeout
value: "15min"
- name: checkpoint_completion_target
value: 0.9
- name: max_wal_size
value: "30GB"
- name: min_wal_size
value: "10GB"
- name: wal_buffers
value: "512MB"
- name: jit
value: on
no_log: "{{ disable_logging }}"
31 changes: 31 additions & 0 deletions roles/setup_hammerdb/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---

- name: Include the HBA file update tasks
include_tasks: update_pg_hba.yml

- name: Include Postgres configuration for TPROC-C
include_tasks: configure_postgres_params.yml

- name: Include HammerDB installation
include_role:
name: setup_hammerdbserver
tasks_from: install_hammerdb

- name: Include Touchstone installation
include_role:
name: setup_touchstone
tasks_from: main

- name: Create TPROC-C loader.tcl
template:
dest: loader.tcl
src: ./templates/loader.tcl.template
mode: 0644
become: no

- name: Create TPROC-C load script
template:
src: ./templates/load-tproc-c.template
dest: /usr/local/bin/load-tproc-c
mode: 0755
become: yes
35 changes: 35 additions & 0 deletions roles/setup_hammerdb/tasks/update_pg_hba.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---

- name: Reference pg_type variables
include_vars: "{{ role_path }}/../init_dbserver/vars/{{ pg_type }}.yml"

- name: Initialize the hba_entries variable
set_fact:
hba_entries: >-
[
{
'users': 'all',
'databases': 'all',
'contype': 'host',
'source': '{{ hostvars[inventory_hostname].hammerdb_server_private_ip | default("127.0.0.1") }}/32',
'method': 'trust'
},
{
'users': 'all',
'databases': 'all',
'contype': 'host',
'source': '{{ hostvars['primary1'].private_ip | default("127.0.0.1") }}/32',
'method': 'trust'
}
]
- name: Allow access from the hammerdb server
include_role:
name: manage_dbserver
tasks_from: manage_hba_conf
vars:
pg_hba_ip_addresses: "{{ hba_entries }}"

- name: Reset hba_entries
set_fact:
hba_entries: []
7 changes: 7 additions & 0 deletions roles/setup_hammerdb/templates/load-tproc-c.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/sh
(cd ${HOME}/HammerDB-{{ hammerdb_version }} && \
./hammerdbcli << !
source ${HOME}/loader.tcl
!
)
echo "load complete"
16 changes: 16 additions & 0 deletions roles/setup_hammerdb/templates/loader.tcl.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env tclsh
global complete
proc wait_to_complete {} {
global complete
set complete [vucomplete]
if {!$complete} {after 5000 wait_to_complete} else { exit }
}
dbset db pg
diset connection pg_host {{ hostvars['primary1'].private_ip }}
diset connection pg_port {{ pg_port }}
diset tpcc pg_count_ware 600
diset tpcc pg_num_vu {{ ansible_processor_vcpus }}
diset tpcc pg_raiseerror true
diset tpcc pg_superuser postgres
buildschema
wait_to_complete
42 changes: 42 additions & 0 deletions roles/setup_hammerdbserver/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@

# setup_hammerdbserver

This role is for setting up a server for [HammerDB](https://hammerdb.com/).
HammerDB is the leading benchmarking and load testing software for the worlds
most popular databases.

## Requirements

Following are the requirements of this role.
1. Ansible
2. `edb_devops.edb_postgres` -> `setup_repo` role for setting the repository
on the systems.

## Role Variables

The variables that can be configured and are available in the:

* [roles/setup_hammerdbserver/defaults/main.yml](./defaults/main.yml)

Below is the documentation of the rest of the main variables:

### `hammerdb_version`

The release version of HammerDB. Default: 3.3

Example:
```yaml
hammerdb_version: 3.3
```
## License
BSD
## Author information
Author:
* Mark Wong
* EDB Postgres
* [email protected] www.enterprisedb.com
6 changes: 6 additions & 0 deletions roles/setup_hammerdbserver/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---

hammerdb_version: 3.3
supported_os:
- CentOS8
- RHEL8
22 changes: 22 additions & 0 deletions roles/setup_hammerdbserver/meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
galaxy_info:
author: EDB
description: Setup HammerDB server
company: "EnterpriseDB"

license: BSD

min_ansible_version: 2.8

platforms:
- name: CentOS
versions:
- 8
- name: Red Hat
versions:
- 8

galaxy_tags:
- database

dependencies: []
9 changes: 9 additions & 0 deletions roles/setup_hammerdbserver/tasks/install_hammerdb.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---

- name: Download HammerDB
raw: curl -OL https://github.com/TPC-Council/HammerDB/releases/download/v{{ hammerdb_version }}/HammerDB-{{ hammerdb_version }}-Linux.tar.gz
become: no

- name: Install HammerDB
raw: tar -xvf HammerDB-{{ hammerdb_version }}-Linux.tar.gz
become: no
Loading

0 comments on commit 2573204

Please sign in to comment.