請求日誌寫入 kafka 上線後,發現線上一直報警:請求總耗時過長。 而後就去測試了一下操做請求日誌的那個函數的耗時,結果是讓我挺驚訝的,最長耗時達到了 300ms,最重要的是這個函數影響了全局的接口請求(全部的請求都要通過該函數) 當時增長新操做就直接往函數里加,沒有考慮到會如此耗時,大概加了三四個動做吧。python
既然這個函數如此耗時,那麼就直接將這個函數異步咯。想法聽上去好像是完美的,然而現實是殘酷的。bash
單位是微秒異步
print access log cost time: 175002
print access log cost time: 18812
print access log cost time: 32655
print access log cost time: 60613
print access log cost time: 57820
print access log cost time: 6242
print access log cost time: 5541
print access log cost time: 17026
print access log cost time: 19471
複製代碼
print access log cost time: 62
print access log cost time: 61
print access log cost time: 67
print access log cost time: 87
print access log cost time: 60
print access log cost time: 149
print access log cost time: 79
print access log cost time: 58
print access log cost time: 65
複製代碼