-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix CPU usage and other concurrency problems.
This is a hard commit to break up into smaller chunks. It basically rewrites the concurrency portion of Server.hs, which ends up touching a few other places. Here's the main parts: (1) Get rid of the separate cfgWorkQ channel that holds composes waiting to be started. Instead, I've introduced a new ComposeMsgAsk type that the API server can use to request a compose be started, just like it uses other message types to ask other things. (2) This means the slot in AskTuple used for the compose server to write an answer back now becomes a Maybe. If a compose is requested, there is no answer. The client requests the status later on. (3) Use the concurrency functions in the async module. These are a little nicer to use and there's all sorts of more advanced functions we may be able to make use of later, if needed. (4) composeServer does two tasks - listen and respond to messages, and start composes. I was previously doing this pretty stupidly. In a single loop, I would deal with any messages and then look for any composes to start. This is now done in two separate, eternally running threads. (5) There is actually still a worklist that does the same function as cfgWorkQ used to do, but it is no longer exposed. It's only used by composeServer and its two helper threads. (6) Stop using an IORef to manage the worklist. Polling on this value in a loop was keeping the CPU pegged at 100% at all times. Instead, use a list in a TVar and use some custom code to treat it like a queue. It shouldn't ever get large, so this should be fine. Note the very important comment above the retry call.
- Loading branch information
Showing
5 changed files
with
78 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters