B4J Question Server B4j, how to measure real benefits parameter srvr.GzipEnabled = True

Roberto P.

Well-Known Member
Licensed User
Longtime User
Hi
in a data exchange between apps and servers, I've added srvr.GzipEnabled = True optimization.

I measured the size of the stream with and without parameter, but the dimensions are the same.

Here's how I measure the dimensions: Log("Numero di byes ricevuti dal server : " & j.GetInputStream.BytesAvailable)

This is the B4A code:

B4X:
Sub ReadObject (In As InputStream) As Object
   Dim out As OutputStream
   out.InitializeToBytesArray(0)
   File.Copy2(In, out)
   Dim raf2 As RandomAccessFile
   raf2.Initialize3(out.ToBytesArray, False)
    Dim res As Object = raf2.ReadB4XObject(0) 
   raf2.Close
   Return

Is it correct or should I look on the other side?
 

Roberto P.

Well-Known Member
Licensed User
Longtime User
Upvote 0

OliverA

Expert
Licensed User
Longtime User
Is it correct or should I look on the other side?
No. Both the server and the client take care of compressing / uncompressing. You're insulated from the process. The object that you get back is already uncompressed for you.
 
Upvote 0

Roberto P.

Well-Known Member
Licensed User
Longtime User
data exchange is done with a procedure not with a browser. The data is transmitted with B4XSerializator
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
@Erel's answer here (https://www.b4x.com/android/forum/t...e-database-connector.61801/page-5#post-456003): Yes. B4XSerializator compresses the data while it converts the objects to bytes.

So different methodology (B4XSerializator vs HTTP), but same concept (it's taken care of for you).

Edit: That is probably why you are not seeing any differences in enabling Gzip. It's already compressed, therefore Gzip will not give you the results expected (may actually make it a tad larger).
 
Upvote 0

mindful

Active Member
Licensed User
I think the srvr.GzipEnabled feature will encode only static files and for sure it does it on the fly so is better to use already gzipped files (as abmaterial does it) and set staticfilesoptions with setting gzip=true (so that the server knows that will use gziped files)....
 
Upvote 0

mindful

Active Member
Licensed User
I am not at the pc right now but you can look at github as jServer library is published there and see what exactly GzipEnabled does.
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
@Erel sets an GzipHandler(). Therefore I'm pretty sure this allows for the compression of dynamic pages.

Code:
B4X:
public void setGzipEnabled(boolean b) {
        if (b) {
            gzipHandler = new GzipHandler();
            gzipHandler.setIncludedMethods(HttpMethod.POST.toString(), HttpMethod.GET.toString());
        } else {
            gzipHandler = null;
        }
}
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…