mirror of
				https://github.com/TeaOSLab/EdgeNode.git
				synced 2025-11-04 16:00:25 +08:00 
			
		
		
		
	
		
			
	
	
		
			30 lines
		
	
	
		
			493 B
		
	
	
	
		
			Go
		
	
	
	
	
	
		
		
			
		
	
	
			30 lines
		
	
	
		
			493 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
							 | 
						||
| 
								 | 
							
								}
							 |