-
Notifications
You must be signed in to change notification settings - Fork 28
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
Add support for parallel input event handler #295
Comments
I think async is better for this case than threads, but it may require API changes. |
@maratori: do you have an idea how an API could look like? |
Nope :) |
:D I am not sure if i want to introduce an async API. To make the whole API sync was an design criteria actually, because in my opinion giving end-users an async API can be error prone: async def handle_input_event(self, request):
long_running_database_operation() For someone who try to solve a real world problem, like an accounting APP, this code might look just fine and it will work on their laptop, but the io loop is blocked until the database operation is done. We could add an async API for users who know what they are doing, but we need a solution for the sync world as well, and i am not sure if i want to support both. |
Totally agree |
I like keeping API sync idea, actually. async can add a lot of mental overhead. |
I like keeping API sync idea, actually. async can add a lot of mental overhead. Maybe just use thread pools if scalability is an issue? I am not convinced in default low limit... I was originally suggesting making threaded callbacks explicit, but that would complicate API, likely unnecessary. |
That is pretty much what JavaScript does. You can add a callback to a button and run a short running function when it is clicked. If you run an endless loop in that callback, the page hangs until you return, and the browser will issue an warning that your code takes to long to complete.
Actually there is already a limit, which currently is 1. Currently we use the websocket as a queue, and process events sequentially.
Lona already uses thread pools to run input event handler. This way we don't block the io loop and the user don't has to deal with multi-threading or async code. But we have to limit the threads a view may use at a time, so power-clicking does not slow down the experience for other users. |
Thank you for clarifying, @fscherf. In my Lona app there is no scalability concerns, as I use it as local UI, which is not the target for your proposed change |
@korantu: That's totaly fine and intended! And that's how many projects start. It would be nice if all Lona projects scale, even if they don't have to at the moment. |
I did some experiments and i realized just limiting, the jobs a view can run simultaneously, to a finite number, has multiple problems:
Priorities instead of limitsI think a better solution for this is to not limiting parallel jobs, but to prioritize them: All input events get pushed into one When an input event comes in, it gets put into the queue with its priority set to This way "power-clicking" would be accounted for, and slow only one user down, but not his neighbors, this scales up and down and parallel execution would be possible. Why timestamps? In this context they are called deadlines and ensure that jobs can be prioritized, but can't get stuck in the queue indefinitely. If we would use a base priority of |
This could lead to a situation where events from a user could be re-ordered on the server, right? |
No. priority = (now() + timedelta(seconds=user.pending_input_events)).total_seconds I changed the variable names to make my point more clear. This deadline-scheduling basically, and should ensure that all tasks that use the same |
I try to encourage Lona users to use callback based input event handler to make their apps more scaleable, but currently input event handler run serialized.
Let's say we have two buttons. The first button triggers a long running operation (getting a value from a database), the second triggers a short running operation (toggling a popup). When the first button is pressed the popup can't be opened or closed, until
get_count_from_database()
is done. For the end-user the app then feels slow and unresponsive.You can solve this issue by runnnig
get_count_from_database()
in a thread, but i think we can automate this.My idea is to allow parallel execution of input event handlers in the server, but very limited. I think we can't just use a thread for every click a user makes (that would be ascalability nightmare), but we can make the count of parallel input event handler configurable in the settings.
I would propose
2
as default. With two parallel handlers you can run one long running call and service input like button presses, without handling threading by yourself.@SmithChart, @maratori, @grigolet, @laundmo, @korantu
The text was updated successfully, but these errors were encountered: