Matomo archive getting http 504 error

Hi, we are getting 504 gateway time out on the site id’s that have the most traffic.
It is probably due to timeouts on php, does anyone experiencing the same?

Matomo version: Matomo 3.13.4

Error: Error unserializing the following response from ?module=API&method=API.get&idSite=2&period=year&date=last2&format=php&trigger=archivephp: <html>^M <head><title>504 Gateway Time-out</title></head>^M <body>^M <center><h1>504 Gateway Time-out</h1></center>^M <hr><center>nginx</center>^M </body>^M </html>
INFO [2020-04-23 09:40:51] 14202  Error: Empty or invalid response '<html>^M <head><title>504 Gateway Time-out</title></head>^M <body>^M <center><h1>504 Gateway Time-out</h1></center>^M <hr><center>nginx</center>^M </body>^M </html>' for website id 23, Time elapsed: 600.306s, skipping
INFO [2020-04-23 09:40:51] 14202  Error: Error unserializing the following response from ?module=API&method=API.get&idSite=24&period=week&date=last2&format=php&trigger=archivephp: <html>^M <head><title>502 Bad Gateway</title></head>^M <body>^M <center><h1>502 Bad Gateway</h1></center>^M <hr><center>nginx</center>^M </body>^M </html>
INFO [2020-04-23 09:40:51] 14202  Error: Error unserializing the following response from ?module=API&method=API.get&idSite=26&period=week&date=last2&format=php&trigger=archivephp: <html>^M <head><title>502 Bad Gateway</title></head>^M <body>^M <center><h1>502 Bad Gateway</h1></center>^M <hr><center>nginx</center>^M </body>^M </html>

php errors:
[23-Apr-2020 10:37:36 UTC] PHP Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 1205 Lock wait timeout exceeded; try restarting transaction in /apps/matomo/matomo/libs/Zend/Db/Statement/Pdo.php:228

Which version von Matomo are you using at the moment?