Exceeding size limit with Sagemaker endpoint - amazon-sagemaker

I have setup a Sagemaker inference endpoint for processing images. I am sending a json request like this to the endpoint:
data = {
'inferenceType' : 'SINGLE_INSTANCE',
'productType' : productType,
'images': [encoded_image_bytes_as_string],
'content_type': "application/json",
payload = json.dumps(data)
response = sagemaker_runtime_client.invoke_endpoint(
where image is an array of base64 encoded images. The endpoint works fine except when I send large images I exceed the Sagemaker's inference payload size limit of:
Maximum payload size for endpoint invocation 6 MB
what other data formats can I make use of that are smaller than JSON? Is there any possibility of using something like gzip to compress my payload before sending it? I know that Sagemaker asynchronous endpoints and batch transform have higher allowable payload sizes however I require realtime inference. Thanks!

You're currently sending the image bytes inefficiently as Base64 (which is ~1.3x bigger than just bytes). If you'll send bytes instead of JSON, it will allow you to grow the maximum image from (6/1.13)MB to 6MB.
You could also contact AWS support and try to ask increase the maximum payload size.
If you need more than that, then you'll need to write the file to some storage (like S3 or EFS), then send the image ref to the endpoint which will read back the image from that storage. Overall, quite hard to pull off, reliably, end to end, in <500ms.

Asynchronous is technically a Real Time hosting option in SageMaker. Depending on the kind of latency requirements you have for your invocations, I would recommend exploring Asynchronous Inference as that is designed for large payloads. I would suggest running some load tests with Asynchronous endpoints.


Single get request on frontend returning an entire table in chunks - how to do? Django

Could use some help with this please.
Django and PostgreSQL is the backend for a React frontend project of mine. The frontend needs to fetch and perform calculations on a large number of rows in a table... a million + rows is possible.
Right now, fetching and doing those calculations is implemented, but it takes way too long, and that's locally. When deployed, it doesn't even work because it's not in batches, it's just one big GET request which times out after 30 seconds.
I've set up splicing on the frontend for dealing with POST/PUT related requests to get around that time out issue, but how would I go about doing a GET request in batches? I've been looking into iterator and cursor stuff to try and deal with things in chunks, but I am also confused - if a single GET request is performed on the frontend, is it even possible to send multiple responses? I have seen conflicting information on that.
Some guidance on the best way to address this would be appreciated. If it helps, I am primarily working with a class based way of doing things, Model, Serializer, ModelViewSet.
Here's what I'm working on currently to attempt to do batch get-requests, but not sure if I'm on the right page.
def batch_get(self, request):
count = UploadedShares.objects.all().count()
chunk_size = 500
for i in range(0, count, chunk_size):
shares = UploadedShares.objects.all()[i:i + chunk_size]
serialized_shares = serializers.serialize('json', shares)
return JsonResponse(serialized_shares, safe=False)

Gatling : Any thoughts on writing response into a file ,will it be thread safe and will it be an overhead for load test time or overall performance

I need to save response from my two tests which give two variations . I need to calculate the ratio of the response received.
response 1
"var1": "a1"
response 2
"var1": "b1"
I was thinking about writing the response into files and then write a method to read those files and calculate the ratios.
Is there any other way to do so in gatling?
Gatling stores its results in target/gatling/<simulation>. This folder also contains the raw log file <logfile>.log that you can parse yourself after the run. Note that you can only differentiate between different requests, it doesn't log the returned responses, from your description I'm not sure whether this fits your needs.
Gatling already has a parser for the logfile with which you should be able to easily interface, it's used for the generation of gatlings fancy log reports here: https://github.com/gatling/gatling/blob/master/gatling-charts/src/main/scala/io/gatling/charts/stats/LogFileReader.scala.
I also wrote a much simpler parser myself, if you're interested I can put it on github.

JAXWS - Best Way to transfer file is byte[] or MTOM

I am trying to find best way to transfer files in JAXWS webservice.
MTOM or byte[] are the options I found. Someone can tell me which is the best way and why
There's not a universal best way to transfer files. It depends on your needs.
As a byte array (Base64)
You should refer to it as Base64 encoded and not as byte[] (the file is sent as text using Base64 encoding and you will handle it in your java code as a byte[]). This method is fast since it only needs to encode the data to Base64 text and write it to the soap message, but the encoded data is 33% larger than the original file size.
So this method is only recommended for small files.
Using MTOM
This is the recommended method for bigger files because it does not increase the file size since it doesn't send the file as encoded data but as a MIME attachment. This method involves some steps more than just encoding the data so it takes a little more processing time although the difference may not be that big.
Best of both worlds
Most web services frameworks allow you to specify a threshold that indicates the minimum file size needed to use MTOM. If the file does not reach that size, the data will be sent as Base64 encoded text.
Example in JAX-WS:
#MTOM(threshold = 3072)
public class MyWebService {
This means that if the file is less than 3 Mb it will be sent as Base64 text, and if it's bigger it will be sent using MTOM. This is a very common approach and it will probably suit your needs.
For a file to be considered small or big it depends on your hardware, concurrent clients using the service, etc.

libcurl C API > POST ranges of data obtained from URL

How can I post ranges of data obtained from URL, not from file? Say I need to read 150-250000 bytes from http://localhost/video.mp4 (A) and POST this data to (B) in chunks smoothly so that it looked like the data is streamed from (A) to (B)?
Why not simply start downloading from A (using a range if you don't want the whole thing) and once you have received enough data to pass it along to site B, you issue a separate request with that data. Meanwhile you continue downloading from A into an alternative buffer etc.
You can do this using two threads or even in the same thread using libcurl's multi interface.

How to implement a lossless URL shortening

First, a bit of context:
I'm trying to implement a URL shortening on my own server (in C, if that matters). The aim is to avoid long URLs while being able to restore a context from a shortened URL.
Currently I have a implementation that creates a session on the server, identified by a certain ID. This works, but consumes memory on the server (and is not desired since it's an embedded server with limited resources and the main purpose of the device isn't providing web pages but doing other cool stuff).
Another option would be to use cookies or HTML5 webstorage to store the session information in the client.
But what I'm searching for is the possibility to store the shortened URL parameters in one parameter that I attach to the URL and be able to re-construct the original parameters from that one.
First thought was to use a Base64-encoding to put all the parameters into one, but this produces an even larger URL.
Currently, I'm thinking of compressing the URL parameters (using some compression algorithm like zip, bz2, ...), do the Base64-encoding on that compressed binary blob and use that information as context. When I get the parameter, I could do a Base64-decoding, de-compress the result and have hands on the original URL.
The question is: is there any other possibility that I'm overlooking that I could use to lossless compress a large list of URL parameters into a single smaller one?
After the comments from home, I realized that I overlooked that compressing itself adds some overhead to the compressed data making the compressed data even larger than the original data because of the overhead that for example zipping adds to the content.
So (as home states in his comments), I'm starting to think that compressing the whole list of URL parameters is only really useful if the parameters are beyond a certain length because otherwise, I could end up having an even larger URL than before.
You can always roll your own compression. If you simply apply some huffman coding, the result will always be smaller (but then base64 encoding it, it'll grow a bit, so the net effect may perhaps not be optimal).
I'm using a custom compression strategy on an embedded project I work with where I first use a lzjb (a lempel ziv derivate, follow link for source code, really tight implementation (from open solaris)) followed by huffman coding the compressed result.
The lzjb algorithm doesn't perform too well on very short inputs, though (~16 bytes, in which case I leave it uncompressed).