jakxz
10/30/2023, 8:03 PMFile too large errors when trying to store large bundles with client.executeBatch -
I was thinking of using Node's built in zlib functionality to compress the JSON to a usable size Buffer, but... if I understand correctly, I will run through the compression() middleware [of Medplum's express server] first and then the json() middleware will read the length of the uncompressed bundle and still throw a File too large error.
Is my understanding correct? Or am I completely off base? What would you suggest as the best way to handle storing large bundles [other than splitting it into multiple executeBatch commands, which I would love to avoid if possible]?rahul1
10/30/2023, 10:42 PMBundle resources, or are you using them as batch requests to create data? Typically, executeBatch is for the latter
- Approximately how big are your Bundles (# of entries, and ~KB)jakxz
10/30/2023, 10:49 PMjakxz
10/30/2023, 10:50 PMrahul1
10/31/2023, 1:51 AMmaxJsonSize - have you already tried that?
https://www.medplum.com/docs/self-hosting/config-settingsrahul1
10/31/2023, 1:57 AMrahul1
10/31/2023, 1:57 AMjakxz
10/31/2023, 2:02 AMmedplumClient.executeBatch method.
Do we just set a number for https://www.medplum.com/docs/sdk/interfaces/MedplumClientOptions#autobatchtime when instantiating the client?jakxz
10/31/2023, 2:03 AMMAX_JSON_SIZE='50mb'
you'd expect that to just work?rahul1
10/31/2023, 2:26 AMrahul1
10/31/2023, 2:27 AMjakxz
10/31/2023, 2:27 AMrahul1
10/31/2023, 2:28 AMrahul1
10/31/2023, 2:30 AMts
const medplum = new MedplumClient({autobatchTime: 1000});
const patientsToCreate = [];
// Main thread continues
patientsToCreate.push(
medplum.createResource({
resourceType: 'Patient',
id: 'john-smith',
name: [
{
family: 'Smith',
given: ['John'],
},
],
})
);
// Main thread continues
patientsToCreate.push(
medplum.createResource({
resourceType: 'Patient',
id: 'homer-simpson',
name: [
{
family: 'Simpson',
given: ['Homer', 'Jay'],
},
],
})
);
// Both promises are resolved simultaneously
await Promise.all(patientsToCreate);jakxz
10/31/2023, 2:33 AMexecuteBatch? I might be misunderstanding but since we just want to do the one request, we're not queueing up multiple requests [and thus nothing needs to be `autobatch`ed*] right?jakxz
10/31/2023, 2:34 AMcreateResource for every entry with autobatch enabled? and that way the request will be as large as is allowed, and as few requests as possible will be made*?rahul1
10/31/2023, 2:54 AMrahul1
10/31/2023, 2:54 AMexecuteBatch is finerahul1
10/31/2023, 2:55 AMexecuteBatch on your behalfjakxz
10/31/2023, 3:00 AMexecuteBatch and called createResource individually, we could count on the client to make appropriately sized executeBatch requests for us, right? Or would it still hit the file size limit error if we make too many requests in the time window/with bundles** that are too large?
Would autobatched requests* respect maxJsonSize?jakxz
10/31/2023, 3:01 AMbrendankeeler
10/31/2023, 4:16 PMrahul1
10/31/2023, 6:26 PMrahul1
10/31/2023, 6:27 PMjakxz
10/31/2023, 6:29 PMrahul1
10/31/2023, 6:29 PMjakxz
11/01/2023, 8:37 PMjakxz
11/01/2023, 8:38 PMexecuteBatch? If I understand correctly fetch that's used under the hood should be able to use that right?jakxz
11/01/2023, 9:25 PMconst stringifiedBundle = JSON.stringify(bundle);
if (Buffer.byteLength(stringifiedBundle, 'utf-8') > MAX_BUNDLE_SIZE) {
const compressedBundle = await gzip(stringifiedBundle);
responseBundle = await medplumClient.post(medplumClient.getBaseUrl().slice(0, -1), compressedBundle, undefined, {
headers: {
'Content-Encoding': 'gzip',
},
});
} else {
responseBundle = await medplumClient.executeBatch(bundle as MedplumBundle);
}
but I'm curious if you have feedbackrahul1
11/01/2023, 11:59 PMjakxz
11/02/2023, 4:01 PMexpress.json() behaviour to check against the inflated (uncompressed) size of the bunde: https://github.com/expressjs/express/blob/2a00da2067b7017f769c9100205a2a5f267a884b/test/express.json.js#L171jakxz
11/02/2023, 4:02 PMjakxz
11/02/2023, 5:29 PMrahul1
11/03/2023, 12:18 AMrahul1
11/03/2023, 12:40 AMrahul1
11/03/2023, 12:41 AMmaxJsonSize config setting?jakxz
11/03/2023, 5:40 PMrahul1
11/03/2023, 11:03 PMrahul1
11/03/2023, 11:04 PMrahul1
11/03/2023, 11:04 PM