[Qt-interest] QSslSocket: massive difference in app memory usage when encryption enabled
Stephen Collyer
scollyer at netspinner.co.uk
Fri Jul 10 15:41:23 CEST 2009
I'm using Qt 4.5.0 on Opensuse 11.1
I have an HTTP/HTTPS implementation based on QTcpServer and QSslSocket.
When emitting a file in response to a GET request, memory usage is
minimal when handling an unencrypted http request. However,
when handling an encrypted https request, memory usage increases
dramatically, and I get the impression that Qt is buffering the whole
file before any writes to the underlying socket takes place.
The code in skeleton looks like this:
class HTTPReader : public QSSlSocket
{
...
};
In the ctor we connect readyRead():
HTTPReader::HTTPReader()
{
...
connect(this, SIGNAL( readyRead() ), this, SLOT( read_client() ));
}
and in read_client() we eventually handle GET requests, with code like this:
// each time we write some data, emit the next chunk
connect(this, SIGNAL( bytesWritten(qint64) ), SLOT( emit_file_chunk() ));
// and emit the first chunk ..
emit_file_chunk();
where emit_file_chunk() does the following loop:
void HTTPReader::emit_file_chunk()
{
...
while (bytesToWrite() < http_socket_buffer_length_)
{
bytes_read = GET_file_->read(http_get_file_buffer_,
http_get_file_buffer_length_);
if (bytes_read > 0)
{
bytes_written = write(http_get_file_buffer_, bytes_read);
if (bytes_written == -1)
{
GET_file_->close();
close();
break;
}
}
else if (bytes_read == 0)
{
GET_file_->close();
break;
}
}
This code is supposed to top up the QSSlSocket buffer to the tunable
value of http_socket_buffer_length_, then to return to yield to the
event loop, when it will be run again the next time bytesWritten() is
emitted.
This seems to work fine for non-encrypted sockets but has an unacceptable
memory footprint for encrypted sockets. There seems to be a fundamental
difference in buffering when QSSlSocket is encrypted, to the extent that the
app's VSZ reaches the size of the file being sent in response to the GET.
Does anyone have any insight into what's going on here ?
--
Stephen Collyer
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090710/6445d7be/attachment.html
More information about the Qt-interest-old
mailing list