Skip to content

关于使用python运行和secretnote分段运行有明显时间差别的问题 #131

@winnylyc

Description

@winnylyc

您好,打扰您了。
我在benchmark labeled PSI时发现直接使用python运行和使用secretnote分段运行有明显时间差别。我想请教一下是什么因素导致了这样的差别。
我目前在尝试的是以下的代码。
server方:

import secretflow as sf
import spu
import time

cluster_config = {
    'parties' : {
        'alice': {
            'address': '127.0.0.1:59179',
            'listen_addr': '0.0.0.0:59179'
        },
        'bob': {
            'address': '127.0.0.1:53341',
            'listen_addr': '0.0.0.0:53341'
        }
    },
    'self_party': 'alice'
}
sf.shutdown
sf.init(address='local', cluster_config=cluster_config)
cluster_def = {
    "nodes": [
        {
            "party": "alice",
            "address": "127.0.0.1:45413"
        },
        {
            "party": "bob",
            "address": "127.0.0.1:47480"
        },
    ],
    "runtime_config": {
        "protocol": spu.spu_pb2.SEMI2K,
        "field": spu.spu_pb2.FM128
    },
}

spu = sf.SPU(
    cluster_def,
    link_desc={
        "connect_retry_times": 60,
        "connect_retry_interval_ms": 1000,
    }
)

start_time = time.time()
spu.pir_query(
    server="alice",
    client="bob",
    server_setup_path="./alice_exactpsi_setup_1e6_npq20",
    client_key_columns=["name"],
    client_input_path="./bob_exactpsi_1e6_to_1e2.csv",
    client_output_path="./bob_exactpsi_1e6_to_1e2_output_test.csv"
)
end_time = time.time()
elapsed_time = end_time - start_time
print("The function took", elapsed_time, "seconds to run.")

对于时间的输出是
The function took 12.396417617797852 seconds to run.
client方:

import secretflow as sf
import spu
import time

cluster_config = {
    'parties' : {
        'alice': {
            'address': '127.0.0.1:59179',
            'listen_addr': '0.0.0.0:59179'
        },
        'bob': {
            'address': '127.0.0.1:53341',
            'listen_addr': '0.0.0.0:53341'
        }
    },
    'self_party': 'bob'
}
sf.shutdown
sf.init(address='local', cluster_config=cluster_config)
cluster_def = {
    "nodes": [
        {
            "party": "alice",
            "address": "127.0.0.1:45413"
        },
        {
            "party": "bob",
            "address": "127.0.0.1:47480"
        },
    ],
    "runtime_config": {
        "protocol": spu.spu_pb2.SEMI2K,
        "field": spu.spu_pb2.FM128
    },
}

spu = sf.SPU(
    cluster_def,
    link_desc={
        "connect_retry_times": 60,
        "connect_retry_interval_ms": 1000,
    }
)

start_time = time.time()
spu.pir_query(
    server="alice",
    client="bob",
    server_setup_path="./alice_exactpsi_setup_1e6_npq20",
    client_key_columns=["name"],
    client_input_path="./bob_exactpsi_1e6_to_1e2.csv",
    client_output_path="./bob_exactpsi_1e6_to_1e2_output_test.csv"
)
end_time = time.time()
elapsed_time = end_time - start_time
print("The function took", elapsed_time, "seconds to run.")

对于时间的输出是
The function took 14.504458665847778 seconds to run.

在secrenote上的运行参考https://www.bilibili.com/video/BV13M4m1R7gp 上面的教程,将运行分为三个部分,连接sf, 连接spu, 运行spu.pir_query。基本上运行spu.pir_query这一部分在10s左右。另外我也尝试了,将spu.pir_query这个部分放在两个代码块中分两个party运行,这种尝试下依然是10s,而且两边的时间差不多长(并没有12s和14s这样大的差别)。
还有一种尝试,就是在secretnote将整个代码放入代码块运行,这样的表现和直接运行.py文件一样,所以造成差别的因素因该主要是分段式运行。
对于这个差异我有两个问题:

  1. 为什么分段式运行代码的花费时间更小?有没有方法使单单调用pir_query的时间开销更小?
  2. 似乎receiver(clinet)总是比sender(server)的耗时更久,这里面是什么原因?

非常期待您的回答!感谢您的帮助!

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions