browser icon indicating copy to clipboard operation
browser copied to clipboard

Need Suggestion : CPU is reaching high at 50-60 tps

Open iRipulChhabra opened this issue 1 year ago • 7 comments

Hi @dineshgowda24

Thanks for creating this library. Just need your suggestion on the CPU usage. I am seeing very high CPU (~ 80% ) while I am on 50 TPS load test. If I remove the browser detection code. Its come to 10-15%. Did you test the lib against heavy traffic and experience anything like this?

FYI, I am using a 4 VCPU and 16G RAM machine to perform the test.

Example code which I use it for each http request to detect browser from UA.

b, err := browser.NewBrowser(ua)
if err != nil {
	return "unknown"
}
return b.Name()
}

iRipulChhabra avatar Feb 21 '25 07:02 iRipulChhabra

@dineshgowda24 Did you get a chance to look at it? any suggestions?

iRipulChhabra avatar Mar 17 '25 12:03 iRipulChhabra

Hey, are you creating a browser instance on each request?

dineshgowda24 avatar Mar 17 '25 18:03 dineshgowda24

@dineshgowda24 - I am calling the below function on each request. Is there any other way to use it? because, UA is different on each request.

func (r *Request) Browser() string {
	if r.UA != nil && r.UA != "" {
		b, err := browser.NewBrowser(r.UA)
		if err != nil {
			return "unknown"
		}
		return b.Name()
	}
	return "unknown"
}

iRipulChhabra avatar Mar 18 '25 07:03 iRipulChhabra

Oh yeah! It's been so long since I looked at it.

My suspicion is that since the instance is created on request, it might be causing CPU overhead. I will spend some time over the week validating the hypothesis by running some load tests and compute pprofs and then fixing it if that's the case.

dineshgowda24 avatar Mar 19 '25 10:03 dineshgowda24

Do u happen to have a flame graph?

dineshgowda24 avatar Mar 19 '25 10:03 dineshgowda24

@dineshgowda24 Please check this. Attaching the profiling file also

Image

cpu.txt - (added .txt extension just to upload the file, please remove it to use it with pprof tool)

iRipulChhabra avatar Mar 21 '25 05:03 iRipulChhabra

Hi @dineshgowda24 Did you get a chance to look at this? thanks

iRipulChhabra avatar Mar 25 '25 18:03 iRipulChhabra