Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

circuit can't open? #81

Closed
jiacai2050 opened this issue Sep 8, 2019 · 3 comments
Closed

circuit can't open? #81

jiacai2050 opened this issue Sep 8, 2019 · 3 comments

Comments

@jiacai2050
Copy link

func main() {
	// f := rolling.StatFactory{}
	h := circuit.Manager{
		DefaultCircuitProperties: []circuit.CommandPropertiesConstructor{
			// f.CreateConfig,
			func(circuitName string) circuit.Config {
				return circuit.Config{
					Execution: circuit.ExecutionConfig{
						MaxConcurrentRequests: 1000,
					},
					General: circuit.GeneralConfig{
						OpenToClosedFactory: hystrix.CloserFactory(hystrix.ConfigureCloser{
							//		// This should allow a new request every 10 milliseconds
							SleepWindow: time.Millisecond * 10,
						}),
						ClosedToOpenFactory: hystrix.OpenerFactory(hystrix.ConfigureOpener{
							RequestVolumeThreshold:   10,
							ErrorThresholdPercentage: 50,
						}),
					},
				}
			},
		},
	}

	c := h.MustCreateCircuit("hello-world")
	fmt.Printf("var = %+v\n", h.Var())
	loop := 100
	for i := 0; i < loop; i++ {
		time.Sleep(500 * time.Millisecond)
		errResult := c.Execute(context.Background(), func(ctx context.Context) error {

			if i > 10 {
				return nil
			}
			return fmt.Errorf("err i %d", i)
		}, nil)

		fmt.Println("Result of execution:", errResult)
	}

}

AKAIK, circuit should open after 10*50%=5 failed response within rolling window(default: 10s), but it execute successfully
revision: 7687802

Output

Result of execution: err i 0
Result of execution: err i 1
Result of execution: err i 2
Result of execution: err i 3
Result of execution: err i 4
Result of execution: err i 5
Result of execution: err i 6
Result of execution: err i 7
Result of execution: err i 8
Result of execution: err i 9
Result of execution: err i 10
Result of execution: <nil>
Result of execution: <nil>
Result of execution: <nil>
Result of execution: <nil>
Result of execution: <nil>
@yangxikun
Copy link

Because:

SleepWindow: time.Millisecond * 10, // This allow a new request every 10 milliseconds when circuit is open

And your test code is run in 1req/500ms.

@jiacai2050
Copy link
Author

Thanks @yangxikun , I modify SleepWindow to 5s, circuit indeed open, but after 10 failed reqs, not 5.

@yangxikun
Copy link

@jiacai2050 Because RequestVolumeThreshold: 10. see

func (e *Opener) ShouldOpen(now time.Time) bool {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants