当前位置: 首页>>代码示例>>Golang>>正文


Golang syscall.Rlimit类代码示例

本文整理汇总了Golang中syscall.Rlimit的典型用法代码示例。如果您正苦于以下问题:Golang Rlimit类的具体用法?Golang Rlimit怎么用?Golang Rlimit使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Rlimit类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: 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

示例2: 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

示例3: MaximizeOpenFileLimit

// MaximizeOpenFileLimit tries to set the resource limit RLIMIT_NOFILE (number
// of open file descriptors) to the max (hard limit), if the current (soft
// limit) is below the max. Returns the new (though possibly unchanged) limit,
// or an error if it could not be changed.
func MaximizeOpenFileLimit() (int, error) {
	// Get the current limit on number of open files.
	var lim syscall.Rlimit
	if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &lim); err != nil {
		return 0, err
	}

	// If we're already at max, there's no need to try to raise the limit.
	if lim.Cur >= lim.Max {
		return int(lim.Cur), nil
	}

	// Try to increase the limit to the max.
	oldLimit := lim.Cur
	lim.Cur = lim.Max
	if err := syscall.Setrlimit(syscall.RLIMIT_NOFILE, &lim); err != nil {
		return int(oldLimit), err
	}

	// If the set succeeded, perform a new get to see what happened. We might
	// have gotten a value lower than the one in lim.Max, if lim.Max was
	// something that indicated "unlimited" (i.e. intmax).
	if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &lim); err != nil {
		// We don't really know the correct value here since Getrlimit
		// mysteriously failed after working once... Shouldn't ever happen, I
		// think.
		return 0, err
	}

	return int(lim.Cur), nil
}
开发者ID:letiemble,项目名称:syncthing,代码行数:35,代码来源:rlimit_unix.go

示例4: 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

示例5: 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

示例6: SetLimits

// SetLimits raises some process limits to values which allow dcrd and
// associated utilities to run.
func SetLimits() error {
	var rLimit syscall.Rlimit

	err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rLimit)
	if err != nil {
		return err
	}
	if rLimit.Cur > fileLimitWant {
		return nil
	}
	if rLimit.Max < fileLimitMin {
		err = fmt.Errorf("need at least %v file descriptors",
			fileLimitMin)
		return err
	}
	if rLimit.Max < fileLimitWant {
		rLimit.Cur = rLimit.Max
	} else {
		rLimit.Cur = fileLimitWant
	}
	err = syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rLimit)
	if err != nil {
		// try min value
		rLimit.Cur = fileLimitMin
		err = syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rLimit)
		if err != nil {
			return err
		}
	}

	return nil
}
开发者ID:decred,项目名称:dcrd,代码行数:34,代码来源:limits_unix.go

示例7: 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

示例8: TestGetSoftFDLimitWithCurrent

func TestGetSoftFDLimitWithCurrent(t *testing.T) {

	requestedSoftFDLimit := uint64(1024)
	currentSoftFdLimit := uint64(2048)
	currentHardFdLimit := uint64(4096)

	limit := syscall.Rlimit{
		Cur: currentSoftFdLimit,
		Max: currentHardFdLimit,
	}

	requiresUpdate, softFDLimit := getSoftFDLimit(
		requestedSoftFDLimit,
		limit,
	)
	assert.False(t, requiresUpdate)

	limit.Cur = uint64(512)

	requiresUpdate, softFDLimit = getSoftFDLimit(
		requestedSoftFDLimit,
		limit,
	)
	assert.True(t, requiresUpdate)
	assert.Equals(t, softFDLimit, requestedSoftFDLimit)

}
开发者ID:ethanfrey,项目名称:sync_gateway,代码行数:27,代码来源:rlimit_test.go

示例9: SetMaxFileDescriptors

