Permalink
Cannot retrieve contributors at this time
56 lines (47 sloc)
1.29 KB
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
statsd-filter-proxy-rs/benchmark/statsd-filter-proxy.js /
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // This is the original implementation of statsd-filter-proxy. It is a very | |
| // tiny nodejs program with decent performance characteristics. This version | |
| // is used as the performance baseline. If the Rust version is slower than | |
| // Nodejs, then we are probably doing it wrong. | |
| const udp = require('dgram'); | |
| const server = udp.createSocket('udp4'); | |
| const client = udp.createSocket('udp4'); | |
| const config = { | |
| listenPort: 8125, | |
| forward: { | |
| host: '127.0.0.1', | |
| port: 8126, | |
| }, | |
| metricBlocklist: [ | |
| "foo" | |
| ] | |
| } | |
| function blacklistMetric(metric) { | |
| for (const substring of config.metricBlocklist) { | |
| if (metric.includes(substring)) { | |
| return true; | |
| } | |
| } | |
| return false; | |
| } | |
| server.on('message', (msg) => { | |
| if (blacklistMetric(msg)) { | |
| return; | |
| } | |
| client.send(msg, config.forward.port, config.forward.host, (error) => { | |
| if (error) { | |
| console.log(`Unable to forward datagram to ${config.forward}, ${error}`); | |
| process.exit(-1); | |
| } | |
| }); | |
| }); | |
| server.on('listening', () => { | |
| console.log(`Listening at ${server.address().address}:${server.address().port}`); | |
| }); | |
| server.on('close', () => { | |
| console.log('UDP server socket is closed'); | |
| }); | |
| server.on('error', (error) => { | |
| console.warn(`UDP server Error: ${error}`); | |
| server.close(); | |
| }); | |
| server.bind(config.listenPort); |