Skip to content

Commit

Permalink
adding partition to config for year,month,day,hour partitions
Browse files Browse the repository at this point in the history
  • Loading branch information
aviaIguazio committed Jul 22, 2019
1 parent b51fbb3 commit d0785f2
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 84 deletions.
5 changes: 2 additions & 3 deletions httpblaster/data_generator/fakerGenerator.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ type Fake struct {
}

func randomBase64String(l int) string {

buff := make([]byte, int(math.Round(float64(l)/float64(1.33333333333))))
_, err := rand.Read(buff)
if err != nil {
Expand All @@ -47,8 +46,8 @@ func (self *Fake) Init() {
gofakeit.Seed(time.Now().UnixNano())
}

func (self *Fake) GenerateRandomData() {
t := time.Now().AddDate(0, 0, 0)
func (self *Fake) GenerateRandomData(t time.Time) {
//t := time.Now().UTC().AddDate(0, 0, 0)
self.Key = randomBase64String(16)

self.Name = gofakeit.Name() // Markus Moen
Expand Down
67 changes: 35 additions & 32 deletions httpblaster/request_generators/faker2kv.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/v3io/http_blaster/httpblaster/utils"
"runtime"
"sync"
"time"
)

var faker = data_generator.Fake{}
Expand All @@ -19,40 +20,12 @@ func (receiver *Faker2KV) UseCommon(c RequestCommon) {

}

func (receiver *Faker2KV) generateRequest(chRecords chan []string, chReq chan *Request, host string,
wg *sync.WaitGroup, cpuNumber int, wl config.Workload) {
defer wg.Done()
faker.Init()
for i := 0; i < wl.Count; i++ {

var contentType = "text/html"
faker.GenerateRandomData()
jsonPayload := faker.ConvertToIgzEmdItemJson()
req := AcquireRequest()
receiver.PrepareRequest(contentType, receiver.workload.Header, "PUT",
receiver.base_uri, jsonPayload, host, req.Request)
chReq <- req
}
}

func (receiver *Faker2KV) generate(ch_req chan *Request, payload string, host string, wl config.Workload) {
defer close(ch_req)
var chRecords = make(chan []string, 1000)
wg := sync.WaitGroup{}
wg.Add(runtime.NumCPU())
for c := 0; c < runtime.NumCPU(); c++ {
go receiver.generateRequest(chRecords, ch_req, host, &wg, c, wl)
}

close(chRecords)
wg.Wait()
}

func (receiver *Faker2KV) GenerateRequests(global config.Global, wl config.Workload, tlsMode bool, host string, retCh chan *Response, workerQd int) chan *Request {
// generating partition
t := time.Now().UTC().AddDate(0, 0, 0)
part := ""
if wl.Partition != "" {
part = receiver.GenerateCurrentPartition(wl.Partition)
part = receiver.GenerateCurrentPartition(wl.Partition, t)
}

receiver.workload = wl
Expand All @@ -71,6 +44,36 @@ func (receiver *Faker2KV) GenerateRequests(global config.Global, wl config.Workl
return ch_req
}

func (receiver *Faker2KV) GenerateCurrentPartition(partitionBy string) string {
return utils.GeneratePartitionedRequest(partitionBy)
func (receiver *Faker2KV) generate(ch_req chan *Request, payload string, host string, wl config.Workload) {
defer close(ch_req)
var chRecords = make(chan []string, 1000)
wg := sync.WaitGroup{}
wg.Add(runtime.NumCPU())
for c := 0; c < runtime.NumCPU(); c++ {
go receiver.generateRequest(chRecords, ch_req, host, &wg, c, wl)
}

close(chRecords)
wg.Wait()
}

func (receiver *Faker2KV) generateRequest(chRecords chan []string, chReq chan *Request, host string,
wg *sync.WaitGroup, cpuNumber int, wl config.Workload) {
defer wg.Done()
faker.Init()
for i := 0; i < wl.Count; i++ {

//receiver.SetBaseUri(tlsMode, host, receiver.workload.Container, receiver.workload.Target+part)
var contentType = "text/html"
faker.GenerateRandomData(time.Now().UTC())
jsonPayload := faker.ConvertToIgzEmdItemJson()
req := AcquireRequest()
receiver.PrepareRequest(contentType, receiver.workload.Header, "PUT",
receiver.base_uri, jsonPayload, host, req.Request)
chReq <- req
}
}

func (receiver *Faker2KV) GenerateCurrentPartition(partitionBy string, t time.Time) string {
return utils.GeneratePartitionedRequest(partitionBy, t)
}
51 changes: 2 additions & 49 deletions httpblaster/utils/partitioned_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,56 +5,9 @@ import (
"time"
)

func PrintTime() {
currentTime := time.Now()
fmt.Println("\n######################################\n")
fmt.Println(currentTime.Format("2006-01-02 15:04:05"))

fmt.Println("\n######################################\n")
timeStampString := currentTime.Format("2006-01-02 15:04:05")
layOut := "2006-01-02 15:04:05"
timeStamp, err := time.Parse(layOut, timeStampString)
if err != nil {
fmt.Println(err)
}
hr, min, sec := timeStamp.Clock()

fmt.Println("Year :", currentTime.Year())
fmt.Println("Month :", currentTime.Month())
fmt.Println("Day :", currentTime.Day())
fmt.Println("Hour :", hr)
fmt.Println("Min :", min)
fmt.Println("Sec :", sec)

fmt.Println("\n######################################\n")
year, month, day := time.Now().Date()
fmt.Println("Year :", year)
fmt.Println("Month :", month)
fmt.Println("Day :", day)

fmt.Println("\n######################################\n")
t := time.Now()

y := t.Year()
mon := t.Month()
d := t.Day()
h := t.Hour()
m := t.Minute()
s := t.Second()
n := t.Nanosecond()

fmt.Println("Year :", y)
fmt.Println("Month :", mon)
fmt.Println("Day :", d)
fmt.Println("Hour :", h)
fmt.Println("Minute :", m)
fmt.Println("Second :", s)
fmt.Println("Nanosec:", n)
}

func GeneratePartitionedRequest(partition_by string) string {
func GeneratePartitionedRequest(partition_by string, t time.Time) string {
//t := time.Now()
t := time.Now().AddDate(0, 0, 0)
//t := time.Now().UTC().AddDate(0, 0, 0)
if partition_by == "year" {
return fmt.Sprintf("/year=%d/",
t.Year())
Expand Down

0 comments on commit d0785f2

Please sign in to comment.