Skip to content
This repository has been archived by the owner on Aug 17, 2020. It is now read-only.

Commit

Permalink
Merge pull request #112 from cwaltken-edrans/102-break-5min-lambda-ba…
Browse files Browse the repository at this point in the history
…rrier

break 5min lambda barrier & other major internal refactoring
  • Loading branch information
zeph authored Apr 24, 2017
2 parents c75a2e0 + 024801e commit 2099508
Show file tree
Hide file tree
Showing 9 changed files with 1,131 additions and 303 deletions.
12 changes: 6 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
FROM golang:1.5
FROM golang:1.8

RUN apt-get update
RUN apt-get install -y zip
ADD . /go/src/github.com/gophergala2016/goad
WORKDIR /go/src/github.com/gophergala2016/goad
RUN go get -u github.com/jteeuwen/go-bindata/...
RUN make bindata
RUN go build -o /go/bin/goad-api webapi/webapi.go
ADD . /go/src/github.com/goadapp/goad
WORKDIR /go/src/github.com/goadapp/goad
RUN go get -u github.com/jteeuwen/go-bindata/...
RUN make linux
# RUN go build -o /go/bin/goad-api webapi/webapi.go

CMD ["/go/bin/goad-api", "-addr", ":8080"]
EXPOSE 8080
4 changes: 2 additions & 2 deletions Godeps/Godeps.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
all: osx linux windows

test:
go test ./...

lambda:
GOOS=linux GOARCH=amd64 go build -o data/lambda/goad-lambda ./lambda
zip -jr data/lambda data/lambda
Expand All @@ -21,6 +24,7 @@ windows: bindata

clean:
rm -rf data/lambda/goad-lambda
rm -rf data/lambda.zip
rm -rf build

all-zip: all
Expand Down
20 changes: 10 additions & 10 deletions goad.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ var supportedRegions = []string{
type Test struct {
Config *TestConfig
infra *infrastructure.Infrastructure
lambdas int
}

// NewTest returns a configured Test
Expand Down Expand Up @@ -85,12 +86,13 @@ func (t *Test) Start() <-chan queue.RegionsAggData {
}

t.infra = infra
t.lambdas = numberOfLambdas(t.Config.Concurrency, len(t.Config.Regions))
t.invokeLambdas(awsConfig, infra.QueueURL())

results := make(chan queue.RegionsAggData)

go func() {
for result := range queue.Aggregate(awsConfig, infra.QueueURL(), t.Config.TotalRequests) {
for result := range queue.Aggregate(awsConfig, infra.QueueURL(), t.Config.TotalRequests, t.lambdas) {
results <- result
}
close(results)
Expand All @@ -100,15 +102,13 @@ func (t *Test) Start() <-chan queue.RegionsAggData {
}

func (t *Test) invokeLambdas(awsConfig *aws.Config, sqsURL string) {
lambdas := numberOfLambdas(t.Config.Concurrency, len(t.Config.Regions))

for i := 0; i < lambdas; i++ {
for i := 0; i < t.lambdas; i++ {
region := t.Config.Regions[i%len(t.Config.Regions)]
requests, requestsRemainder := divide(t.Config.TotalRequests, lambdas)
concurrency, _ := divide(t.Config.Concurrency, lambdas)
requests, requestsRemainder := divide(t.Config.TotalRequests, t.lambdas)
concurrency, _ := divide(t.Config.Concurrency, t.lambdas)
execTimeout := t.Config.ExecTimeout

if requestsRemainder > 0 && i == lambdas-1 {
if requestsRemainder > 0 && i == t.lambdas-1 {
requests += requestsRemainder
}

Expand All @@ -129,7 +129,7 @@ func (t *Test) invokeLambdas(awsConfig *aws.Config, sqsURL string) {
"-t",
fmt.Sprintf("%s", c.RequestTimeout.String()),
"-f",
fmt.Sprintf("%s", reportingFrequency(lambdas).String()),
fmt.Sprintf("%s", reportingFrequency(t.lambdas).String()),
"-r",
fmt.Sprintf("%s", region),
"-m",
Expand Down Expand Up @@ -196,8 +196,8 @@ func (c TestConfig) check() error {
if (c.TotalRequests < 1 && c.ExecTimeout <= 0) || c.TotalRequests > 2000000 {
return errors.New("Invalid total requests (use 1 - 2000000)")
}
if c.ExecTimeout > 300 {
return errors.New("Invalid maximum execution time in seconds (use 0 - 300)")
if c.ExecTimeout > 3600 {
return errors.New("Invalid maximum execution time in seconds (use 0 - 3600)")
}
if c.RequestTimeout.Nanoseconds() < nano || c.RequestTimeout.Nanoseconds() > nano*100 {
return errors.New("Invalid timeout (1s - 100s)")
Expand Down
23 changes: 16 additions & 7 deletions infrastructure/infrastructure.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,13 +202,22 @@ func (infra *Infrastructure) createIAMLambdaRolePolicy(roleName string) error {
PolicyDocument: aws.String(`{
"Version": "2012-10-17",
"Statement": [
{
"Action": [
"sqs:SendMessage"
],
"Effect": "Allow",
"Resource": "arn:aws:sqs:*:*:goad-*"
},
{
"Action": [
"sqs:SendMessage"
],
"Effect": "Allow",
"Resource": "arn:aws:sqs:*:*:goad-*"
},
{
"Effect": "Allow",
"Action": [
"lambda:Invoke*"
],
"Resource": [
"arn:aws:lambda:*:*:goad:*"
]
},
{
"Action": [
"logs:CreateLogGroup",
Expand Down
Loading

0 comments on commit 2099508

Please sign in to comment.