kv_directory_children_test.go 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. package redis3
  2. import (
  3. "context"
  4. "fmt"
  5. "github.com/go-redis/redis/v8"
  6. "github.com/stvp/tempredis"
  7. "strconv"
  8. "testing"
  9. "time"
  10. )
  11. var names = []string{
  12. "cassandra.in.sh",
  13. "cassandra",
  14. "debug-cql.bat",
  15. "nodetool",
  16. "nodetool.bat",
  17. "source-conf.ps1",
  18. "sstableloader",
  19. "sstableloader.bat",
  20. "sstablescrub",
  21. "sstablescrub.bat",
  22. "sstableupgrade",
  23. "sstableupgrade.bat",
  24. "sstableutil",
  25. "sstableutil.bat",
  26. "sstableverify",
  27. "sstableverify.bat",
  28. "stop-server",
  29. "stop-server.bat",
  30. "stop-server.ps1",
  31. "cassandra.in.bat",
  32. "cqlsh.py",
  33. "cqlsh",
  34. "cassandra.ps1",
  35. "cqlsh.bat",
  36. "debug-cql",
  37. "cassandra.bat",
  38. }
  39. func yTestNameList(t *testing.T) {
  40. server, err := tempredis.Start(tempredis.Config{})
  41. if err != nil {
  42. panic(err)
  43. }
  44. defer server.Term()
  45. client := redis.NewClient(&redis.Options{
  46. Network: "unix",
  47. Addr: server.Socket(),
  48. })
  49. store := newSkipListElementStore("/yyy/bin", client)
  50. var data []byte
  51. for _, name := range names {
  52. nameList := LoadItemList(data, "/yyy/bin", client, store, maxNameBatchSizeLimit)
  53. nameList.WriteName(name)
  54. nameList.ListNames("", func(name string) bool {
  55. println(name)
  56. return true
  57. })
  58. if nameList.HasChanges() {
  59. data = nameList.ToBytes()
  60. }
  61. println()
  62. }
  63. nameList := LoadItemList(data, "/yyy/bin", client, store, maxNameBatchSizeLimit)
  64. nameList.ListNames("", func(name string) bool {
  65. println(name)
  66. return true
  67. })
  68. }
  69. func yBenchmarkNameList(b *testing.B) {
  70. server, err := tempredis.Start(tempredis.Config{})
  71. if err != nil {
  72. panic(err)
  73. }
  74. defer server.Term()
  75. client := redis.NewClient(&redis.Options{
  76. Network: "unix",
  77. Addr: server.Socket(),
  78. })
  79. store := newSkipListElementStore("/yyy/bin", client)
  80. var data []byte
  81. for i := 0; i < b.N; i++ {
  82. nameList := LoadItemList(data, "/yyy/bin", client, store, maxNameBatchSizeLimit)
  83. nameList.WriteName(strconv.Itoa(i) + "namexxxxxxxxxxxxxxxxxxx")
  84. if nameList.HasChanges() {
  85. data = nameList.ToBytes()
  86. }
  87. }
  88. }
  89. func BenchmarkRedis(b *testing.B) {
  90. server, err := tempredis.Start(tempredis.Config{})
  91. if err != nil {
  92. panic(err)
  93. }
  94. defer server.Term()
  95. client := redis.NewClient(&redis.Options{
  96. Network: "unix",
  97. Addr: server.Socket(),
  98. })
  99. for i := 0; i < b.N; i++ {
  100. client.ZAddNX(context.Background(), "/yyy/bin", &redis.Z{Score: 0, Member: strconv.Itoa(i) + "namexxxxxxxxxxxxxxxxxxx"})
  101. }
  102. }
  103. func xTestNameListAdd(t *testing.T) {
  104. server, err := tempredis.Start(tempredis.Config{})
  105. if err != nil {
  106. panic(err)
  107. }
  108. defer server.Term()
  109. client := redis.NewClient(&redis.Options{
  110. Addr: "localhost:6379",
  111. Password: "",
  112. DB: 0,
  113. })
  114. client.FlushAll(context.Background())
  115. N := 364800
  116. ts0 := time.Now()
  117. store := newSkipListElementStore("/y", client)
  118. var data []byte
  119. nameList := LoadItemList(data, "/y", client, store, 100000)
  120. for i := 0; i < N; i++ {
  121. nameList.WriteName(fmt.Sprintf("%8d", i))
  122. }
  123. ts1 := time.Now()
  124. for i := 0; i < N; i++ {
  125. client.ZAddNX(context.Background(), "/x", &redis.Z{Score: 0, Member: fmt.Sprintf("name %8d", i)})
  126. }
  127. ts2 := time.Now()
  128. fmt.Printf("%v %v", ts1.Sub(ts0), ts2.Sub(ts1))
  129. /*
  130. keys := client.Keys(context.Background(), "/*m").Val()
  131. for _, k := range keys {
  132. println("key", k)
  133. for i, v := range client.ZRangeByLex(context.Background(), k, &redis.ZRangeBy{
  134. Min: "-",
  135. Max: "+",
  136. }).Val() {
  137. println(" ", i, v)
  138. }
  139. }
  140. */
  141. }
  142. func xBenchmarkNameList(b *testing.B) {
  143. server, err := tempredis.Start(tempredis.Config{})
  144. if err != nil {
  145. panic(err)
  146. }
  147. defer server.Term()
  148. client := redis.NewClient(&redis.Options{
  149. Addr: "localhost:6379",
  150. Password: "",
  151. DB: 0,
  152. })
  153. store := newSkipListElementStore("/yyy/bin", client)
  154. var data []byte
  155. for i := 0; i < b.N; i++ {
  156. nameList := LoadItemList(data, "/yyy/bin", client, store, maxNameBatchSizeLimit)
  157. nameList.WriteName(fmt.Sprintf("name %8d", i))
  158. if nameList.HasChanges() {
  159. data = nameList.ToBytes()
  160. }
  161. }
  162. }
  163. func xBenchmarkRedis(b *testing.B) {
  164. client := redis.NewClient(&redis.Options{
  165. Addr: "localhost:6379",
  166. Password: "",
  167. DB: 0,
  168. })
  169. for i := 0; i < b.N; i++ {
  170. client.ZAddNX(context.Background(), "/xxx/bin", &redis.Z{Score: 0, Member: fmt.Sprintf("name %8d", i)})
  171. }
  172. }