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

Upgrade connection to websocket and provision new connection #1594

Closed
wants to merge 5 commits into from

Conversation

ttaym
Copy link
Contributor

@ttaym ttaym commented Mar 17, 2022

Contributes to #755

Signed-off-by: Aleksey Mikhaylov aym@tempesta-tech.com

Signed-off-by: Aleksey Mikhaylov <aym@tempesta-tech.com>
@ttaym ttaym force-pushed the am-755-update-srv-shceduler branch from baa327a to eac58dd Compare March 18, 2022 13:00
Copy link
Contributor

@krizhanovsky krizhanovsky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quite a good and accurate work, especially in the subtle server connection schedulers code! Besides the minor cleanups, there is only one place with tfw_sock_srv_connect_try() instead of tfw_sock_srv_connect_try_later(), which confuses me.

fw/sock_srv.c Outdated Show resolved Hide resolved
fw/http.c Outdated Show resolved Hide resolved
fw/http.c Show resolved Hide resolved
fw/server.h Show resolved Hide resolved
fw/http_sched_hash.c Show resolved Hide resolved
fw/http.c Outdated Show resolved Hide resolved
fw/http_sched_ratio.c Outdated Show resolved Hide resolved
Signed-off-by: Aleksey Mikhaylov <aym@tempesta-tech.com>
Signed-off-by: Aleksey Mikhaylov <aym@tempesta-tech.com>
Signed-off-by: Aleksey Mikhaylov <aym@tempesta-tech.com>
Signed-off-by: Aleksey Mikhaylov <aym@tempesta-tech.com>
@ttaym ttaym requested a review from krizhanovsky March 23, 2022 08:44
Copy link
Contributor

@krizhanovsky krizhanovsky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems we have severe race, which may lead to crashes on multi-core workload with concurrent websocket creations, and need to find a simpler solution leaving #710 for later phases.

fw/sock_srv.c Show resolved Hide resolved
fw/sock_srv.c Show resolved Hide resolved
fw/t/unit/test_hpack.c Show resolved Hide resolved
fw/t/unit/test_hpack.c Show resolved Hide resolved
fw/http_sched_hash.c Show resolved Hide resolved
if (unlikely(ci++ == srv->conn_n))
goto err;
*conn++ = srv_conn;

cl_copy->conns[ci-1] = srv_conn;
}
if (unlikely(ci != srv->conn_n))
goto err;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems I was wrong with the proposal of the functions unification in both the schedulers.

Previously we called tfw_sock_srv_new_conn(), which adds a new connection to the connection list, only from process context (since we have constant number of server connections and just failover TCP connections inside them). Moreover, tfw_peer_add_conn() uses a spin lock to add a connection. I believe we have a mutex on concurrent configuraion reloads, so we rely on the fact that tfw_sched_ratio_add_srv() always works in single context.

Now we can call this function concurrently with other websocket creation and with the configuration reload, so we definitely have races in all the places in the function. We can back to the separate functions and use the spin lock in the new function, but we'll also need to use the spin lock in all other functions iterating the connections list, which introduces lock contention.

What you're doing in the patch is almost solving #710 , which is a hard task on it's own to upgrade the schedulers data structures without locks.

Initially with #755 I assumed that you just "steal" sk from TfwSrvConn and initiate the existing connection failovering mechanism.

@krizhanovsky
Copy link
Contributor

krizhanovsky commented Apr 3, 2022

The code and the only one not-addressed comment were moved to #1595 . Please don't forget to remove the branch, when it's not needed

@ttaym ttaym deleted the am-755-update-srv-shceduler branch April 8, 2022 09:08
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

Successfully merging this pull request may close these issues.

2 participants