當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Rlimit.Max方法代碼示例

本文整理匯總了Golang中syscall.Rlimit.Max方法的典型用法代碼示例。如果您正苦於以下問題:Golang Rlimit.Max方法的具體用法?Golang Rlimit.Max怎麽用?Golang Rlimit.Max使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在syscall.Rlimit的用法示例。


在下文中一共展示了Rlimit.Max方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: setUlimit

func setUlimit(cfg *Config) error {
	var rLimit syscall.Rlimit
	if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rLimit); err != nil {
		return err
	}
	if cfg.NoFiles == 0 {
		rLimit.Max = 1000000
	} else {
		rLimit.Max = cfg.NoFiles
	}
	rLimit.Cur = rLimit.Max
	return syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rLimit)
}
開發者ID:UNwS,項目名稱:docker-from-scratch,代碼行數:13,代碼來源:scratch.go

示例2: checkAndSetUlimit

func checkAndSetUlimit() error {
	var rLimit syscall.Rlimit
	err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rLimit)
	if err != nil {
		return fmt.Errorf("error getting rlimit: %s", err)
	}

	ipfsFileDescNum := int64(ipfsFileDescNum)

	var setting bool
	if rLimit.Cur < ipfsFileDescNum {
		if rLimit.Max < ipfsFileDescNum {
			log.Error("adjusting max")
			rLimit.Max = ipfsFileDescNum
		}
		fmt.Printf("Adjusting current ulimit to %d...\n", ipfsFileDescNum)
		rLimit.Cur = ipfsFileDescNum
		setting = true
	}

	err = syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rLimit)
	if err != nil {
		return fmt.Errorf("error setting ulimit: %s", err)
	}

	if setting {
		fmt.Printf("Successfully raised file descriptor limit to %d.\n", ipfsFileDescNum)
	}

	return nil
}
開發者ID:tswindell,項目名稱:go-ipfs,代碼行數:31,代碼來源:ulimit_freebsd.go

示例3: TestMain

func TestMain(m *testing.M) {
	var lim syscall.Rlimit
	syscall.Getrlimit(syscall.RLIMIT_NOFILE, &lim)
	lim.Cur = 1024000
	lim.Max = 1024000
	syscall.Setrlimit(syscall.RLIMIT_NOFILE, &lim)
}
開發者ID:uin57,項目名稱:frontd,代碼行數:7,代碼來源:reuse_test.go

示例4: main

func main() {
	var rlim syscall.Rlimit
	err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rlim)
	if err != nil {
		fmt.Errorf("獲取Rlimit報錯 %s", err)
		os.Exit(1)
	}
	fmt.Printf("ENV RLIMIT_NOFILE : %+v\n", rlim)

	rlim.Max = 65535
	rlim.Cur = 65535
	//err = syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rlim)
	err = syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rlim)
	if err != nil {
		fmt.Errorf("設置Rlimit報錯 %s", err)
		os.Exit(1)
	}
	//fmt.Printf("ENV RLIMIT_NOFILE : %+v\n", rlim)
	err = syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rlim)
	if err != nil {
		fmt.Errorf("獲取Rlimit報錯 %s", err)
		os.Exit(1)
	}
	fmt.Printf("ENV RLIMIT_NOFILE : %+v\n", rlim)
}
開發者ID:kuuyee,項目名稱:go-apue,代碼行數:25,代碼來源:getrlimit.go

示例5: setOpenFilesLimit

// setOpenFilesLimit sets the open file limit in the kernel
// cur is the soft limit, max is the ceiling (or hard limit) for that limit
func (pm *ProcessManager) setOpenFilesLimit(cur, max uint64) error {
	var rLimit syscall.Rlimit
	// First check if the limits are already what we want
	err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rLimit)
	if err != nil {
		return err
	}

	// If the current values are less than we want, set them
	if rLimit.Cur < cur || rLimit.Max < max {
		if cur > rLimit.Cur {
			rLimit.Cur = cur
		}
		if max > rLimit.Max {
			rLimit.Max = max
		}

		log.Infof("Setting open files limit (soft, hard) to (%v, %v)", rLimit.Cur, rLimit.Max)
		err := syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rLimit)
		if err != nil {
			return err
		}
	}

	return nil
}
開發者ID:sanmiguel,項目名稱:riak-mesos,代碼行數:28,代碼來源:manager_linux.go

示例6: main

