lazyfree.tcl 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. start_server {tags {"lazyfree"}} {
  2. test "UNLINK can reclaim memory in background" {
  3. set orig_mem [s used_memory]
  4. set args {}
  5. for {set i 0} {$i < 100000} {incr i} {
  6. lappend args $i
  7. }
  8. r sadd myset {*}$args
  9. assert {[r scard myset] == 100000}
  10. set peak_mem [s used_memory]
  11. assert {[r unlink myset] == 1}
  12. assert {$peak_mem > $orig_mem+1000000}
  13. wait_for_condition 50 100 {
  14. [s used_memory] < $peak_mem &&
  15. [s used_memory] < $orig_mem*2
  16. } else {
  17. fail "Memory is not reclaimed by UNLINK"
  18. }
  19. }
  20. test "FLUSHDB ASYNC can reclaim memory in background" {
  21. set orig_mem [s used_memory]
  22. set args {}
  23. for {set i 0} {$i < 100000} {incr i} {
  24. lappend args $i
  25. }
  26. r sadd myset {*}$args
  27. assert {[r scard myset] == 100000}
  28. set peak_mem [s used_memory]
  29. r flushdb async
  30. assert {$peak_mem > $orig_mem+1000000}
  31. wait_for_condition 50 100 {
  32. [s used_memory] < $peak_mem &&
  33. [s used_memory] < $orig_mem*2
  34. } else {
  35. fail "Memory is not reclaimed by FLUSHDB ASYNC"
  36. }
  37. }
  38. }