3 ms·
Most of the runtime needs in this space can be managed with circuit breakers without having to provide separate processes or memory spaces, be they temporal or
by togusa 11y ago
Most of the runtime needs in this space can be managed with circuit breakers without having to provide separate processes or memory spaces, be they temporal or resource based.
For example your regex, could be given 20ms to run and use a maximum of 8Mb of heap before it is interrupted. This can happen on a single thread and drop back to the caller if an exception is thrown. I'd love to see a language feature which defines the maximum stack and heap for a particular scope i.e. in C#:
Breaker.Heap(8.MiB(), () => {
Breaker.Time(200.Milliseconds(), () => {
// risky operation
});
});
(we already do the time breaker, but not the heap)
Edit: correct calling convention.
Edit 2: add missing extension method brackets
- aartur 11y agoInteresting. Is the circuit breaker a feature of .NET running on Windows? To my knowledge, it can't be implemented on Linux + Java or Python (a thread can't be terminated from outside, and some syscalls involve a whole process).
- eonwe 11y agoI think this can be mostly implemented in Java with bytecode re-writing which will check for the conditions on time to time. Stopping the thread can still leave some of the stuff in indeterminate state if the thread has some resources it needs to release manually.
- togusa 11y agoIt's a library I wrote. The time breaker is actually quite complicated. It is a wrapper that sets up some global parameters on the thread for timeouts on async/await calls and handles the timeout conditions. It integrates with our own async wrappers for external http calls, message delivery, query execution etc. It only enforces that all aggregate async calls will complete or fail by the end of the timeout period. Realistically this is usually around the 500-800ms space as load spikes can break everything otherwise.
- Too 11y ago.net has a public thread.abort function which allows this, it will result in a interruptedexception on the aborted thread. I think there are ways to do this in java and python also although I know the official stance on thread.abort from the python maintainers is no way in hell.
- gregmac 11y agoAside, for both the circuit breaker and numeric overloads, is that a particular library you're using or just example code? By themselves, the overloads for integers like that is pretty neat, never seen that before. I can actually think of several dozen places I do things like TimeSpan.FromSeconds(x) where that could enhance readability.
- togusa 11y agoIt's a real library I wrote. I just noticed I missed the brackets. Quick example you can infer the rest from: Code: public static class IntegerExtensions { public static TimeSpan Minutes(this int val) { return TimeSpan.FromMinutes(val); } } Usage examples I can think of: var eightMinutes = 8.Minutes(); var tenMinutes = 8.Minutes() + 2.Minutes(); DoSomethingEvery(8.Minutes());
- gregmac 11y agoYeah I figured. Is it published/OSS?
- togusa 11y agoNot at the moment. I've got a ton of stuff I probably could publish however.
- jmcqk6 11y agoJust a note, because I started in the same way you have, simply writing my own extension methods in a common dll. The Humanizer library has a bunch of these features, including the 6.minutes() functionality: https://github.com/MehdiK/Humanizer https://github.com/MehdiK/Humanizer
- radicalbyte 11y agoI was thinking the same thing - Extention Methods on the types of common literals can make for some very pretty interfaces. In combination with operator overloads and implicit casts and you have some really powerful tools for building readable APIs :)
- Too 11y agoThe latest version of .net actually has a built in timeout argument to the regex match function ;)
- togusa 11y agoHadn't noticed that. Thanks for the pointer :)