Impala
Impalaistheopensource,nativeanalyticdatabaseforApacheHadoop.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
cgroups-mgr.h
Go to the documentation of this file.
1 // Copyright 2012 Cloudera Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef IMPALA_UTIL_CGROUPS_MGR_H
16 #define IMPALA_UTIL_CGROUPS_MGR_H
17 
18 #include <string>
19 #include <boost/thread/mutex.hpp>
20 #include <boost/unordered_map.hpp>
21 #include "common/status.h"
22 #include "util/metrics.h"
23 #include "util/thread.h"
24 
25 namespace impala {
26 
29 //
36 //
41 //
45 
65 //
79 class CgroupsMgr {
80  public:
81  CgroupsMgr(MetricGroup* metrics);
82 
86  Status Init(const std::string& cgroups_hierarchy_path,
87  const std::string& staging_cgroup);
88 
92  std::string UniqueIdToCgroup(const std::string& unique_id) const;
93 
96  int32_t VirtualCoresToCpuShares(int16_t v_cpu_cores);
97 
103  Status RegisterFragment(const TUniqueId& fragment_instance_id,
104  const std::string& cgroup, bool* is_first);
105 
112  Status UnregisterFragment(const TUniqueId& fragment_instance_id,
113  const std::string& cgroup);
114 
118  Status CreateCgroup(const std::string& cgroup, bool if_not_exists) const;
119 
123  Status DropCgroup(const std::string& cgroup, bool if_exists) const;
124 
128  Status SetCpuShares(const std::string& cgroup, int32_t num_shares);
129 
135  Status AssignThreadToCgroup(const Thread& thread, const std::string& cgroup) const;
136 
141  Status RelocateThreads(const std::string& src_cgroup,
142  const std::string& dst_cgroup) const;
143 
144  private:
148  Status GetCgroupPaths(const std::string& cgroup,
149  std::string* cgroup_path, std::string* tasks_path) const;
150 
153 
156 
159  std::string staging_cgroup_;
160 
162  boost::mutex active_cgroups_lock_;
163 
167  boost::unordered_map<std::string, int32_t> active_cgroups_;
168 };
169 
170 }
171 
172 #endif
int32_t VirtualCoresToCpuShares(int16_t v_cpu_cores)
Definition: cgroups-mgr.cc:59
Status CreateCgroup(const std::string &cgroup, bool if_not_exists) const
Definition: cgroups-mgr.cc:64
Status DropCgroup(const std::string &cgroup, bool if_exists) const
Definition: cgroups-mgr.cc:83
Status RegisterFragment(const TUniqueId &fragment_instance_id, const std::string &cgroup, bool *is_first)
Definition: cgroups-mgr.cc:198
TODO: Consider allowing fragment IDs as category parameters.
Definition: thread.h:45
std::string staging_cgroup_
Definition: cgroups-mgr.h:159
std::string UniqueIdToCgroup(const std::string &unique_id) const
Definition: cgroups-mgr.cc:54
class SimpleMetric< int64_t, TMetricKind::COUNTER > IntCounter
Definition: metrics.h:320
MetricGroups may be organised hierarchically as a tree.
Definition: metrics.h:200
Status SetCpuShares(const std::string &cgroup, int32_t num_shares)
Definition: cgroups-mgr.cc:101
boost::mutex active_cgroups_lock_
Protects active_cgroups_.
Definition: cgroups-mgr.h:162
std::string cgroups_hierarchy_path_
Root of the CPU cgroup hierarchy. Created cgroups are placed directly under it.
Definition: cgroups-mgr.h:155
CgroupsMgr(MetricGroup *metrics)
Definition: cgroups-mgr.cc:40
Status Init(const std::string &cgroups_hierarchy_path, const std::string &staging_cgroup)
Definition: cgroups-mgr.cc:45
Status AssignThreadToCgroup(const Thread &thread, const std::string &cgroup) const
Definition: cgroups-mgr.cc:142
Status RelocateThreads(const std::string &src_cgroup, const std::string &dst_cgroup) const
Definition: cgroups-mgr.cc:161
boost::unordered_map< std::string, int32_t > active_cgroups_
Definition: cgroups-mgr.h:167
Status GetCgroupPaths(const std::string &cgroup, std::string *cgroup_path, std::string *tasks_path) const
Definition: cgroups-mgr.cc:120
IntCounter * active_cgroups_metric_
Number of currently active Impala-managed cgroups.
Definition: cgroups-mgr.h:152
Status UnregisterFragment(const TUniqueId &fragment_instance_id, const std::string &cgroup)
Definition: cgroups-mgr.cc:215