// Set Max File Descriptor limits
//
// Background information:
//
// - SG docs
//   http://developer.couchbase.com/documentation/mobile/1.1.0/develop/guides/sync-gateway/os-level-tuning/max-file-descriptors/index.html
// - Related SG issues
//   https://github.com/couchbase/sync_gateway/issues/1083
// - Hard limit vs Soft limit
//   http://unix.stackexchange.com/questions/29577/ulimit-difference-between-hard-and-soft-limits
func SetMaxFileDescriptors(requestedSoftFDLimit uint64) (uint64, error) {

	var limits syscall.Rlimit

	if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &limits); err != nil {
		return 0, err
	}

	requiresUpdate, recommendedSoftFDLimit := getSoftFDLimit(
		requestedSoftFDLimit,
		limits,
	)

	// No call to Setrlimit required, because the requested soft limit is lower than current soft limit
	if !requiresUpdate {
		return 0, nil
	}

	// Update the soft limit (but don't bother updating the hard limit, since only root can do that,
	// and it's assumed that this process is not running as root)
	limits.Cur = recommendedSoftFDLimit
	err := syscall.Setrlimit(syscall.RLIMIT_NOFILE, &limits)

	if err == nil {
		Logf("Configured process to allow %d open file descriptors", recommendedSoftFDLimit)
	}

	return recommendedSoftFDLimit, err

}
开发者ID:ethanfrey,项目名称:sync_gateway,代码行数:40,代码来源:rlimit.go

示例10: upLimitToHard

// upLimitToHard ups a resource limit identified
// by the resource argument to it's hard limit
// the returned error is either from syscall.(Get|Set)rlimit
func upLimitToHard(resource int) error {
	var resLimit = new(syscall.Rlimit)
	if err := syscall.Getrlimit(resource, resLimit); err != nil {
		return err
	}
	resLimit.Cur = resLimit.Max
	return syscall.Setrlimit(resource, resLimit)
}
开发者ID:na--,项目名称:nedomi,代码行数:11,代码来源:main.go

示例11: 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

示例12: main

func main() {
	log.Println("livesyncd running")
	log.Println("Stop with [CTRL] + [c]")
	log.Println("Ignore: ", config.Ignore)

	rlimit := new(syscall.Rlimit)
	syscall.Getrlimit(syscall.RLIMIT_NOFILE, rlimit)

	rlimit.Cur = rlimit.Max

	err := syscall.Setrlimit(syscall.RLIMIT_NOFILE, rlimit)

	if err != nil {
		log.Panicf("Could not change Rlimit: %q", err)
	}

	watcher, err := fsnotify.NewWatcher()

	if err != nil {
		log.Panicln(err)
	}

	events := make(chan *SyncEvent)
	quitSync := make(chan bool)

	quitWatcher := make(chan bool)

	sigInt := make(chan os.Signal)
	signal.Notify(sigInt, os.Interrupt)

	StartSFTPSync(events, quitSync, config)
	startWatchLoop(events, quitWatcher, watcher)

	watched := addWatchesRecursive(root, watcher)

	log.Printf("Found %d directories to watch\n", watched)

	select {
	case <-sigInt:
		log.Println("Stopping to watch...")

		// Wait until the watcher has finished quitting
		quitWatcher <- true
		log.Println("Done")

		// Close all file handles, opened by the watcher
		watcher.Close()

		log.Println("Stopping Sync Backend...")
		quitSync <- true
		<-quitSync
		log.Println("Done")

		return
	}
}
开发者ID:CHH,项目名称:livesyncd,代码行数:56,代码来源:livesyncd.go

示例13: 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

示例14: 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

示例15: setMaxOpenFiles

// For all unixes we need to bump allowed number of open files to a
// higher value than its usual default of '1024'. The reasoning is
// that this value is too small for a server.
func setMaxOpenFiles() error {
	var rLimit syscall.Rlimit
	err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rLimit)
	if err != nil {
		return err
	}
	// Set the current limit to Max, it is usually around 4096.
	// TO increase this limit further user has to manually edit
	// `/etc/security/limits.conf`
	rLimit.Cur = rLimit.Max
	return syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rLimit)
}
开发者ID:hackintoshrao,项目名称:minio,代码行数:15,代码来源:server-rlimit-nix.go


注:本文中的syscall.Rlimit类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。