如何释放 beanstalkd 所使用的内存?

作者: gopher001创建于 2023年6月23日更新于 2023年6月23日
  1. First, start the beanstalkd server by the command: /usr/local/bin/beanstalkd -l 0.0.0.0 -p 11300 -u beanstalkd -b /var/lib/beanstalkd/binlog -f 1000
  2. Then, I execute top -u beanstalkd, and get the results (RES: 1684):
PID USER      PR  NI    VIRT    RES    SHR S  %CPU  %MEM     TIME+ COMMAND                                                                         
1865 beansta+  20   0    2612   1684   1580 S   0.0   0.1   0:00.16 beanstalkd                                                                      

Execute telnet 127.0.0.1 11300 and type stats to get the results:

OK 982
---
current-jobs-urgent: 0
current-jobs-ready: 0
current-jobs-reserved: 0
current-jobs-delayed: 0
current-jobs-buried: 0
cmd-put: 0
cmd-peek: 0
cmd-peek-ready: 0
cmd-peek-delayed: 0
cmd-peek-buried: 0
cmd-reserve: 0
cmd-reserve-with-timeout: 0
cmd-delete: 0
cmd-release: 0
cmd-use: 0
cmd-watch: 0
cmd-ignore: 0
cmd-bury: 0
cmd-kick: 0
cmd-touch: 0
cmd-stats: 2
cmd-stats-job: 0
cmd-stats-tube: 0
cmd-list-tubes: 0
cmd-list-tube-used: 0
cmd-list-tubes-watched: 0
cmd-pause-tube: 0
job-timeouts: 0
total-jobs: 0
max-job-size: 65535
current-tubes: 1
current-connections: 1
current-producers: 0
current-workers: 0
current-waiting: 0
total-connections: 2
pid: 1865
version: "1.13"
rusage-utime: 0.055940
rusage-stime: 0.119873
uptime: 1335
binlog-oldest-index: 57
binlog-current-index: 57
binlog-records-migrated: 0
binlog-records-written: 0
binlog-max-size: 10485760
draining: false
id: 112c3a2a07cde8db
hostname: "debian"
os: "#1 SMP Debian 5.10.140-1 (2022-09-02)"
platform: "x86_64"
3. Then, I put many jobs into the queue by golang code:

package main import ( "GitHub.com/beanstalkd/go-beanstalk" "log" "time" ) func main() { c, err := beanstalk.Dial("tcp", "127.0.0.1:11300") if err != nil { log.Fatalln(err) } defer c.Close()

for {
	msg := time.Now().Format("2006-01-02 15:04:05")
	jobId, err := c.Put([]byte(msg), 0, 0, time.Second)
	if err != nil {
		log.Println("put job err:" + err.Error())
	} else {
		log.Printf("put job success,jobId=%d\n", jobId)
	}
	time.Sleep(time.Millisecond)
}

} 4. Check the results of top -u beanstalkd (RES: 49648):

PID USER      PR  NI    VIRT    RES    SHR S  %CPU  %MEM     TIME+ COMMAND                                                                         
1865 beansta+  20   0   50812  49648   1588 S   0.0   2.5   0:13.15 beanstalkd

The results of stats:

OK 1008
---
current-jobs-urgent: 223611
current-jobs-ready: 223611
current-jobs-reserved: 0
current-jobs-delayed: 0
current-jobs-buried: 0
cmd-put: 223611
cmd-peek: 0
cmd-peek-ready: 0
cmd-peek-delayed: 0
cmd-peek-buried: 0
cmd-reserve: 0
cmd-reserve-with-timeout: 0
cmd-delete: 0
cmd-release: 0
cmd-use: 0
cmd-watch: 0
cmd-ignore: 0
cmd-bury: 0
cmd-kick: 0
cmd-touch: 0
cmd-stats: 3
cmd-stats-job: 0
cmd-stats-tube: 0
cmd-list-tubes: 0
cmd-list-tube-used: 0
cmd-list-tubes-watched: 0
cmd-pause-tube: 0
job-timeouts: 0
total-jobs: 223611
max-job-size: 65535
…

内容来源: beanstalkd/beanstalkd