add profile event

add profile event for set&seek

fix

fix

fix
This commit is contained in:
Nikita Taranov 2023-11-27 18:51:47 +01:00
parent c52571223e
commit 0ad796aa99
2 changed files with 37 additions and 16 deletions

View File

@ -438,8 +438,12 @@ The server successfully detected this situation and will download merged part fr
M(WaitPrefetchTaskMicroseconds, "Time spend waiting for prefetched reader") \
\
M(ThreadpoolReaderTaskMicroseconds, "Time spent getting the data in asynchronous reading") \
M(ThreadpoolReaderPrepareMicroseconds, "Time spent on preparation (e.g. call to reader seek() method)") \
M(ThreadpoolReaderReadBytes, "Bytes read from a threadpool task in asynchronous reading") \
M(ThreadpoolReaderSubmit, "Bytes read from a threadpool task in asynchronous reading") \
M(ThreadpoolReaderSubmitReadSynchronously, "How many times we haven't scheduled a task on the thread pool and read synchronously instead") \
M(ThreadpoolReaderSubmitReadSynchronouslyBytes, "How many bytes were read synchronously") \
M(ThreadpoolReaderSubmitReadSynchronouslyMicroseconds, "How much time we spent reading synchronously") \
M(AsynchronousReaderIgnoredBytes, "Number of bytes ignored during asynchronous reading") \
\
M(FileSegmentWaitReadBufferMicroseconds, "Metric per file segment. Time spend waiting for internal read buffer (includes cache waiting)") \

View File

@ -20,8 +20,12 @@
namespace ProfileEvents
{
extern const Event ThreadpoolReaderTaskMicroseconds;
extern const Event ThreadpoolReaderPrepareMicroseconds;
extern const Event ThreadpoolReaderReadBytes;
extern const Event ThreadpoolReaderSubmit;
extern const Event ThreadpoolReaderSubmitReadSynchronously;
extern const Event ThreadpoolReaderSubmitReadSynchronouslyBytes;
extern const Event ThreadpoolReaderSubmitReadSynchronouslyMicroseconds;
extern const Event AsynchronousReaderIgnoredBytes;
}
@ -70,15 +74,25 @@ std::future<IAsynchronousReader::Result> ThreadPoolRemoteFSReader::submit(Reques
auto * fd = assert_cast<RemoteFSFileDescriptor *>(request.descriptor.get());
auto & reader = fd->getReader();
/// `seek` have to be done before checking `isContentCached`, and `set` have to be done prior to `seek`
reader.set(request.buf, request.size);
reader.seek(request.offset, SEEK_SET);
{
ProfileEventTimeIncrement<Microseconds> elapsed(ProfileEvents::ThreadpoolReaderPrepareMicroseconds);
/// `seek` have to be done before checking `isContentCached`, and `set` have to be done prior to `seek`
reader.set(request.buf, request.size);
reader.seek(request.offset, SEEK_SET);
}
if (reader.isContentCached(request.offset, request.size))
{
std::promise<Result> promise;
std::future<Result> future = promise.get_future();
promise.set_value(execute(request, /*seek_performed=*/true));
auto && res = execute(request, /*seek_performed=*/true);
ProfileEvents::increment(ProfileEvents::ThreadpoolReaderSubmitReadSynchronously);
ProfileEvents::increment(ProfileEvents::ThreadpoolReaderSubmitReadSynchronouslyBytes, res.size);
if (res.execution_watch)
ProfileEvents::increment(ProfileEvents::ThreadpoolReaderSubmitReadSynchronouslyMicroseconds, res.execution_watch->elapsedMicroseconds());
promise.set_value(std::move(res));
return future;
}
@ -102,20 +116,23 @@ IAsynchronousReader::Result ThreadPoolRemoteFSReader::execute(Request request, b
auto read_counters = fd->getReadCounters();
std::optional<AsyncReadIncrement> increment = read_counters ? std::optional<AsyncReadIncrement>(read_counters) : std::nullopt;
{
ProfileEventTimeIncrement<Microseconds> elapsed(ProfileEvents::ThreadpoolReaderPrepareMicroseconds);
if (!seek_performed)
{
reader.set(request.buf, request.size);
reader.seek(request.offset, SEEK_SET);
}
if (request.ignore)
{
ProfileEvents::increment(ProfileEvents::AsynchronousReaderIgnoredBytes, request.ignore);
reader.ignore(request.ignore);
}
}
auto watch = std::make_unique<Stopwatch>(CLOCK_REALTIME);
if (!seek_performed)
{
reader.set(request.buf, request.size);
reader.seek(request.offset, SEEK_SET);
}
if (request.ignore)
{
ProfileEvents::increment(ProfileEvents::AsynchronousReaderIgnoredBytes, request.ignore);
reader.ignore(request.ignore);
}
bool result = reader.available();
if (!result)
result = reader.next();