Skip to content
This repository was archived by the owner on Jan 25, 2025. It is now read-only.

Commit

Permalink
Merge pull request #2 from nranchev/object_cleanup
Browse files Browse the repository at this point in the history
Cleanup objects created by this tool at the end of a run
  • Loading branch information
nranchev authored Jan 27, 2017
2 parents 1c5d05a + ad1aa64 commit aafa129
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions s3bench.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ func main() {
objectSize := flag.Int64("objectSize", 80*1024*1024, "size of individual requests in bytes (must be smaller than main memory)")
numClients := flag.Int("numClients", 40, "number of concurrent clients")
numSamples := flag.Int("numSamples", 200, "total number of requests to send")
skipCleanup := flag.Bool("skipCleanup", false, "skip deleting objects created by this tool at the end of the run")

flag.Parse()

if *numClients > *numSamples || *numSamples < 1 {
Expand Down Expand Up @@ -75,11 +77,12 @@ func main() {
fmt.Println()

// Start the load clients and run a write test followed by a read test
params.StartClients(&aws.Config{
cfg := &aws.Config{
Credentials: credentials.NewStaticCredentials(*accessKey, *accessSecret, ""),
Region: aws.String("igneous-test"),
S3ForcePathStyle: aws.Bool(true),
})
}
params.StartClients(cfg)

fmt.Printf("Running %s test...\n", opWrite)
writeResult := params.Run(opWrite)
Expand All @@ -95,6 +98,25 @@ func main() {
fmt.Println(writeResult)
fmt.Println()
fmt.Println(readResult)

// Do cleanup if required
if !*skipCleanup {
fmt.Println()
fmt.Printf("Cleaning up %d objects...", *numSamples)
numDeleted := 0
svc := s3.New(session.New(), cfg)
for i := 0; i < *numSamples; i++ {
params := &s3.DeleteObjectInput{
Bucket: aws.String(*bucketName),
Key: aws.String(fmt.Sprintf("%s%d", *objectNamePrefix, i)),
}
_, err := svc.DeleteObject(params)
if err == nil {
numDeleted++
}
}
fmt.Printf("Done (%d/%d)\n", numDeleted, *numSamples)
}
}

func (params *Params) Run(op string) Result {
Expand Down

0 comments on commit aafa129

Please sign in to comment.