Skip to content

Conversation

yuji38kwmt
Copy link
Collaborator

@yuji38kwmt yuji38kwmt commented May 13, 2022

概要

塗りつぶし画像などを取得する際に利用できる、requests.getに相当する関数を用意しました。
reqeuests.getを使うときと比較して、以下のメリットがあります。

  • requests.Session 情報を使ってTCPコネクションを再利用しているため、requests.get を使ってダウンロードするよりも、パフォーマンスが向上する可能性があります。
  • 必要に応じてリトライします

パフォーマンス測定

execute_http_getの処理時間は、requests.getと比較して、実際の処理時間は0.5倍以下になった。

In [3]: import annofabapi; s=annofabapi.build()

In [4]: annotation_list = s.wrapper.get_all_annotation_list(project_id)

# アノテーションの個数
In [6]: len(annotation_list)
Out[6]: 1155

# 外部にリソースを持つアノテーションの個数(アノテーションの個数と一致)
In [9]: len([e for e in annotation_list if e["detail"]["data_holding_type"]=="outer"])
Out[9]: 1155

In [11]: %time for e in annotation_list: s.wrapper.execute_http_get(e["detail"]["url"])
CPU times: user 8.46 s, sys: 384 ms, total: 8.84 s
Wall time: 1min 53s

In [12]: import requests

IIn [13]: %time for e in annotation_list:requests.get(e["detail"]["url"])
CPU times: user 23.1 s, sys: 1.09 s, total: 24.2 s
Wall time: 3min 55s

@yuji38kwmt yuji38kwmt changed the title Public Wrapperクラスにdownload, execute_http_get関数を用意 May 13, 2022
@yuji38kwmt yuji38kwmt merged commit 840b0d5 into main May 13, 2022
@yuji38kwmt yuji38kwmt deleted the public branch May 13, 2022 02:10
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.

1 participant