本文整理汇总了Golang中syscall.Rlimit.Cur方法的典型用法代码示例。如果您正苦于以下问题:Golang Rlimit.Cur方法的具体用法?Golang Rlimit.Cur怎么用?Golang Rlimit.Cur使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类syscall.Rlimit
的用法示例。
在下文中一共展示了Rlimit.Cur方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: 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
}
示例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
}
示例3: 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))
}
示例4: raiseFdLimit
// raiseFdLimit tries to maximize the file descriptor allowance of this process
// to the maximum hard-limit allowed by the OS.
func raiseFdLimit(max uint64) error {
// Get the current limit
var limit syscall.Rlimit
if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &limit); err != nil {
return err
}
// Try to update the limit to the max allowance
limit.Cur = limit.Max
if limit.Cur > max {
limit.Cur = max
}
if err := syscall.Setrlimit(syscall.RLIMIT_NOFILE, &limit); err != nil {
return err
}
return nil
}
示例5: 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)
}
示例6: 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
}
示例7: 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)
}
示例8: 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
}
示例9: 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)
}
示例10: 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
}
示例11: 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)
}
示例12: 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)
}
}
示例13: 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
}
}
示例14: 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)
}
}
示例15: 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())
}
}