openvsx icon indicating copy to clipboard operation
openvsx copied to clipboard

Add Spring caching

Open svenefftinge opened this issue 4 years ago • 9 comments
trafficstars

We should add spring caching on the most frequently fetched resources.

svenefftinge avatar Mar 31 '21 10:03 svenefftinge

Fixing the download count (issue #283), a priority, is dependent on this issue.

brianking avatar Apr 15 '21 19:04 brianking

@svenefftinge

  • This is server side caching only? I see other issues already worked on setting caching headers in the HTTP response.
  • Is there a list of most frequently fetched resources? It looks like issue #266 has some hints on what to cache.

brianking avatar Jul 02 '21 11:07 brianking

@brianking This relates to caching database query results (and other heavy computations) internally in the server using Spring Caching. My bad, I misunderstood the issue at first.

Could this be a good opportunity to look for database related performance issues in general?

amvanbaren avatar Sep 15 '21 09:09 amvanbaren

Yes, I'm sure there are plenty of code parts that can be optimized w.r.t. DB access performance. Currently both the server and DB have super high CPU load in production (especially if we decrease LB caching), which indicates that we send too many and too complex DB queries.

This was my first project with Spring and JPA/Hibernate. I must say I would never start a project with JPA again, but evaluate SQL-first approaches like jOOQ instead. Maybe it's even worth refactoring the whole server app to drop JPA entirely.

spoenemann avatar Sep 15 '21 09:09 spoenemann

@amvanbaren what Miro said! However, a refactoring might be too large a time commitment at this point. Feel free to try some optimizations, however, and to recommend approaches moving forward.

brianking avatar Sep 15 '21 10:09 brianking

Hibernate fetches @ManyToOne and @OneToOne mappings eagerly. The effect is most pronounced for ExtensionVersion queries. In this case the Extension, Namespace, PersonalAccessToken and UserData are also loaded.

Changing @ManyToOne to @ManyToOne(fetch=FetchType.LAZY) or @OneToOne to @OneToOne(fetch=FetchType.LAZY) or adding @Basic(fetch=FetchType.LAZY) to enable lazy loading has no effect.

Any ideas why lazy loading is ignored?

amvanbaren avatar Sep 28 '21 08:09 amvanbaren

I'm currently working on implementing projections/dtos to speed up the /vscode/gallery/extensionquery endpoint. https://github.com/eclipse/openvsx/blob/d72fb0fe5361c0775f3b6fbc13bbbadf0fe9ff79/server/src/main/java/org/eclipse/openvsx/adapter/VSCodeAdapter.java#L312-L314 Is it possible to create public ids before the extensionquery endpoint is called?

amvanbaren avatar Oct 04 '21 12:10 amvanbaren

Is it possible to create public ids before the extensionquery endpoint is called?

Yes, we could create them when an extension is published instead of when it's accessed in extensionquery results.

spoenemann avatar Oct 15 '21 06:10 spoenemann

Ok good, In PR #350 I've moved the creation of public ids to ExtensionService.createExtensionVersion when a new Extension is created.

amvanbaren avatar Oct 15 '21 06:10 amvanbaren

I'm closing this issue. If there are still performance/caching issues, please open a new issue for a specific endpoint with a test case.

amvanbaren avatar Dec 08 '22 11:12 amvanbaren