iRule to forward requests to pool with most active members

Does someone know if it is possible to create an iRule that forwards the requests to that pool that has the most available members? How could the rule look like?

Depending on how you define “the most available members”, here’s one you can try:

when CLIENT_ACCEPTED {
    if { [active_members pool_1] >= [active_members pool_2] } {
        pool pool_1
    } else {
        pool pool_2
    }
}

.

Try this code

when CLIENT_ACCEPTED {
    pool [expr { [active_members pool_1] >= [active_members pool_2] ? pool_1 : pool_2}]
}