func main() {
	runtime.GOMAXPROCS(runtime.NumCPU())
	os.Setenv("GOTRACEBACK", "crash")

	lim := syscall.Rlimit{}
	syscall.Getrlimit(syscall.RLIMIT_NOFILE, &lim)
	if lim.Cur < _MaxOpenfile || lim.Max < _MaxOpenfile {
		lim.Cur = _MaxOpenfile
		lim.Max = _MaxOpenfile
		syscall.Setrlimit(syscall.RLIMIT_NOFILE, &lim)
	}

	ln, err := net.Listen("tcp", ":1153")
	if err != nil {
		log.Fatal(err)
	}
	go TCPServer(ln, queryTypeDNS)

	ln, err = net.Listen("tcp", ":1154")
	if err != nil {
		log.Fatal(err)
	}
	go TCPServer(ln, queryTypeMYIP)

	http.HandleFunc("/myip", HTTPServerMYIP)
	http.HandleFunc("/dns", HTTPServerDNS)
	http.HandleFunc("/health", HTTPServerHealth)
	log.Fatal(http.ListenAndServe(":1053", nil))
}
開發者ID:inter-rpm,項目名稱:httpdns-1,代碼行數:29,代碼來源:main.go

示例7: initLimit

func initLimit() {
	var rLimit syscall.Rlimit
	rLimit.Max = 10000
	rLimit.Cur = 10000
	err := syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rLimit)
	if err != nil {
		fmt.Println("Error Setting Rlimit ", err)
	}
}
開發者ID:Nitecon,項目名稱:consul,代碼行數:9,代碼來源:start.go

示例8: init

func init() {
	var rLimit syscall.Rlimit
	rLimit.Max = 4096
	rLimit.Cur = 4096

	err := syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rLimit)
	if err != nil {
		log.Println("Warning: setrlimit:", err)
	}
}
開發者ID:reth-,項目名稱:mole,代碼行數:10,代碼來源:rlimit.go

示例9: init

// 提升程序可打開的文件描述符上限
func init() {
	var rlim syscall.Rlimit
	if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rlim); err != nil {
		panic(err.Error())
	}
	rlim.Cur = 1000000
	rlim.Max = 1000000
	if err := syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rlim); err != nil {
		panic(err.Error())
	}
}
開發者ID:sunyuantao,項目名稱:windows,代碼行數:12,代碼來源:syscall.go

示例10: main

func main() {
	logging.SetFormatter(logging.MustStringFormatter(format))
	logging.SetLevel(logging.INFO, "gogorobot")
	//logging.SetLevel(logging.DEBUG, "gogorobot")
	//
	// Set the file descriptor limit higher if we've permission
	var rLimit syscall.Rlimit
	err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rLimit)
	if err != nil {
		log.Info(fmt.Sprintf("Error geting rlimit: %s", err))
	}
	rLimit.Max = 65536
	rLimit.Cur = 65536
	err = syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rLimit)
	if err != nil {
		log.Info(fmt.Sprintf("Error setting rlimit: %s", err))
	}
	//
	fetchPipeline := make(chan FetchRequest)
	savePipeline := make(chan RobotResponse)
	// NOTE: Important to pass via pointer
	// Otherwise, a new WaitGroup is created
	var fetchGroup sync.WaitGroup
	var saveGroup sync.WaitGroup

	saveGroup.Add(1)
	go saveRobots(savePipeline, &saveGroup)

	for i := 0; i < 50; i++ {
		fetchGroup.Add(1)
		go fetchRobot(fetchPipeline, savePipeline, &fetchGroup)
	}

	// Insert entries
	reader := bufio.NewReader(os.Stdin)
	for {
		domain, err := reader.ReadString('\n')
		if err != nil {
			break
		}
		domain = strings.TrimRight(domain, "\r\n")
		log.Debug(fmt.Sprintf("MAIN: Providing %s to fetch pipeline", domain))
		fetchPipeline <- FetchRequest{domain, 0}
	}
	// TODO: Temporary fix to allow time for the pipeline to clear (see TODO in fetcher's error area)
	time.Sleep(60 * time.Second)
	close(fetchPipeline)
	log.Notice("Fetching pipeline closed -- waiting for pending fetches to complete")
	//
	fetchGroup.Wait()
	close(savePipeline)
	saveGroup.Wait()
}
開發者ID:Smerity,項目名稱:gogorobot,代碼行數:53,代碼來源:gogorobot.go

示例11: NewServer

func NewServer() *Server {
	s := &Server{
		port:          common.GetConfInt("server", "port", 8080),
		maxClients:    common.GetConfInt("server", "max_clients", 100000),
		clientNum:     0,
		acceptTimeout: common.GetConfSecond("server", "accept_timeout", 60*5),
		connTimeout:   common.GetConfSecond("server", "connection_timeout", 60*3),
		headerLen:     common.GetConfInt("server", "header_length", 10),
		maxBodyLen:    common.GetConfInt("server", "max_body_length", 102400),
		running:       false,
		heartbeat:     time.Now().Unix(),
		workerNum:     common.WorkerNum,
		currentWorker: -1,
		slowread:      common.GetConfSecond("server", "slow_read", 0),
		logger:        common.NewLogger("server"),
	}

	if s == nil {
		fmt.Println("new server failed")
		return nil
	}

	if s.logger == nil {
		fmt.Println("new server logger failed")
		return nil
	}

	ip, err := common.Conf.String("server", "bind")
	if err != nil {
		ip = ""
	}
	s.ip = ip

	max_clients := uint64(s.maxClients)
	if max_clients > 1024 {
		var rlim syscall.Rlimit
		err = syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rlim)
		if err != nil {
			fmt.Println("server get rlimit error: " + err.Error())
			return nil
		}
		rlim.Cur = max_clients
		rlim.Max = max_clients
		err = syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rlim)
		if err != nil {
			fmt.Println("server set rlimit error: " + err.Error())
			return nil
		}
		s.logger.Info("set fd limit to %d", s.maxClients)
	}

	return s
}
開發者ID:dengzhi007,項目名稱:sky,代碼行數:53,代碼來源:server.go

示例12: SetRlimit

func SetRlimit() {
	var rLimit syscall.Rlimit
	rLimit.Max = 999999
	rLimit.Cur = 999999
	err := syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rLimit)
	if err != nil {
		panic(fmt.Sprintf("Error Setting Rlimit '%s'", err))
	}
	err = syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rLimit)
	if err != nil {
		panic(fmt.Sprintf("Error Getting Rlimit '%s'", err))
	}
	fmt.Printf("final: rlimit.Cur = %d, rlimit.Max = %d\n", rLimit.Cur, rLimit.Max)
}
開發者ID:robmurtha,項目名稱:goq,代碼行數:14,代碼來源:rlimit.go

示例13: setHardRLimit

func setHardRLimit(label string, rLimitId int, rLimitMax uint64) error {
	var rlimit syscall.Rlimit

	if err := syscall.Getrlimit(rLimitId, &rlimit); err != nil {
		return fmt.Errorf("container_daemon: getting system limit %s: %s", label, err)
	}

	rlimit.Max = rLimitMax
	if err := syscall.Setrlimit(rLimitId, &rlimit); err != nil {
		return fmt.Errorf("container_daemon: setting hard system limit %s: %s", label, err)
	}

	return nil
}
開發者ID:nagyistoce,項目名稱:garden-linux,代碼行數:14,代碼來源:rlimits_manager.go

示例14: init

func init() {
	var rLimit syscall.Rlimit
	err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rLimit)
	if err != nil {
		fmt.Println("Error Getting Rlimit ", err)
	}

	rLimit.Max = 999999
	rLimit.Cur = 999999
	err = syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rLimit)
	if err != nil {
		fmt.Println("Error Setting Rlimit ", err)
	}
}
開發者ID:philips,項目名稱:earthquake,代碼行數:14,代碼來源:run.go

示例15: MaybeBecomeChildProcess

func MaybeBecomeChildProcess() {
	lrs := os.Getenv("_RUNSIT_LAUNCH_INFO")
	if lrs == "" {
		return
	}
	defer os.Exit(2) // should never make it this far, though

	lr := new(LaunchRequest)
	d := gob.NewDecoder(base64.NewDecoder(base64.StdEncoding, strings.NewReader(lrs)))
	err := d.Decode(lr)
	if err != nil {
		log.Fatalf("Failed to decode LaunchRequest in child: %v", err)
	}
	if lr.NumFiles != 0 {
		var lim syscall.Rlimit
		if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &lim); err != nil {
			log.Fatalf("failed to get NOFILE rlimit: %v", err)
		}
		noFile := rlim_t(lr.NumFiles)
		lim.Cur = noFile
		lim.Max = noFile
		if err := syscall.Setrlimit(syscall.RLIMIT_NOFILE, &lim); err != nil {
			log.Fatalf("failed to set NOFILE rlimit: %v", err)
		}
	}
	if lr.Gid != 0 {
		if err := syscall.Setgid(lr.Gid); err != nil {
			log.Fatalf("failed to Setgid(%d): %v", lr.Gid, err)
		}
	}
	if len(lr.Gids) != 0 {
		if err := syscall.Setgroups(lr.Gids); err != nil {
			log.Printf("setgroups: %v", err)
		}
	}
	if lr.Uid != 0 {
		if err := syscall.Setuid(lr.Uid); err != nil {
			log.Fatalf("failed to Setuid(%d): %v", lr.Uid, err)
		}
	}
	if lr.Path != "" {
		err = os.Chdir(lr.Dir)
		if err != nil {
			log.Fatalf("failed to chdir to %q: %v", lr.Dir, err)
		}
	}
	err = syscall.Exec(lr.Path, lr.Argv, lr.Env)
	log.Fatalf("failed to exec %q: %v", lr.Path, err)
}
開發者ID:kofalt,項目名稱:runsit,代碼行數:49,代碼來源:exec.go


注:本文中的syscall.Rlimit.Max方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。