0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Langfuse Cloud環境でレイテンシーが大きくなる事象についてのメモ

0
Last updated at Posted at 2025-12-31

2025/12時点でLangfuseのCloud環境利用時にレイテンシーが大きくなる事象の報告をいくつか目にしたので、簡単にまとめてみました。それぞれの事象に直接的な関連性があるかは分かりませんが、時折発生しているようです :thinking:

たとえばどれ?

トレース取得時に発生

トレース取得に関するAPIで、レスポンスが遅くなるという報告です。

この事象については、私の環境でも発生しており、やや困っています。下記のような非常にシンプルなコードでも、2025/12時点ではタイムアウトが発生します。

import time
from langfuse import get_client

langfuse = get_client()
start = time.perf_counter()
trace = langfuse.api.trace.list(limit=1)
print(f"Trace Name: {trace.data[0].name}, ID: {trace.data[0].id}")
end = time.perf_counter()
print(f"Time taken to fetch trace: {end - start:.4f} seconds")

$ time python trace_get.py 
Traceback (most recent call last):
  File "/venv/lib/python3.12/site-packages/httpx/_transports/default.py", line 101, in map_httpcore_exceptions
    yield
  File "/venv/lib/python3.12/site-packages/httpx/_transports/default.py", line 250, in handle_request
    resp = self._pool.handle_request(req)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/venv/lib/python3.12/site-packages/httpcore/_sync/connection_pool.py", line 256, in handle_request
    raise exc from None
  File "/venv/lib/python3.12/site-packages/httpcore/_sync/connection_pool.py", line 236, in handle_request
    response = connection.handle_request(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/venv/lib/python3.12/site-packages/httpcore/_sync/connection.py", line 103, in handle_request
    return self._connection.handle_request(request)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/venv/lib/python3.12/site-packages/httpcore/_sync/http11.py", line 136, in handle_request
    raise exc
  File "/venv/lib/python3.12/site-packages/httpcore/_sync/http11.py", line 106, in handle_request
    ) = self._receive_response_headers(**kwargs)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/venv/lib/python3.12/site-packages/httpcore/_sync/http11.py", line 177, in _receive_response_headers
    event = self._receive_event(timeout=timeout)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/venv/lib/python3.12/site-packages/httpcore/_sync/http11.py", line 217, in _receive_event
    data = self._network_stream.read(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/venv/lib/python3.12/site-packages/httpcore/_backends/sync.py", line 126, in read
    with map_exceptions(exc_map):
  File "/usr/lib/python3.12/contextlib.py", line 158, in __exit__
    self.gen.throw(value)
  File "/venv/lib/python3.12/site-packages/httpcore/_exceptions.py", line 14, in map_exceptions
    raise to_exc(exc) from exc
httpcore.ReadTimeout: The read operation timed out

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/1214/score.py", line 9, in <module>
    trace = langfuse.api.trace.list(limit=1)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/venv/lib/python3.12/site-packages/langfuse/api/resources/trace/client.py", line 348, in list
    _response = self._client_wrapper.httpx_client.request(
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/venv/lib/python3.12/site-packages/langfuse/api/core/http_client.py", line 207, in request
    response = self.httpx_client.request(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/venv/lib/python3.12/site-packages/httpx/_client.py", line 825, in request
    return self.send(request, auth=auth, follow_redirects=follow_redirects)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/venv/lib/python3.12/site-packages/httpx/_client.py", line 914, in send
    response = self._send_handling_auth(
               ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/venv/lib/python3.12/site-packages/httpx/_client.py", line 942, in _send_handling_auth
    response = self._send_handling_redirects(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/venv/lib/python3.12/site-packages/httpx/_client.py", line 979, in _send_handling_redirects
    response = self._send_single_request(request)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/venv/lib/python3.12/site-packages/httpx/_client.py", line 1014, in _send_single_request
    response = transport.handle_request(request)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/venv/lib/python3.12/site-packages/httpx/_transports/default.py", line 249, in handle_request
    with map_httpcore_exceptions():
  File "/usr/lib/python3.12/contextlib.py", line 158, in __exit__
    self.gen.throw(value)
  File "/venv/lib/python3.12/site-packages/httpx/_transports/default.py", line 118, in map_httpcore_exceptions
    raise mapped_exc(message) from exc
httpx.ReadTimeout: The read operation timed out

real    0m7.400s
user    0m0.820s
sys     0m0.053s

Observation取得時に発生

Observation取得APIのレスポンスが重いという報告です。

Issue内のコメントを見る限り、対象となるAPIは明確ではありませんが、古いAPIについてはリソース消費が大きいため、意図的に制限が加えられているようです。

また、LangfuseのSDKによっては、この新APIへの対応がまだされていない場合があるとも記載されており、利用時には注意が必要そうです。

This is coincidence with the release from the new API and was a measure to protect CH resources from the old, very expensive, APIs. Hence we have worse latencies on the old APIs.

Azure環境からLangfuse Cloud環境への通信で発生

Azure App Service環境からLangfuse Cloud環境へ通信する際に、断続的に発生するという報告です。
Issue自体は10月に起票されていますが、12/23時点でも解消していないようです。

どうしたら良いの?

クライアント側でできる対応としては、現状ではタイムアウトを延ばすくらいしかなさそうです。Python SDKの場合、環境変数LANGFUSE_TIMEOUTを設定することで、リクエストのタイムアウト時間を延長できます。

タイムアウトを伸ばして確認すると、先ほどのコードでも、リクエストに20秒弱かかっているようでした。

time python trace_get.py 
Trace Name: main, ID: 37fde35dd72a20b215a1a2311962c259
Time taken to fetch trace: 17.0700 seconds

real    0m20.419s
user    0m0.851s
sys     0m0.038s

listでの取得ではなく、idを指定する方法だとさらに重いですね。。。

import time
from langfuse import get_client

start = time.perf_counter()
trace = langfuse.api.trace.get(trace_id="37fde35dd72a20b215a1a2311962c259")
print(f"Trace Name: {trace.name}, ID: {trace.id}")
end = time.perf_counter()
print(f"Time taken to fetch trace: {end - start:.4f} seconds")
# Time taken to fetch trace: 37.6425 seconds

1/14追記

最近はエラーが起きると下記のメッセージを返すようになりましたね。
安定化することを祈ります 🙏

'We got notified about this issue and are looking into it. We are continuously improving our API performance.\nSee https://langfuse.com/docs/api-and-data-platform/features/public-api for more details.', 'error': 'Request is taking too long to process.

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?