You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

84 lines
2.1 KiB

5 years ago
5 years ago
5 years ago
5 years ago
6 years ago
5 years ago
3 years ago
  1. package main
  2. import (
  3. "flag"
  4. "fmt"
  5. "github.com/seaweedfs/seaweedfs/weed/pb"
  6. "log"
  7. "math/rand"
  8. "time"
  9. "context"
  10. "google.golang.org/grpc"
  11. "github.com/seaweedfs/seaweedfs/weed/operation"
  12. "github.com/seaweedfs/seaweedfs/weed/security"
  13. "github.com/seaweedfs/seaweedfs/weed/util"
  14. )
  15. var (
  16. master = flag.String("master", "127.0.0.1:9333", "the master server")
  17. repeat = flag.Int("n", 5, "repeat how many times")
  18. garbageThreshold = flag.Float64("garbageThreshold", 0.3, "garbageThreshold")
  19. replication = flag.String("replication", "", "replication 000, 001, 002, etc")
  20. )
  21. func main() {
  22. flag.Parse()
  23. util.LoadConfiguration("security", false)
  24. grpcDialOption := security.LoadClientTLS(util.GetViper(), "grpc.client")
  25. genFile(grpcDialOption, 0)
  26. go func() {
  27. for {
  28. println("vacuum threshold", *garbageThreshold)
  29. _, _, err := util.Get(fmt.Sprintf("http://%s/vol/vacuum?garbageThreshold=%f", pb.ServerAddress(*master).ToHttpAddress(), *garbageThreshold))
  30. if err != nil {
  31. log.Fatalf("vacuum: %v", err)
  32. }
  33. time.Sleep(time.Second)
  34. }
  35. }()
  36. for i := 0; i < *repeat; i++ {
  37. // create 2 files, and delete one of them
  38. assignResult, targetUrl := genFile(grpcDialOption, i)
  39. util.Delete(targetUrl, string(assignResult.Auth))
  40. }
  41. }
  42. func genFile(grpcDialOption grpc.DialOption, i int) (*operation.AssignResult, string) {
  43. assignResult, err := operation.Assign(func(_ context.Context) pb.ServerAddress { return pb.ServerAddress(*master) }, grpcDialOption, &operation.VolumeAssignRequest{
  44. Count: 1,
  45. Replication: *replication,
  46. })
  47. if err != nil {
  48. log.Fatalf("assign: %v", err)
  49. }
  50. data := make([]byte, 1024)
  51. rand.Read(data)
  52. targetUrl := fmt.Sprintf("http://%s/%s", assignResult.Url, assignResult.Fid)
  53. uploadOption := &operation.UploadOption{
  54. UploadUrl: targetUrl,
  55. Filename: fmt.Sprintf("test%d", i),
  56. Cipher: false,
  57. IsInputCompressed: true,
  58. MimeType: "bench/test",
  59. PairMap: nil,
  60. Jwt: assignResult.Auth,
  61. }
  62. _, err = operation.UploadData(data, uploadOption)
  63. if err != nil {
  64. log.Fatalf("upload: %v", err)
  65. }
  66. return assignResult, targetUrl
  67. }