We have a multi-threaded uploader which transfers large files from local disk to GCS. The uploader is co-located with our low-latency app. inside the JVM. To control latency, we must throttle the uploader. Our best workaround involves resorting to reflection in order to install HttpRequest interceptor which effectively wraps HttpContent with a throttled OutputStream; e.g.,
Object storageRpc = FieldUtils.getField(storage.getClass(), "storageRpc", true).get(storage);
Object serviceStorage = FieldUtils.getField(storageRpc.getClass(), "storage", true).get(storageRpc);
Object requestFactory = FieldUtils.getField(serviceStorage.getClass(), "requestFactory", true).get(serviceStorage);
Field initializerField = FieldUtils.getField(requestFactory.getClass(), "initializer", true);
Object initializer = initializerField.get(requestFactory);
initializerField.set(requestFactory, new InterceptingHttpRequestInitializer((HttpRequestInitializer) initializer));
We have a multi-threaded uploader which transfers large files from local disk to GCS. The uploader is co-located with our low-latency app. inside the JVM. To control latency, we must throttle the uploader. Our best workaround involves resorting to reflection in order to install
HttpRequestinterceptor which effectively wrapsHttpContentwith a throttledOutputStream; e.g.,