You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a loopback 4 application where I have API which returns large data 500000 records to explain the problem I have added the jaeger trace
if you see 1) is my API which has responded in 7-8 sec but the complete API took 12-13 sec
I want to know what happens in those remaining 5-6 sec?
I debugged the API and found out that the control goes to loopback/rest where it is stringifying the response that too using JSON.stringify() and not asyncrously
what happens is that during this time all other requests goes pending in my case liveliness check goes pending and as per my configuration if liveliness failed the container restarts .
how to fix this problem ?
Logs
No response
Additional information
Can we do a faster stringify?
or maybe make this asynchronous? I am ready to contribute
Reproduction
.
The text was updated successfully, but these errors were encountered:
There are options like fast-json-stringify which relies on json schema to be defined for the payload. This would work well with Loopback as response schemas should exist for all apis.
I doubt this will help in your case though because it does not improve the performance a lot for large payloads. JSON is just a extremely inefficient serialization format, especially for large payloads.
or maybe make this asynchronous?
There is no cheap way to make JSON serialization async, could run the serialziation in a worker thread but I would assume passing the object and then the serialized json through worker boundaries is quite expensive as well.
I haven't used this library myself, but streaming the serialization via JSONStream might help, likely takes more overall time but you have run the chunks in different iterations of the event loop which will give your app time to respond to other requests.
what happens is that during this time all other requests goes pending in my case liveliness check goes pending and as per my configuration if liveliness failed the container restarts .
how to fix this problem ?
Could just run the server hosting the liveness api in a different thread. That way it would still be able to respond even if main thread is busy.
Describe the bug
I have a loopback 4 application where I have API which returns large data 500000 records to explain the problem I have added the jaeger trace
if you see 1) is my API which has responded in 7-8 sec but the complete API took 12-13 sec
I want to know what happens in those remaining 5-6 sec?
I debugged the API and found out that the control goes to loopback/rest where it is stringifying the response that too using JSON.stringify() and not asyncrously
what happens is that during this time all other requests goes pending in my case liveliness check goes pending and as per my configuration if liveliness failed the container restarts .
how to fix this problem ?
Logs
No response
Additional information
Can we do a faster stringify?
or maybe make this asynchronous? I am ready to contribute
Reproduction
.
The text was updated successfully, but these errors were encountered: