lots of async at once cause strange backoff delay of 5s
nightshade427 opened this issue · comments
When you do lots of async at once for some reason when using latest cl-async master that uses libuv there is a strange backoff of 5s. When doing the same with the older libevent cl-async it didnt do that it just ran all 100 at same time and was MUCH faster as a result.
Diff is responses of over 3 minutes in master cl-async vs 200ms in libevent cl-async for my typical use cases.
repo:
(as:with-event-loop (:catch-app-errors t)
(bb:catcher
(bb:alet ((result (bb:amap #'(lambda (item)
(format t "~&starting")
(bb:alet* ((start (get-internal-real-time))
(value (carrier:request "https://www.firma8.com/" :return-body t)\
)
(end (get-internal-real-time)))
(format t "~&done request: ~s" (* 1.0 (/ (- end start) internal-time-units\
-per-second)))
value))
(iter:iter (iter:for i from 0 to 100)
(iter:collect i)))))
(format t "~&result: ~s" result))
(t (e) (format t "~&error: ~a" e))))
done request: 0.35
done request: 0.352
done request: 0.357
done request: 0.359
done request: 0.358
done request: 0.36
done request: 0.364
done request: 0.366
done request: 0.368
done request: 5.124
done request: 5.127
done request: 5.129
done request: 5.136
done request: 10.128
done request: 10.139
done request: 10.147
done request: 10.146
done request: 15.136
done request: 15.139
done request: 15.14
done request: 15.142
done request: 20.142
done request: 20.145
done request: 20.151
done request: 20.153
done request: 25.143
done request: 25.146
done request: 25.15
done request: 25.161
done request: 30.165
done request: 30.166
done request: 30.174
done request: 30.176
Found the issue. It is dns look-ups or something. If I replace "www.firma8.com" above with ip instead of host it runs all blazing fast like libevent one does. I will have to take a look at how dns is getting resolved.
This is obeying os level DNS using getaddrinfo so I'm closing this out. I will either cache DNS locally in app or use nscd.
I'm willing to bet that libevent was caching DNS internally. I'd rather not get into this space in cl-async (I don't even know if libuv exposes TTL so we couldn't cache correctly anyway). As you mentioned, it should be fairly easy to do this yourself though, depending on your requirements.
Agreed :)