-
Notifications
You must be signed in to change notification settings - Fork 56
Description
I am using QAT (QuickAssist Technology) to compress and decompress 64KB chunks of data sequentially, and then concatenate them together. However, I have not observed any performance improvement for both compression and decompression, even though the hardware has been verified to be functioning correctly. Could you explain why this might be happening?
for compress:
qat_compress_string(StringInfo ibuffer, StringInfo obuffer, void *clevel, void *context)
{
int obytes, max_obytes;
int ret;
bool output = true;
AssertArg(ibuffer && obuffer);
max_obytes = LZ4_compressBound(ibuffer->len);
enlargeHugeStringInfo(obuffer, max_obytes);
QzSession_T sess={0};
ret = qzInit(&sess, 0);
if (QZ_DUPLICATE != ret && QZ_OK != ret) {
elog(ERROR,"Failed to initialize QAT ZIP library, %d\n", ret);
output = false;
goto close;
}
QzSessionParams_T params = {0};
//if (qzGetDefaults(¶ms) != QZ_OK)
// fprintf(stderr, "Failed to get params \n");
if (qzGetDefaultsLZ4(¶ms) != QZ_OK)
fprintf(stderr, "Failed to get params \n");
//params.comp_algorithm = QZ_LZ4;
params.comp_lvl = 1;
//params.hw_buff_sz = Qatzip_HardwareBufferSize_SZ_64K;
if (NULL == sess.internal || QZ_NONE == sess.hw_session_stat)
{
//ret = qzSetupSessionLZ4(&sess, NULL);
ret = qzSetupSession(&sess, NULL);
if (ret != QZ_OK)
{
elog(ERROR, "failed setup qat compress session");
output = false;
goto out;
}
}
int src_len = ibuffer->len;
int dest_len = max_obytes;
ret = qzCompress(&sess, (const char *) ibuffer->data, &src_len, obuffer->data + obuffer->len, &dest_len, 1);
if (dest_len <= 0)
{
elog(WARNING, "Fail to qat_compress_default");
output = false;
goto out;
}
/* No need to compress */
if (dest_len>= ibuffer->len)
{
elog(WARNING, "no need to compress");
output = false;
goto out;
}
obuffer->len += dest_len;
out:
(void) qzTeardownSession(&sess);
close:
qzClose(&sess);
return output;
}
for decompress
qat_decompress_string(StringInfo ibuffer, StringInfo obuffer, int32 rawsize, void* context)
{
int obytes;
bool output = true;
AssertArg(ibuffer && obuffer && rawsize >= 0);
enlargeHugeStringInfo(obuffer, rawsize);
//QzSession_T *sess = palloc0(sizeof(QzSession_T));
QzSession_T sess={0};
int ret = qzInit(&sess, 0);
if (QZ_DUPLICATE != ret && QZ_OK != ret) {
fprintf(stderr, "Failed to initialize QAT ZIP library: %d\n", ret);
output = false;
goto out;
}
if (NULL == sess.internal || QZ_NONE == sess.hw_session_stat)
{
//ret = qzSetupSessionLZ4(&sess, NULL);
ret = qzSetupSession(&sess, NULL);
if (ret != QZ_OK)
{
elog(ERROR, "failed setup qat decompress session");
output = false;
goto out;
}
}
//ret = qzSetupSession(sess, ¶ms);
int src_len = ibuffer->len;
obytes= rawsize;
ret = qzDecompress(&sess, (const char *) ibuffer->data, &src_len, (const char *) obuffer->data+obuffer->len, &obytes);
if (ret != QZ_OK)
{
elog(ERROR, "%d decompression error", ret);
output = false;
goto out;
}
if (obytes < 0)
{
elog(WARNING, "Fail to qat_decompress_string, error code: %d",obytes);
output = false;
goto out;
}
if (obytes != rawsize)
{
elog(WARNING, "compressed qat data is corrupt, expected %d bytes but decompressed %d bytes", rawsize, obytes);
output = false;
goto out;
}
obuffer->len += obytes;
out:
(void) qzTeardownSession(&sess);
qzClose(&sess);
return output;
}