dependency-track icon indicating copy to clipboard operation
dependency-track copied to clipboard

High Load on (PostgeSQL)DB after upgrade to 4.2.1

Open guruguruguru opened this issue 5 years ago • 31 comments

Hi together,

since we upgraded to 4.2.1 we see a very high load on our db server. The load is caused by the following statement:

SELECT $1 AS "DN_TYPE","A0"."AUTHOR","A0"."BLAKE2B_256","A0"."BLAKE2B_384","A0"."BLAKE2B_512","A0"."BLAKE3","A0"."CLASSIFIER","A0"."COPYRIGHT","A0"."CPE","A0"."DESCRIPTION","A0"."DIRECT_DEPENDENCIES","A0"."EXTENSION","A0"."FILENAME","A0"."GROUP","A0"."ID" AS "NUCORDER0","A0"."INTERNAL","A0"."LAST_RISKSCORE","A0"."LICENSE","A0"."MD5","A0"."NAME","A0"."TEXT","B0"."ACTIVE","B0"."AUTHOR","B0"."CLASSIFIER","B0"."CPE","B0"."DESCRIPTION","B0"."DIRECT_DEPENDENCIES","B0"."GROUP","B0"."ID","B0"."LAST_BOM_IMPORTED","B0"."LAST_BOM_IMPORTED_FORMAT","B0"."LAST_RISKSCORE","B0"."NAME","B0"."PUBLISHER","B0"."PURL","B0"."SWIDTAGID","B0"."UUID","B0"."VERSION","A0"."PUBLISHER","A0"."PURL","A0"."PURLCOORDINATES","C0"."FSFLIBRE","C0"."ID","C0"."LICENSEID","C0"."NAME","C0"."ISOSIAPPROVED","C0"."UUID","A0"."SHA1","A0"."SHA_256","A0"."SHA_384","A0"."SHA3_256","A0"."SHA3_384","A0"."SHA3_512","A0"."SHA_512","A0"."SWIDTAGID","A0"."UUID","A0"."VERSION" FROM "COMPONENT" "A0" INNER JOIN "PROJECT" "B0" ON "A0"."PROJECT_ID" = "B0"."ID" LEFT OUTER JOIN "LICENSE" "C0" ON "A0"."LICENSE_ID" = "C0"."ID" ORDER BY "NUCORDER0" OFFSET $2 ROWS FETCH NEXT $3 ROWS ONLY

This statements is fired ~14.000 times per hour.

The execution plan looks alright though but i am not sure what values are used for the parameters:

--------------------------------------------------------------------------------------------------------------------- Limit (cost=87.06..173.14 rows=100 width=9591) -> Nested Loop Left Join (cost=0.98..279289.71 rows=324443 width=9591) -> Nested Loop (cost=0.70..184548.91 rows=324443 width=9507) -> Index Scan using "COMPONENT_PK" on "COMPONENT" "A0" (cost=0.42..84801.68 rows=324443 width=6040) -> Index Scan using "PROJECT_PK" on "PROJECT" "B0" (cost=0.28..0.31 rows=1 width=3475) Index Cond: ("ID" = "A0"."PROJECT_ID") -> Index Scan using "LICENSE_PK" on "LICENSE" "C0" (cost=0.27..0.29 rows=1 width=88) Index Cond: ("ID" = "A0"."LICENSE_ID") (8 rows)

Do you have any idea? I was not sure if this qualifies as issue or question, if this is not an issue please close.

Regards, Dennis

guruguruguru avatar Apr 29 '21 10:04 guruguruguru

Was this statement not issued or not an issue with 4.0.0, 4.1.0, or 4.2.0?

stevespringett avatar Apr 29 '21 16:04 stevespringett

Hi @stevespringett ,

sorry I forgot to mention: we upgraded from 3.8.0, before there was no issue.

If we restart the app-container the problem vanishes until about 0:20 in the morning and then it starts again. Maybe it is just a failing configuration? A job that cannot finish?

Thanks, Dennis

guruguruguru avatar Apr 30 '21 10:04 guruguruguru

I guess its possible that many nightly builds are potentially overloading DT. Another possibility is an integration (e.g. vulnerability aggregation platform or BI tool) that is trying to extract a ton of data from DT for reporting on a scheduled basis.

Vulnerability analysis of all components in DT happens every 24 hours - not at a specific time. Its based on the last time DT was started. So if its restarted at 9am, then the following day at 9am, a vulnerability analysis would be performed again. So I don't think its that.

stevespringett avatar Apr 30 '21 15:04 stevespringett

