Zlib working extremely slow in functions

Hi! I’ve tried to add compressing with zlib to one of my functions, however i faced extremely slow performance.

Here is sample function

    exports = function(){

      const zlib = require('zlib');

      const testString = 'Test';
      const compressed = zlib.deflateSync(testString);
      
      return compressed;
    };

It takes 20 seconds to complete, just to compress single word. I’ve tried another third party lib for node.js but results are pretty same. Is it known issue? Are there any ways to workaround this?

1 Like

Hi @Mikhail_Mulyar

Welcome to MongoDB community!

It is possible that the overhead of loading the entire zlib package for just one function cause this latency. Can you try and load just that method?

Thanks
Pavel

No, it still the same. All overhead happens in deflate function. If i call it twice function will take twice longer time. So if you want to compress 4-5 words separately you easily will have timeout for this function.

Same code with much bigger string in Firebase functions takes less than a second to execute

I also have this same problem when trying to decompress GZIP data from api.

Hi @Matt_McKenzie and @Mikhail_Mulyar,

I suggest you open a case with our Support to investigate the specific slowdown in ur case.

Best
Pavel

Hi @Pavel_Duchovny and @Mikhail_Mulyar whatever happened here? I’m having the same issue with Stripe. It’s taking 1 minute and 15 seconds to complete a simple call to list customers by email address. The function executes quickly (including loading the dependencies with require) up until I call stripe.customers.list. This same call take < 100 ms on my local machine or within a Firebase function. Something is definitely wrong.

I don’t work for Mongo, but I do believe adding any dependencies are a Beta feature. So I only use realm to communicate with my atlas database which doesn’t require any dependencies. It still takes about 200ms, vs a lambda function 40ms (on second request)

Also not sure if you can compare other cloud serverless options to Realm functions, as far as I know they are much lighter weight then a lambda function and designed to run “more frequently” – not sure what that means but i was told that by a Realm engineer.