Data Compression in Python

Please refer to the Data Compression page for a discussion of the advantages of in-memory and persistent database compression.

In-Memory Database Compression

To enable compression for an in-memory database, specify the compressionLevel, compressionMask, and expectedCompressionRatio arguments in the call to method open_database(). (These parameters have the same effect as described in the C API. Please refer to page Data Compression in C for further details.)

For example:

 
    exdb.open_database(dbname='testdb',
        dictionary=dict,
        is_disk=False,
        db_segment_size=128*1024*1024,
        compressionLevel=3, compressionMask=3, expectedCompressionRatio=30
            
    );
     

Persistent Database Compression

For persistent databases, compression is enabled by specifying the DiskCompression parameter when calling the exdb.init_runtime() method and specifying the compressionLevel, compressionMask, and expectedCompressionRatio arguments in the call to method open_database(). (These parameters have the same effect as described in the C API. Please refer to page Data Compression in C for further details.)

For example:

     
    #Load Runtime configuration specified by parameters
    exdb.init_runtime(is_disk=True, tmgr='mvcc', DiskCompression=True)
    ...
    #Open the database specifying compression parameters
    exdb.open_database(dbname='testdb',
        dictionary=dict,
        is_disk=True,
        db_segment_size=128*1024*1024,
        compressionLevel=3, compressionMask=3, expectedCompressionRatio=30
            
    );
     
 

Data Compression for IoT Communications

Data compression for IoT communications is enabled by setting the compression_level key of the comm_params dictionary parameter in the IoTCommunicator constructor. For example:

 
    iot_communicator = exdb.IoTCommunicator(comm_params = {'compression_level' : 1})
 

The default level of 0 means no compression. As explained in the Data Compression page, the communications between each server-device pair will be compressed only if both sides (server and device) have compression_level greater than 0, and all communicating components must use the same compression level value.

Also explained in the Data Compression page is the formula used to determine the compression ratio. The stat dictionary of an IoTConnection can be examined to; elements sent_compression_ratio and recv_compression_ratio show the compression efficiency for incoming and outgoing communications.