@stevespringett Do you have any hint how to debug this? After a restart of the DT Container load stays very low until midnight. The it goes back to 30 and stays there until the next restart.

I (as DBA) could identify the above statement but I do not know much about the apllication.

Thanks a lot for helping!

guruguruguru avatar May 05 '21 11:05 guruguruguru

We found the cause of the issue: Deptrack has no stop condition (or probably a wrong one) for fetching the rows in batches. It tries to fetch rows starting from 25010000 while the table COMPONENT only has around 300k rows. The query then returns 0 results and Deptrack tries to fetch the next batch.

lusor avatar May 05 '21 13:05 lusor

DT relies on datanucleus for a persistence layer. The DT REST API allows for pagination. Any API call can fetch the range they want. So its possible that an integration (e.g. BI tool) is causing the issue.

The server does do some internal pagination for some calls as well, so its possible this logic is wrong. But I'll need to know where to look. WRT the application logs, where does the statement get executed? Is it executing when performing a vulnerability analysis, when its updating metrics, or some other task?

stevespringett avatar May 05 '21 13:05 stevespringett

@stevespringett

after looking into the logs of the api-server container I've seen, that a "MetricsUpdateTask" is running.

` 12:37:11.220 INFO [MetricsUpdateTask] Executing metrics update for project: 9c06ec5f-dff2-46c8-88eb-2a108fb9c787

13:01:20.610 INFO [MetricsUpdateTask] Completed metrics update for project: 9c06ec5f-dff2-46c8-88eb-2a108fb9c787 `

Also we are getting an error which we have never seen before:

ERROR [Cache] >> EC.preCommit L1Cache op IS NULL!

I hope these logs are helping you. If not, let me know where I should search for more detailed logs / which kind of logs you prefer.

kekkegenkai avatar May 05 '21 13:05 kekkegenkai

Thanks @kekkegenkai . I'll take a look a the metrics logic and ensure there isn't any logic flows around db pagination.

Regarding ERROR [Cache] >> EC.preCommit L1Cache op IS NULL!. This has come up before.

See: https://datanucleus.groups.io/g/main/topic/ec_precommit_l1cache_op_is/9346765?p=,,,20,0,0,0::recentpostdate%2Fsticky,,,20,1,0,9346765

DT recently moved to Java 11 inside its containers and I have not seen this issue with Java 11. But it's still possible that Java 8 may be a better choice. Try increasing the heap to a large number - 12GB or more, and ensure the host machine has enough physical RAM to accommodate.

stevespringett avatar May 05 '21 14:05 stevespringett

@kriss-s @Otterian

davidkarlsen avatar May 07 '21 06:05 davidkarlsen

We experience this too. It hangs every day, and it seems to paginate endlessly on:

021-05-06 07:19:01.687 UTC,"postgres","postgres",344316,"10.200.8.27:44506",6093983d.540fc,64,"SELECT",2021-05-06 07:18:21 UTC,17/4143331,0,LOG,00000,"duration: 595.154 ms  execute <unnamed>: SELECT 'org.dependencytrack.model.Component' AS ""DN_TYPE"",""A0"".""AUTHOR"",""A0"".""BLAKE2B_256"",""A0"".""BLAKE2B_384"",""A0"".""BLAKE2B_512"",""A0"".""BLAKE3"",""A0"".""CLASSIFIER"",""A0"".""COPYRIGHT"",""A0"".""CPE"",""A0"".""DESCRIPTION"",""A0"".""DIRECT_DEPENDENCIES"",""A0"".""EXTENSION"",""A0"".""FILENAME"",""A0"".""GROUP"",""A0"".""ID"" AS ""NUCORDER0"",""A0"".""INTERNAL"",""A0"".""LAST_RISKSCORE"",""A0"".""LICENSE"",""A0"".""MD5"",""A0"".""NAME"",""A0"".""TEXT"",""B0"".""ACTIVE"",""B0"".""AUTHOR"",""B0"".""CLASSIFIER"",""B0"".""CPE"",""B0"".""DESCRIPTION"",""B0"".""DIRECT_DEPENDENCIES"",""B0"".""GROUP"",""B0"".""ID"",""B0"".""LAST_BOM_IMPORTED"",""B0"".""LAST_BOM_IMPORTED_FORMAT"",""B0"".""LAST_RISKSCORE"",""B0"".""NAME"",""B0"".""PUBLISHER"",""B0"".""PURL"",""B0"".""SWIDTAGID"",""B0"".""UUID"",""B0"".""VERSION"",""A0"".""PUBLISHER"",""A0"".""PURL"",""A0"".""PURLCOORDINATES"",""C0"".""FSFLIBRE"",""C0"".""ID"",""C0"".""LICENSEID"",""C0"".""NAME"",""C0"".""ISOSIAPPROVED"",""C0"".""UUID"",""A0"".""SHA1"",""A0"".""SHA_256"",""A0"".""SHA_384"",""A0"".""SHA3_256"",""A0"".""SHA3_384"",""A0"".""SHA3_512"",""A0"".""SHA_512"",""A0"".""SWIDTAGID"",""A0"".""UUID"",""A0"".""VERSION"" FROM ""COMPONENT"" ""A0"" INNER JOIN ""PROJECT"" ""B0"" ON ""A0"".""PROJECT_ID"" = ""B0"".""ID"" LEFT OUTER JOIN ""LICENSE"" ""C0"" ON ""A0"".""LICENSE_ID"" = ""C0"".""ID"" ORDER BY ""NUCORDER0"" OFFSET 6302900 ROWS FETCH NEXT 100 ROWS ONLY ",,,,,,,,,"PostgreSQL JDBC Driver","client backend"
select count(*) from "COMPONENT";

 count  
