Skip to content

Commit

Permalink
add concurrency to http_service
Browse files Browse the repository at this point in the history
  • Loading branch information
mrkurt committed Jul 19, 2022
1 parent cd0b194 commit 4f5d126
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 15 deletions.
13 changes: 10 additions & 3 deletions api/machine_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,16 @@ type MachinePort struct {
}

type MachineService struct {
Protocol string `json:"protocol" toml:"protocol"`
InternalPort int `json:"internal_port" toml:"internal_port"`
Ports []MachinePort `json:"ports" toml:"ports"`
Protocol string `json:"protocol" toml:"protocol"`
InternalPort int `json:"internal_port" toml:"internal_port"`
Ports []MachinePort `json:"ports" toml:"ports"`
Concurrency MachineServiceConcurrency `json:"concurrency" toml:"concurrency"`
}

type MachineServiceConcurrency struct {
Type string `json:"type" toml:"type,omitempty"`
HardLimit int `json:"hard_limit" toml:"hard_limit,omitempty"`
SoftLimit int `json:"soft_limit" toml:"soft_limit,omitempty"`
}

type MachineConfig struct {
Expand Down
6 changes: 4 additions & 2 deletions internal/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,11 @@ type Config struct {
}

type HttpService struct {
InternalPort int `json:"internal_port" toml:"internal_port" validate:"required,numeric"`
ForceHttps bool `toml:"force_https"`
InternalPort int `json:"internal_port" toml:"internal_port" validate:"required,numeric"`
ForceHttps bool `toml:"force_https"`
Concurrency api.MachineServiceConcurrency `toml:"concurrency"`
}

type VM struct {
CpuCount int `toml:"cpu_count,omitempty"`
Memory int `toml:"memory,omitempty"`
Expand Down
24 changes: 14 additions & 10 deletions internal/command/deploy/machines.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package deploy
import (
"context"
"fmt"
"math"

"github.com/superfly/flyctl/api"
"github.com/superfly/flyctl/client"
Expand Down Expand Up @@ -37,31 +38,34 @@ func createMachinesRelease(ctx context.Context, config *app.Config, img *imgsrc.

// Convert the new, slimmer http service config to standard services
if config.HttpService != nil {

concurrency := config.HttpService.Concurrency
if concurrency.Type == "" {
concurrency.Type = "requests"
}
if concurrency.HardLimit == 0 {
concurrency.HardLimit = 25
}
if concurrency.SoftLimit == 0 {
concurrency.SoftLimit = int(math.Ceil(float64(concurrency.HardLimit) * 0.8))
}
httpService := api.MachineService{
Protocol: "tcp",
InternalPort: config.HttpService.InternalPort,
Concurrency: concurrency,
Ports: []api.MachinePort{
{
Port: 80,
Handlers: []string{"http"},
ForceHttps: true,
ForceHttps: config.HttpService.ForceHttps,
},
},
}

httpsService := api.MachineService{
Protocol: "tcp",
InternalPort: config.HttpService.InternalPort,
Ports: []api.MachinePort{
{
Port: 443,
Handlers: []string{"http", "tls"},
},
},
}

machineConfig.Services = append(machineConfig.Services, httpService, httpsService)
machineConfig.Services = append(machineConfig.Services, httpService)
}

// Copy standard services to the machine vonfig
Expand Down

0 comments on commit 4f5d126

Please sign in to comment.