opensrp / fhircore

FHIR Core / OpenSRP 2 is a Kotlin application for delivering offline-capable, mobile-first healthcare project implementations from local community to national and international scale using FHIR and WHO Smart Guidelines on Android.
https://smartregister.org
Apache License 2.0
50 stars 39 forks source link

Implement Gzip compression for all requests #2753

Closed ndegwamartin closed 8 months ago

ndegwamartin commented 9 months ago

Describe the feature request. We need to enforce GZIP for all requests from the android client. This leads to 7x improvements during sync in terms of bandwidth.

Additional context We have confirmed that currently some endpoints do not use gzip compression when making requests to the backend e.g custom endpoints during initial sync.

Acceptance criteria The app should login and sync down data successfully for all the endpoints/resources.

Area path A list of ordered steps in the app on usage of the feature to support anyone testing it e.g. Code reviewer, QA e.g.

  1. Login to the app
  2. Sync data

Implementation plan (For Engineers) The plan for implementing the solution e.g. via a description or a check list for the various ordered tasks that will need to be completed.

pld commented 9 months ago

Cool, adding this to current milestone

ellykits commented 8 months ago

Findings

This header is not present in the download requests Accept-Encoding: gzip. The OkHttp client responsible for performing the requests is in the Android FHIR SDK code. FHIRCore HTTP clients will also need to be updated to include this header esp. for the endpoint that returns practitioner-details.

pld commented 8 months ago

nice, this is kinda a great finding, since we should get a speedup from having gzip on, is there an issue on the SDK yet for this?

ellykits commented 8 months ago

No issue yet

ellykits commented 8 months ago

Also, NOTE that the SDK provides a NetworkConfiguration for enabling gzip only for upload requests, defaults to false. We have overridden this in FHIRCore FhirEngineModule enable gzip for the upload requests. The implementation can be adopt for download requests in the SDK.

pld commented 8 months ago

@ellykits based on Aditya's comment on the space gzip is already enabled, https://github.com/square/okhttp/issues/2132#issuecomment-165888326

Rkareko commented 8 months ago

When a breakpoint is added in the OkHttpCall.java class in the parseResponse function that is part of the Retrofit package, and then run rawResponse.networkResponse(), you will see that in the request headers, gzip is set as the encoding method when running fhir core agaimst the stage server https://fhir.labs.smartregister.org/fhir/Patient?organization=144238&_count=100&_sort=_lastUpdated&_summary=count cc @ndegwamartin @ellykits The app is pointing to a non proxy server

fhir_core_request_header

Rkareko commented 8 months ago

Apps pointing to the gateway also have the gzip encoding header as seen below

fhir_core_gateway

ellykits commented 8 months ago

This issue can be closed. As verified by the screenshots logs shared above by @Rkareko.