We fixed the problem.
In the end, the solution was quite simple. Since there was so many duplicates (mostly MAC addresses and with combination with SN and hostname) server simply couldnt handle the requests in time... php, apache, nginx proxy all had too low timeout.
So we increased the timeouts, merged duplicates and now it works normally and fast.
Now to fix the cause of duplicates.
Thanks pchamorro for trying to help, I do appreciate it.