Repository navigation
Replace file locks with invocations to a centralised queue server over HTTP - #37
debater-coder wants to merge 3 commits into
Conversation
Signed-off-by: debater-coder <hamzah@syedahmed.net>
|
Please clean up this PR so it is reviewable and a logical self-contained change, and explain what the change is, why it is being made, and why it is correct. This is critical infrastructure for the seL4 tests. Opening a PR with a random checkbox list and no explanation is not Ok. For instance, there seems to be nix stuff in this PR. What for? If this needs a specific environment for development or even use and doesn't work properly in a generic context, then call this out and argue why that is Ok. |
|
Sorry, I should have marked this as a draft. I will add a lot more clarification. As for the nix stuff: this new implementation requires a client binary. I have already packaged this with Nix but there will also be a pre-built binary built in CI as well as of course the option to build from source. This is what I was referring to in updating the documentation. |
Signed-off-by: debater-coder <hamzah@syedahmed.net>
Signed-off-by: debater-coder <hamzah@syedahmed.net>
|
Hi, I will be getting review from my supervisors in au-ts#1 first. We will be testing with a limited subset of |
This PR replaces the use of file locks on tftp.keg.cse.unsw.edu.au with invocations to the lock server API at https://trustworthy.systems/mq/. The source for the server and additional documentation is provided here.
The linked repository contains a HTTP server and a client CLI for interfacing with that server. From my README:
Why make this change?
In the current system, machine queue locks are acquired by running
lockfilecommand over SSH, and released by deleting the lock file. This has a number of disadvantages:Waiting time
Currently multiple SSH connections are established and closed in succession in the process of acquiring a lock. If the user is outside the
kegnetwork, these connections will also go through SSH bastions adding additional latency. This adds to several seconds of latency when outside thekegnetwork.In contrast, the system implemented in my PR uses HTTP proxied over
nginx, which leads to noticably faster lock acquisition. The client also reuses TCP connections (the library used by the CLI client uses HTTP persistent connections by default), so when multiple requests are needed (for example to display information about jobs in the queue before acquiring the lock) there will be no repeated opening/closing of connections.This system also uses HTTP long polling, meaning that the server holds the connection open for a given (server-configurable) period, and if it is the clients turn to acquire the lock the server will send a HTTP response early to notify the client immediately. Thus, the system is effectively event-based rather than poling-based.
Fairness
In the existing system, each client spawns a
lockfileinstance over SSH, and locks are acquired opportunistically. In contrast, this system uses a FIFO queue (with support for priority if that is needed in the future, but this is currently not used anywhere). This allows for 'fairer' waiting times, reducing tail waiting times.Ease of administration
This system stores timestamps of when a job was created, when it acquires a machine, when it releases a machine. This is rather useful, for example: the total time a user or job has used the machine could be accessed. The server process itself is stateless, all state is stored in a SQLite database. The HTTP API offers a much richer set of data to use with dashboards etc.
Additionally, this system opens the potential for centralised management of machines, as the SQLite database already stores all relevant metadata about machines. In the existing system any changes to machine configurations require git commits to this repository, and then users have to
git pull. This new system enables machines to be managed centrally from the SQLite database (using the CLI client), making it easier for admins to add, remove, or reconfigure machines on machine_queue.This change will likely be in an upcoming PR to keep this one self-contained.
Breaking changes
jqandmachine-locks-client(the latter can be downloaded pre-built, built from source, or built with Nix)mq sem ...with pass-through tomachine-locks-clientCorrectness
The change to
machine_queueitself is rather trivial, its correctness is largely contingent to the correctness of components inmachine-locks.Now that acquiring locks involves creating a job in a FIFO queue it is important that such jobs are removed from the queue if terminated while waiting for a lock, or if something fails in this time.
machine-locks-clientitself handles this cancellation, in the same way thatlockfilecurrently receives a SIGHUP if the connection is terminated while waiting on a lock. The trap for unlocking is retained, and unlocking is still idempotent as before.Unlocking and advancing the queue are done on the server within automatic SQLite transactions (every SQLite statement is also an implicit transaction which subqueries execute within), that is that they are atomic. The query is also designed such that these operations are idempotent: if executed multiple times it will not skip a job.
Finally, the server handles cases where a job times out while a client is waiting for it to be acquired. This is extremely unlikely and can only happen if a client disappears for a while and starts polling again. In this case, a job timed out response is sent and the acquisition fails. If this case was not handled, the client would simply hang.
Before merge
machine-locks-clientmachine-locksmachine-locks-clientfor easier installationmachine-locks