--------
 177796
(1 row)

davidkarlsen avatar May 07 '21 06:05 davidkarlsen

Hi @stevespringett

could you find something in the metric logic that may cause this issue?

rylyade1 avatar May 11 '21 08:05 rylyade1

Did anyone NOT experience this issue with 4.0 or 4.1? Is it only limited to 4.2? I haven't found anything yet, but theres a lot of places to look and the statements provided do not provide any clue.

stevespringett avatar May 11 '21 21:05 stevespringett

I've checked all the places in DT where query and pagination of components occur. This logic has not changed in over two years. So i'm wondering if this is a JDBC driver issue or a datanucleus issue.

Is anyone NOT using Postgres that is having this issue?

stevespringett avatar May 12 '21 02:05 stevespringett

I can not think of a configuration in the JDBC driver that could cause this issue. Do you have anything in mind?

guruguruguru avatar May 12 '21 08:05 guruguruguru

@guruguruguru I don't know of anything specific to JDBC driver that would cause this issue. However, the JDBC driver and datanucleus were both updated in 4.x, whereas the pagination code in DT hasn't changed in two years.

I'm setting up a dedicated environment for postgres and will be doing some testing today with 4.3 snapshot - which I've added a bunch of debug logging to. Perhaps this will be helpful, but right now I'm flying blind.

stevespringett avatar May 12 '21 14:05 stevespringett

I am happy to help/test if you need something!

guruguruguru avatar May 12 '21 17:05 guruguruguru

There are three main places where all components in the database are queried for and paginated through. They are:

  • ComponentIndexer - Reindexes the internal Lucene search engine for all component objects
  • RepositoryMetaAnalyzerTask - Queries repos to determine the latest version of a component and when it was published
  • BaseComponentAnalyzerTask - Common to all the vulnerability analyzers (OSSIndex, NPM, VulnDB, and Internal) where all components are iterated on and analyzed for known vulnerabilities

In my test environment, I've modified TaskScheduler so that portfolio metrics, vulnerability analysis, and meta analysis are constantly being triggered. All three of these are working as designed. It's paginating correctly in all three cases.

stevespringett avatar May 12 '21 17:05 stevespringett

One scenario that may be problematic, is in 3.x, there was a global component model, components would typically be additive. it would be rare when components would be deleted as that would have to happen intentionally.

With 4.x, the global model doesn't exist. Components are tied to specific projects. If the component is no longer used by a project, or a project is deleted, the component is deleted.

If the count was determined prior to components being deleted, then that might be a problem. But this would not explain the issue @lusor is having where it was attempting to fetch row 25,010,000 on a table that only has 300K rows.

I'm at a loss and unable to replicate.

stevespringett avatar May 12 '21 18:05 stevespringett

This occurs to our DT installation as well. We're also running it against the PostgreSQL database and we also upgraded from 3.x to 4.2 so can't comment on the 4.0 or 4.1 behavior. And in our case it doesn't happen every day like others mention, but after some 2 weeks of runtime. After todays occurrence I setup some stats collection at the DB side so hopefully we will be able to gather some useful information next time.

hostalp avatar May 17 '21 09:05 hostalp

@hostalp

We found our that the problem (in our case) happens after bulk loading BOMs into Dependency-Track. After talking to others this is the case after running the jenkins plugin or by scripts using the API. I don't know how often you load boms into DT - but if you don't do it every day this might be the reason. Maybe this information helps you to find the right logs.

kekkegenkai avatar May 17 '21 09:05 kekkegenkai