user3071284
user3071284

Reputation: 7100

BreezeJS: Retrieving large number of records via executequery() == System.OutOfMemoryException

Is System.OutOfMemoryException expected when a large number (e.g. more than 625,000) of records would be returned from a call to executequery()?

Using take() works fine, e.g.

var query = breeze.EntityQuery
    .from("Biography")
    .select("ENTITY_ID, NAME, NICKNAME")
    .where("VAL1","==","AL")
    .orderBy("ENTITY_ID")
    .take(1000);

However, asking for all records results in the System.OutOfMemoryException error.

var query = breeze.EntityQuery
    .from("Biography")
    .select("ENTITY_ID, NAME, NICKNAME")
    .where("VAL1","==","AL")
    .orderBy("ENTITY_ID");

Running the equivalent SQL takes about 5 seconds to complete successfully.

Upvotes: 0

Views: 297

Answers (1)

Jay Traband
Jay Traband

Reputation: 17052

I'm not surprised.

Just to be clear, you are trying to move more than 625,000 records over the wire and then create entities out of them. The query on the server is likely very fast, but then each of these records needs to be serialized to json, sent over the wire, and then reconstituted as an entity. These operations can be both time consuming and memory hogs with large amount of data even with the best of implementations.

So you've got a few options to reduce both the memory footprint and the time that the operation takes.

  1. Use take (per your example)
  2. Use the EntityQuery.noTracking option. This skips the step of converting the serialized records into 'true' entities. If you need 'true' entities later you can add them selectively to the EntityManager as needed.

Upvotes: 1

Related Questions