← 返回题库
中级

实现最少连接负载均衡

未完成
中级参考 代码结构已给出,请填写 ____ 处
def solve():
    from pyodide.http import open_url
    from io import StringIO
    import pandas as pd
    reg_csv = open_url(____).read()
    reg = pd.read_csv(StringIO(____))
    healthy = reg[(____)&(____)].copy()
    def least_connections(____):
        min_row = instances_df.loc[instances_df['____'].idxmin()]
        return min_row['____'], int(____)
    print(____)
    current = healthy.copy()
    for i in range(____):
        inst, conns = least_connections(____)
        print(____)
        idx = current[current['____']==inst].index[____]
        current.loc[idx,'____'] += ____

示例

输入
solve()
期望输出
最少连接负载均衡:
  请求1: 选择 di-3(当前2连接)
  请求2: 选择 di-3(当前3连接)
  请求3: 选择 di-3(当前4连接)
  请求4: 选择 di-3(当前5连接)
  请求5: 选择 di-3(当前6连接)
Python 代码 🔒 登录后使用
🔒

登录后即可练习

注册免费账号,在浏览器中直接运行 Python 代码