dns: Memory usage issue cause dns stuck

In

func (srv *Server) serveDNS(w *response) {
	req := new(Msg)
	err := req.Unpack(w.msg)
	if err != nil { // Send a FormatError back
		x := new(Msg)
		x.SetRcodeFormatError(req)
		w.WriteMsg(x)
		return
	}
	if !srv.Unsafe && req.Response {
		return
	}

Every dns request would create a new dns msg object, this make DNS library occupy a lot of memory. Is it OK to change it use sync.Pool?

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 17 (5 by maintainers)

Most upvoted comments

I confirm the improvement in the e875a31 Thanks

[ Quoting notifications@github.com in “Re: [miekg/dns] Memory usage issue …” ]

Copy the data to a smaller slice triggered by lower utilization of the Rx buffer:

	if 2*n < srv.UDPSize {
		m1 := make([]byte, n)
		Copy(m1, m)
		m = m1
	} else {
		m = m[:n]
	}

So, to safe memory we are going to copy it twice?