totpero / DeviceDetector.NET

The Universal Device Detection library will parse any User Agent and detect the browser, operating system, device used (desktop, tablet, mobile, tv, cars, console, etc.), brand and model.
Apache License 2.0
343 stars 73 forks source link

Extremely slow performance on occassion #47

Open majkinetor opened 3 years ago

majkinetor commented 3 years ago

Hi there.

We noticed 1 to 2 times per day that login lasts around 12s due to agent parsing. This is a graph in last 7 days in which you can see 9 peaks between 10 and 12s and and 5 peaks at around 2s:

image

Otherwise, its around 150ms. We have 10k cache enabled.

Any idea what could go wrong or how to troubleshoot this ? I really like the library but this things is a deal breaker. This is observed on our test web app environment which has very low number of logins per day (around 100).

sanchezzzhak commented 3 years ago

maybe try to implement the indexing of the device brand? this reduces the number of iterations in the loop for known devices to 1 step instead of a full pass. https://github.com/sanchezzzhak/node-device-detector/blob/523097d122e6f8a0766ef2f2cacf2e58c7ef30da/index.js#L475-L477

indexing generator itself is located here https://github.com/sanchezzzhak/node-device-detector/blob/master/tests/tools/generate-indexes.js

this may help, it helped me to reduce count of CPU% and reduced the response for well known brands