Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why is there no performance improvement for compress and decompress and get wrong result for qzSetupSessionLZ4? #123

Open
anjingde opened this issue Dec 6, 2024 · 4 comments

Comments

@anjingde
Copy link

anjingde commented Dec 6, 2024

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(&params) != QZ_OK) 
//   fprintf(stderr, "Failed to get params \n");

if (qzGetDefaultsLZ4(&params) != 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, &params);
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;

}

@anjingde
Copy link
Author

anjingde commented Dec 6, 2024

hardware
image

@anjingde
Copy link
Author

anjingde commented Dec 6, 2024

when I change the qzSetupSession(&sess, NULL); to qzSetupSessionLZ4(&sess, NULL), i get wrong result, the src_len is 4000, but the len of decompressed is 3438

@anjingde
Copy link
Author

anjingde commented Dec 6, 2024

I install qat by sudo dnf -y install qatzip and so on

@daweiq
Copy link
Contributor

daweiq commented Dec 11, 2024

Can you please following the wiki to make use of telemetry to visualize wether QAT is fully utilized?
https://intel.github.io/quickassist/PG/infrastructure_device_telemetry.html#monitoring-telemetry-text-based

You can also benchmarking the QAT with the following benchmark tool.
https://intel.github.io/quickassist/qatlib/qatzip.html?highlight=qatzip+performance#benchmarking

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants