mirror of
				https://github.com/TeaOSLab/EdgeAPI.git
				synced 2025-11-05 00:11:55 +08:00 
			
		
		
		
	
		
			
				
	
	
		
			30 lines
		
	
	
		
			497 B
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			30 lines
		
	
	
		
			497 B
		
	
	
	
		
			Go
		
	
	
	
	
	
// +build darwin
 | 
						|
 | 
						|
package utils
 | 
						|
 | 
						|
import (
 | 
						|
	"syscall"
 | 
						|
)
 | 
						|
 | 
						|
// set resource limit
 | 
						|
func SetRLimit(limit uint64) error {
 | 
						|
	rLimit := &syscall.Rlimit{}
 | 
						|
	err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, rLimit)
 | 
						|
	if err != nil {
 | 
						|
		return err
 | 
						|
	}
 | 
						|
 | 
						|
	if rLimit.Cur < limit {
 | 
						|
		rLimit.Cur = limit
 | 
						|
	}
 | 
						|
	if rLimit.Max < limit {
 | 
						|
		rLimit.Max = limit
 | 
						|
	}
 | 
						|
	return syscall.Setrlimit(syscall.RLIMIT_NOFILE, rLimit)
 | 
						|
}
 | 
						|
 | 
						|
// set best resource limit value
 | 
						|
func SetSuitableRLimit() {
 | 
						|
	_ = SetRLimit(4096 * 100) // 1M=100Files
 | 
						|
}
 |