Filippo Giunchedi has submitted this change and it was merged.

Change subject: Add a new statsd_proxy module and replace statsdlb
......................................................................


Add a new statsd_proxy module and replace statsdlb

statslb is a trivial program that is, thus, not very performant (it's a
single-threaded loop that calls recv(), hashes and sends ). I started
hacking on it to improve its performance, by for example adding multiple
threads or multiple processes (via SO_REUSEPORT) to it, or using epoll()
or recvmmsg(). While doing that, I felt a bit NIH and started Googling a
little bit, until I discovered statsd-proxy: a statsd proxy that someone
else wrote, that uses multiple threads with SO_REUSEPORTS, hashes using
a consistently hashing algorithm (Ketana), supports weights etc.

So, a Debian package, systemd unit, upstart job and puppet module later
(all trivial): replace statsdlb with a drop-in statsd_proxy replacement,
statically configured to use 4 threads for now. This should be a no-op
from the infrastructure PoV, just faster.

Bug: T126447
Change-Id: Ic0cbdf30f2785b6a0097089e3e9762178222cbb9
---
M manifests/role/statsd.pp
A modules/statsd_proxy/manifests/init.pp
A modules/statsd_proxy/templates/statsd-proxy.cfg.erb
3 files changed, 80 insertions(+), 8 deletions(-)

Approvals:
  Filippo Giunchedi: Verified; Looks good to me, approved



diff --git a/manifests/role/statsd.pp b/manifests/role/statsd.pp
index 5497b99..113956b 100644
--- a/manifests/role/statsd.pp
+++ b/manifests/role/statsd.pp
@@ -1,16 +1,26 @@
 # == Class: role::statsd
 #
-# Provisions a statsdlb instance that listens for StatsD metrics on
+# Provisions a statsd-proxy instance that listens for StatsD metrics
 # on UDP port 8125 and forwards to backends on UDP ports 8126+,
 # as well as the set of statsite backends that listen on these ports.
 #
 class role::statsd {
 
-    # statsdlb
-
     class { '::statsdlb':
+        ensure        => absent,
         server_port   => 8125,
         backend_ports => range(8126, 8131),
+        before        => Class['::statsd_proxy'],
+    }
+
+    class { '::statsd_proxy':
+        server_port   => 8125,
+        backend_ports => range(8126, 8131),
+    }
+
+    nrpe::monitor_service { 'statsd-proxy':
+        description  => 'statsd-proxy process',
+        nrpe_command => '/usr/lib/nagios/plugins/check_procs -c 1: -C 
statsd-proxy',
     }
 
     # load balancer frontend, backend ports 8126-8131 are only accessed from 
localhost
@@ -19,11 +29,6 @@
         port    => '8125',
         notrack => true,
         srange  => '$ALL_NETWORKS',
-    }
-
-    nrpe::monitor_service { 'statsdlb':
-        description  => 'statsdlb process',
-        nrpe_command => '/usr/lib/nagios/plugins/check_procs -c 1: -C 
statsdlb',
     }
 
     class { '::statsite': }
diff --git a/modules/statsd_proxy/manifests/init.pp 
b/modules/statsd_proxy/manifests/init.pp
new file mode 100644
index 0000000..4924a58
--- /dev/null
+++ b/modules/statsd_proxy/manifests/init.pp
@@ -0,0 +1,60 @@
+# == Class: statsd_proxy
+#
+# statsd-proxy is a StatsD-compatible proxy which routes metrics to multiple
+# local UDP ports. It consistently hashes metrics uses Ketama and is built for
+# high-performance.
+#
+#
+# === Parameters
+#
+# [*server_port*]
+#   UDP port to listen on. Example: 9001.
+#
+# [*backend_ports*]
+#   Array of local UDP ports to which incoming metrics should be routed.
+#   Example: [ 9002, 9003, 9004 ].
+#
+# [*threads*]
+#   Number of threads to spawn. Defaults to 4.
+#
+# === Examples
+#
+#  # Listen on UDP port 9001 and route to ports 9002-9004:
+#  class { 'statsd_proxy':
+#    server_port   => 9001,
+#    backend_ports => [ 9002, 9003, 9004 ],
+#  }
+#
+class statsd_proxy(
+    $ensure = present,
+    $threads = 4,
+    $server_port,
+    $backend_ports,
+) {
+    validate_ensure($ensure)
+    validate_array($backend_ports)
+    validate_re(join($backend_ports, ' '), '^\d+( \d+)*$', '$backend_ports 
must be an array of port numbers')
+    validate_re($server_port, '^\d+$', '$server_port must be a port number')
+
+    package { 'statsd-proxy':
+        ensure => $ensure,
+    }
+
+    file { '/etc/statsd-proxy.cfg':
+        ensure  => $ensure,
+        content => template('statsd_proxy/statsd-proxy.cfg.erb'),
+        owner   => 'root',
+        group   => 'root',
+        mode    => '0444',
+    }
+
+    service { 'statsd-proxy':
+        ensure    => ensure_service($ensure),
+        enable    => $ensure == 'present',
+        provider  => $::initsystem,
+        subscribe => [
+            Package['statsd-proxy'],
+            File['/etc/default/statsd-proxy'],
+        ],
+    }
+}
diff --git a/modules/statsd_proxy/templates/statsd-proxy.cfg.erb 
b/modules/statsd_proxy/templates/statsd-proxy.cfg.erb
new file mode 100644
index 0000000..1da7285
--- /dev/null
+++ b/modules/statsd_proxy/templates/statsd-proxy.cfg.erb
@@ -0,0 +1,7 @@
+port <%= @server_port %>
+num_threads <%= @threads %>
+flush_interval 10  # ms
+
+<%- @backend_ports.each do |port| -%>
+node 127.0.0.1:<%= port %> :1
+<% end %>

-- 
To view, visit https://gerrit.wikimedia.org/r/282356
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Ic0cbdf30f2785b6a0097089e3e9762178222cbb9
Gerrit-PatchSet: 3
Gerrit-Project: operations/puppet
Gerrit-Branch: production
Gerrit-Owner: Faidon Liambotis <fai...@wikimedia.org>
Gerrit-Reviewer: Filippo Giunchedi <fgiunch...@wikimedia.org>
Gerrit-Reviewer: Ori.livneh <o...@wikimedia.org>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to