Reduce TCP listener allocations

This commit is contained in:
Cameron Sparr 2016-04-05 14:35:14 -06:00
parent 30464396d9
commit 0f16c0f4cf
2 changed files with 6 additions and 5 deletions

View File

@ -2,6 +2,7 @@
### Features ### Features
- [#976](https://github.com/influxdata/telegraf/pull/976): Reduce allocations in the UDP and statsd inputs. - [#976](https://github.com/influxdata/telegraf/pull/976): Reduce allocations in the UDP and statsd inputs.
- [#979](https://github.com/influxdata/telegraf/pull/979): Reduce allocations in the TCP listener.
### Bugfixes ### Bugfixes
- [#968](https://github.com/influxdata/telegraf/issues/968): Processes plugin gets unknown state when spaces are in (command name) - [#968](https://github.com/influxdata/telegraf/issues/968): Processes plugin gets unknown state when spaces are in (command name)

View File

@ -39,7 +39,7 @@ type TcpListener struct {
acc telegraf.Accumulator acc telegraf.Accumulator
} }
var dropwarn = "ERROR: Message queue full. Discarding line [%s] " + var dropwarn = "ERROR: Message queue full. Discarding metric. " +
"You may want to increase allowed_pending_messages in the config\n" "You may want to increase allowed_pending_messages in the config\n"
const sampleConfig = ` const sampleConfig = `
@ -202,11 +202,10 @@ func (t *TcpListener) handler(conn *net.TCPConn, id string) {
if !scanner.Scan() { if !scanner.Scan() {
return return
} }
buf := scanner.Bytes()
select { select {
case t.in <- buf: case t.in <- scanner.Bytes():
default: default:
log.Printf(dropwarn, string(buf)) log.Printf(dropwarn)
} }
} }
} }
@ -215,11 +214,12 @@ func (t *TcpListener) handler(conn *net.TCPConn, id string) {
// tcpParser parses the incoming tcp byte packets // tcpParser parses the incoming tcp byte packets
func (t *TcpListener) tcpParser() error { func (t *TcpListener) tcpParser() error {
defer t.wg.Done() defer t.wg.Done()
var packet []byte
for { for {
select { select {
case <-t.done: case <-t.done:
return nil return nil
case packet := <-t.in: case packet = <-t.in:
if len(packet) == 0 { if len(packet) == 0 {
continue continue
} }