Skip to content
This repository has been archived by the owner on May 7, 2023. It is now read-only.

Commit

Permalink
Set concurrency to runtime NumCpus
Browse files Browse the repository at this point in the history
  • Loading branch information
scoiatael committed Mar 8, 2017
1 parent 8f811b7 commit 4fc0fde
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 1 deletion.
3 changes: 3 additions & 0 deletions actions/context.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package actions

import (
"context"
"encoding/json"

"github.com/scoiatael/archai/http"
Expand All @@ -12,6 +13,7 @@ type HttpHandler interface {
Get(string, func(http.GetContext))
Post(string, func(http.PostContext))
Run(string) error
Stop(context.Context)
}

type Context interface {
Expand All @@ -21,6 +23,7 @@ type Context interface {
HandleErr(error)
HttpHandler() HttpHandler
Telemetry() telemetry.Datadog
Concurrency() int
}

type Action interface {
Expand Down
2 changes: 1 addition & 1 deletion actions/http_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (wj *WriteJob) Run(c Context) {
func (hs HttpServer) Run(c Context) error {
handler := c.HttpHandler()
jobs := make(chan WriteJob, 50)
for w := 0; w < 3; w++ {
for w := 0; w < c.Concurrency(); w++ {
go writer(jobs, c)
}
handler.Get("/stream/:id", func(ctx http.GetContext) {
Expand Down
5 changes: 5 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"fmt"
"log"
"runtime"

"github.com/scoiatael/archai/actions"
"github.com/scoiatael/archai/http"
Expand Down Expand Up @@ -98,3 +99,7 @@ func (c Config) Run() error {
func (c Config) PrettyPrint() {
util.PrettyPrint(c)
}

func (c Config) Concurrency() int {
return runtime.NumCPU()
}
6 changes: 6 additions & 0 deletions http/iris.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package http

import (
"context"

"gopkg.in/kataras/iris.v6"

"github.com/scoiatael/archai/simplejson"
Expand Down Expand Up @@ -81,3 +83,7 @@ func (h *IrisHandler) Run(addr string) error {

return nil
}

func (h *IrisHandler) Stop(ctx context.Context) {
h.framework.Shutdown(ctx)
}

0 comments on commit 4fc0fde

Please sign in to comment.