I was playing with the https://github.com/streadway/amqp library today and had a rough implementation working based of the example here. It was working ok when using the domain name although for connecting to a vagrant box on my local machine it was taking fairly long. The issue came when I added in the functionality to also send a JSON request to that same server I ran into all kinds of timeout issues mostly related to rabbitmq closing a connection because it was waiting so long.
So i ran this following code to see if i could isolate the issue.
package main
import (
"log"
"net/http"
"time"
)
func main() {
start := time.Now()
_, err := http.Get("http://local.test.dev/test")
if err != nil {
log.Println("%s", err.Error())
}
log.Printf("Time: %v", time.Since(start))
}
This resulted in the somewhat surprising output of this after running a few tests.
2015/02/09 01:27:33 Time: 1.131834476s
2015/02/09 01:27:37 Time: 828.873332ms
2015/02/09 01:27:40 Time: 862.059803ms
2015/02/09 01:27:41 Time: 207.781482ms
2015/02/09 01:27:43 Time: 810.567042ms
2015/02/09 01:27:45 Time: 197.555383ms
2015/02/09 01:27:55 Time: 776.675657ms
here is what the traceroute command looked like to make sure it wasn't some other issue.
traceroute to local.test.dev (192.168.56.101), 64 hops max, 52 byte packets
1 local.test.dev (192.168.56.101) 0.368 ms 0.430 ms 0.252 ms
I also tried the same snip-it from above but with the IP instead. It is only about 60ms faster which i find surprising but leads me to think the issue is not the net/http package but with the amqp library. The only place that I am using a domain name in the amqp library is for the following call.
amqp.Dial(amqpURI)
Does go have an issue with using domain names? Other than that I can't think of what could be causing the lookup time to take so long.
EDIT: I thought this was a DNS issue at first but after playing around with IP vs domain name it seems that is not the case. Also amqp Dial does not seem to be the issue. It only takes 4ms to return a connection. This leaves only channel.Consume as the culprit. going to throw together some isolated sample code and update...