本文整理匯總了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)
}
示例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: 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)
}
示例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)
}
示例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
}
示例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))
}
示例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)
}
}
示例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)
}
}
示例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())
}
}
示例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()
}
示例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
}
示例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)
}
示例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
}
示例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)
}
}
示例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)
}