Skip to content

Commit

Permalink
Add query time calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben committed Apr 12, 2017
1 parent cf2e18d commit bc227df
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 25 deletions.
46 changes: 23 additions & 23 deletions src/http/HttpReply.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ namespace Http {

void HttpReply::process()
{
LOG_DEBUG("HttpReply::process()");
LOG_DEBUG("HttpReply::process()");
std::stringstream stream;

if (m_replyHeaders) {
Expand Down Expand Up @@ -88,7 +88,7 @@ namespace Http {

void HttpReply::handleRetrievalRequest(Method method)
{
LOG_DEBUG("HttpReply::handleRetrievalRequest()");
LOG_DEBUG("HttpReply::handleRetrievalRequest()");
std::stringstream stream;

if (!m_request->hasMatchingSite()) {
Expand All @@ -104,7 +104,7 @@ namespace Http {
bool HttpReply::requestFileContents(Method method, const SiteConfig* site,
std::stringstream& stream)
{
LOG_DEBUG("HttpReply::requestFileContents()");
LOG_DEBUG("HttpReply::requestFileContents()");
std::string page;
bool found = false;
size_t bytes = 0;
Expand Down Expand Up @@ -189,7 +189,7 @@ namespace Http {
Code HttpReply::requestPartialFileContents(const std::string& page,
std::stringstream& stream, size_t& bytes)
{
LOG_DEBUG("HttpReply::requestPartialFileContents()");
LOG_DEBUG("HttpReply::requestPartialFileContents()");
std::tuple<int64_t, int64_t> range = m_request->getRangeRequest();
int64_t from = std::get<0>(range);
int64_t to = std::get<1>(range);
Expand Down Expand Up @@ -226,23 +226,23 @@ namespace Http {
m_contentLength = totalBytes;
setFlag(LargeFileRequest, true);

std::stringstream stream;
std::stringstream stream;

if (FileUtils::readFile(page, from, to, stream, bytes) == Code::Ok) {
if (to == totalBytes - 1) {
m_request->setCompleted(true);
post(stream);
return true;
} else {
post(stream);
}
if (FileUtils::readFile(page, from, to, stream, bytes) == Code::Ok) {
if (to == totalBytes - 1) {
m_request->setCompleted(true);
post(stream);
return true;
} else {
post(stream);
}

} else {
return false;
}
} else {
return false;
}

from = to + 1;
return requestLargeFileContents(page, from, totalBytes);
from = to + 1;
return requestLargeFileContents(page, from, totalBytes);
}

void HttpReply::post(std::stringstream& stream)
Expand Down Expand Up @@ -292,7 +292,7 @@ namespace Http {
bool HttpReply::chunkResponse(HttpBufferPtr httpBuffer,
std::vector<boost::asio::const_buffer>& buffers)
{
LOG_DEBUG("HttpReply::chunkResponse()");
LOG_DEBUG("HttpReply::chunkResponse()");
size_t size = 0;

// We cannot take the total Content Length here because the gzip compression changed that
Expand Down Expand Up @@ -328,7 +328,7 @@ namespace Http {
bool HttpReply::encodeResponse(HttpBufferPtr httpBuffer,
std::vector<boost::asio::const_buffer>& buffers)
{
LOG_DEBUG("HttpReply::encodeResponse()");
LOG_DEBUG("HttpReply::encodeResponse()");
std::vector<boost::asio::const_buffer> result;

if (!m_gzipBusy) {
Expand Down Expand Up @@ -381,7 +381,7 @@ namespace Http {

void HttpReply::buildHeaders(HttpBufferPtr httpBuffer)
{
LOG_DEBUG("HttpReply::buildHeaders()");
LOG_DEBUG("HttpReply::buildHeaders()");
std::stringstream stream;
stream << "HTTP/" << m_request->httpVersion() << " ";
stringValue(m_status, stream);
Expand Down Expand Up @@ -411,7 +411,7 @@ namespace Http {
void HttpReply::buildErrorResponse(Code error, std::stringstream& stream,
bool closeConnection)
{
LOG_DEBUG("HttpReply::buildErrorResponse()");
LOG_DEBUG("HttpReply::buildErrorResponse()");
bool found = false;
size_t bytes = 0;

Expand Down Expand Up @@ -447,7 +447,7 @@ namespace Http {
#ifdef ENABLE_GZIP
void HttpReply::initGzip()
{
LOG_DEBUG("HttpReply::initGzip()");
LOG_DEBUG("HttpReply::initGzip()");
m_gzip.zalloc = Z_NULL;
m_gzip.zfree = Z_NULL;
m_gzip.opaque = Z_NULL;
Expand Down
3 changes: 2 additions & 1 deletion src/http/HttpReply.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ namespace Http {
std::stringstream& stream);
Code requestPartialFileContents(const std::string& page,
std::stringstream& stream, size_t& bytes);
bool requestLargeFileContents(const std::string& page, size_t from, size_t totalBytes);
bool requestLargeFileContents(const std::string& page, size_t from,
size_t totalBytes);

boost::asio::const_buffer buf(HttpBufferPtr buffer, const std::string& s);
boost::asio::const_buffer buf(HttpBufferPtr buffer, char* buf, size_t s);
Expand Down
7 changes: 6 additions & 1 deletion src/http/HttpRequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ namespace Http {
void HttpRequest::setCompleted(bool completed)
{
m_completed = completed;
m_endTs = std::chrono::high_resolution_clock::now();
auto duration = std::chrono::duration_cast<std::chrono::microseconds>
( m_endTs - m_startTs ).count();
LOG_INFO(queryString() << "- processing time : " << duration << " ms");
}

bool HttpRequest::supportsCompression() const
Expand Down Expand Up @@ -126,7 +130,8 @@ namespace Http {

Code HttpRequest::parse()
{
LOG_DEBUG("HttpRequest::parse()");
m_startTs = std::chrono::high_resolution_clock::now();
LOG_DEBUG("HttpRequest::parse()");
size_t pos = m_request.find_first_of("\r\n");

if (pos == std::string::npos) {
Expand Down
5 changes: 5 additions & 0 deletions src/http/HttpRequest.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include "Http.h"
#include "core/Config.h"

#include <chrono>

namespace Http {
class HttpHeaders;

Expand Down Expand Up @@ -49,6 +51,9 @@ namespace Http {
bool m_completed;
Host m_host;

std::chrono::high_resolution_clock::time_point m_startTs;
std::chrono::high_resolution_clock::time_point m_endTs;

friend class HttpReply;

};
Expand Down

0 comments on commit bc227df

Please sign in to comment.