Ich habe einen Finder definiert als ein Spring Data Repository, das von MongoRepository abgeleitet wurde und nach 3 verschiedenen Attributen in MongoDB sucht. Alle drei haben einen einzigen Index.Spring Data REST: langsame Seitenzusammenfassung
public Page<Content> findByIdInOrAuthorUserNameInOrTagsIdIn(
@Param("ids") Collection ids,
@Param("userNames") Collection userName,
@Param("tagIds") Collection tagIds,
@Param("pageable") Pageable pageable);
Das Problem ist, dass man Attribute eine Ergebnismenge von 2,5 Mio. Einträge hat:
"page": {
"size": 20,
"totalElements": 2531397,
"totalPages": 126570,
"number": 5
}
So ist die Abfrage für eine Seite ist recht schnell (13ms), wie in der Mongo Protokolldatei gesehen :
2017-04-10T12:50:27.562+0200 I COMMAND [conn68] command content.content command: find { find: "content", filter: { $or: [ { $or: [ { _id: { $in: [ "..." ] } }, { author.userName: { $in: [ "...", "..." ] } } ] }, { tags._id: { $in: [ "..." ] } } ] }, skip: 100, limit: 20 } planSummary: IXSCAN { _id: 1 }, IXSCAN { tags._id: 1 }, IXSCAN { author.userName: 1 } keysExamined:120 docsExamined:120 cursorExhausted:1 numYields:0 nreturned:20 reslen:21185 locks:{ Global: { acquireCount: { r: 2 } }, Database: { acquireCount: { r: 1 } }, Collection: { acquireCount: { r: 1 } } } protocol:op_query 13ms
Aber es scheint, dass die Seite Zusammenfassung, die das Ergebnis zählt, nimmt ~ 117S:
2017-04-10T12:52:24.172+0200 I COMMAND [conn68] command content.content command: count { count: "content", query: { $or: [ { $or: [ { _id: { $in: [ "..." ] } }, { author.userName: { $in: [ "...", "..." ] } } ] }, { tags._id: { $in: [ "..." ] } } ] } } planSummary: IXSCAN { _id: 1 }, IXSCAN { tags._id: 1 }, IXSCAN { author.userName: 1 } keysExamined:2531466 docsExamined:2531397 numYields:21190 reslen:44 locks:{ Global: { acquireCount: { r: 42382 } }, Database: { acquireCount: { r: 21191 } }, Collection: { acquireCount: { r: 21191 } } } protocol:op_query 116592ms
Gibt es eine Möglichkeit, die Seitenzusammenfassung auszuschalten oder das Zählen zu beschleunigen?
Nicht sicher, ob das funktioniert, aber Sie haben versucht, eine Scheibe statt einer Seite: http://docs.spring.io/spring-data/commons/docs/current/api/org/springframework/data/domain/ Slice.html –
Das war genau das, wofür ich gesperrt habe :) Slice kann auch mit dem Parameter Pageable kombiniert werden. Danke –
Hat es eine Antwort so gemacht, Sie können es schließen, und das System denkt nicht, dass dies immer noch unbeantwortet ist. –