Sending progress in HTTP headers (continued) [#CLICKHOUSE-32].

This commit is contained in:
Alexey Milovidov 2017-01-22 19:34:17 +03:00
parent 4aa90e908d
commit 48ae82e1c7
3 changed files with 29 additions and 9 deletions

View File

@ -14,6 +14,7 @@
#include <DB/IO/ZlibDeflatingWriteBuffer.h>
#include <DB/IO/HTTPCommon.h>
#include <DB/Common/NetException.h>
#include <DB/Common/Stopwatch.h>
#include <DB/Core/Progress.h>
@ -56,6 +57,8 @@ private:
bool body_started_sending = false; /// If true, you could not add any headers.
Progress accumulated_progress;
size_t send_progress_interval_ms = 100;
Stopwatch progress_watch;
std::mutex mutex; /// progress callback could be called from different threads.
@ -143,11 +146,15 @@ public:
if (body_started_sending)
return;
accumulated_progress.incrementPiecewiseAtomically(progress);
if (progress_watch.elapsed() >= send_progress_interval_ms * 1000000)
{
progress_watch.restart();
/// Send all common headers before our special progress headers.
startSendHeaders();
accumulated_progress.incrementPiecewiseAtomically(progress);
std::string progress_string;
{
WriteBufferFromString progress_string_writer(progress_string);
@ -156,6 +163,7 @@ public:
*response_header_ostr << "X-ClickHouse-Progress: " << progress_string << "\r\n" << std::flush;
}
}
/// Send at least HTTP headers if no data has been sent yet.
/// Use after the data has possibly been sent and no error happened (and thus you do not plan
@ -187,6 +195,13 @@ public:
add_cors_header = enable_cors;
}
/// Don't send HTTP headers with progress more frequently.
void setSendProgressInterval(size_t send_progress_interval_ms_)
{
send_progress_interval_ms = send_progress_interval_ms_;
}
~WriteBufferFromHTTPServerResponse()
{
if (!offset())

View File

@ -237,7 +237,10 @@ struct Settings
M(SettingUInt64, output_format_pretty_max_rows, 10000) \
\
/** Use client timezone for interpreting DateTime string values, instead of adopting server timezone. */ \
M(SettingBool, use_client_time_zone, false)
M(SettingBool, use_client_time_zone, false) \
\
/** Do not send HTTP headers X-ClickHouse-Progress more frequently than at each specified interval. */ \
M(SettingUInt64, http_headers_progress_interval_ms, 100) \
/// Всевозможные ограничения на выполнение запроса.
Limits limits;

View File

@ -229,6 +229,8 @@ void HTTPHandler::processQuery(
if (client_supports_http_compression)
used_output.out->setCompressionLevel(context.getSettingsRef().http_zlib_compression_level);
used_output.out->setSendProgressInterval(context.getSettingsRef().http_headers_progress_interval_ms);
/// If 'http_native_compression_disable_checksumming_on_decompress' setting is turned on,
/// checksums of client data compressed with internal algorithm are not checked.
if (in_post_compressed && context.getSettingsRef().http_native_compression_disable_checksumming_on_decompress)