You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by GitBox <gi...@apache.org> on 2020/01/08 12:36:58 UTC

[GitHub] [incubator-doris] imay commented on a change in pull request #2710: use cgroups memory limit and cpu cores in container

imay commented on a change in pull request #2710: use cgroups memory limit and cpu cores in container
URL: https://github.com/apache/incubator-doris/pull/2710#discussion_r364203466
 
 

 ##########
 File path: be/src/util/cgroup_util.cpp
 ##########
 @@ -0,0 +1,236 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#include "util/cgroup_util.h"
+
+#include <algorithm>
+#include <fstream>
+#include <iostream>
+#include <utility>
+
+#include <boost/algorithm/string.hpp>
+#include <boost/filesystem.hpp>
+
+#include "gutil/strings/escaping.h"
+#include "gutil/strings/substitute.h"
+#include "util/error_util.h"
+#include "util/string_parser.hpp"
+
+#include "common/names.h"
+
+using boost::algorithm::is_any_of;
+using boost::algorithm::split;
+using boost::algorithm::token_compress_on;
+using strings::CUnescape;
+using std::pair;
+
+namespace doris {
+
+Status CGroupUtil::find_global_cgroup(const string& subsystem, string* path) {
+    ifstream proc_cgroups("/proc/self/cgroup", ios::in);
+    string line;
+    while (true) {
+        if (proc_cgroups.fail()) {
+            return Status::IOError(Substitute("Error reading /proc/self/cgroup: $0", get_str_err_msg()));
+        } else if (proc_cgroups.peek() == std::ifstream::traits_type::eof()) {
+            return Status::NotFound(Substitute("Could not find subsystem $0 in /proc/self/cgroup", subsystem));
+        }
+        // The line format looks like this:
+        // 4:memory:/user.slice
+        // 9:cpu,cpuacct:/user.slice
+        getline(proc_cgroups, line);
+        if (!proc_cgroups.good()) continue;
+        vector<string> fields;
+        split(fields, line, is_any_of(":"));
 
 Review comment:
   You can try split in gutil which is easier to use

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org