0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
LoadThread.cc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2007-2015 Hypertable, Inc.
3  *
4  * This file is part of Hypertable.
5  *
6  * Hypertable is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 3
9  * of the License, or any later version.
10  *
11  * Hypertable is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19  * 02110-1301, USA.
20  */
21 #include <Common/Compat.h>
22 
23 #include <ctime>
24 #include <cmath>
25 
26 #include "LoadThread.h"
27 
28 using namespace Hypertable;
29 using namespace std;
30 
32  unique_lock<mutex> lock(m_state.mutex);
33  clock_t start_clocks=0, stop_clocks=0;
34  double latency = 0.0;
35  double clocks_per_usec = (double)CLOCKS_PER_SEC / 1000000.0;
36 
37  try {
38  m_mutator.reset(m_table->create_mutator(0, m_mutator_flags,
39  m_shared_mutator_flush_interval));
40  }
41  catch (Exception &e) {
42  HT_FATAL_OUT << e << HT_END;
43  }
44 
45  while (!m_state.finished || !m_state.requests.empty()) {
46  m_state.cond.wait(lock, [this](){
47  return !m_state.requests.empty() || m_state.finished; });
48  if (!m_state.requests.empty()) {
49  LoadRec *request = m_state.requests.front();
50 
51  start_clocks = clock();
52 
53  if (request->is_delete)
54  m_mutator->set_delete(request->key);
55  else
56  m_mutator->set(request->key, request->value, request->value_len);
57  m_mutator->flush();
58 
59  stop_clocks = clock();
60  if (stop_clocks < start_clocks)
61  latency = ((std::numeric_limits<clock_t>::max() - start_clocks) + stop_clocks) / clocks_per_usec;
62  else
63  latency = (stop_clocks-start_clocks) / clocks_per_usec;
64  m_state.cum_latency += latency;
65  m_state.cum_sq_latency += pow(latency,2);
66  if (m_state.min_latency == 0 || latency < m_state.min_latency)
67  m_state.min_latency = latency;
68  if (latency > m_state.max_latency)
69  m_state.max_latency = latency;
70 
71  m_state.requests.pop_front();
72  m_state.garbage.push_back(request);
73  }
74  }
75 
76 }
STL namespace.
const void * value
Definition: ParallelLoad.h:87
Compatibility Macros for C/C++.
#define HT_END
Definition: Logger.h:220
::uint32_t value_len
Definition: ParallelLoad.h:88
Hypertable definitions
This is a generic exception class for Hypertable.
Definition: Error.h:314
#define HT_FATAL_OUT
Definition: Logger.h:347