anthropics / anthropics/original_performance_takehome

Hot reloading of traces run into streaming issues on some browsers

Đang mở
#18 3 bình luận 0 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
Python
Star
4.2k
Fork
950
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

### Issue Identified
When utilising the recommended debug loop of importing traces onto https://ui.perfetto.dev/ I noticed that doing so via the webUI provided by `watch_trace.html` by running `python watch_trace.py` actually throws `BrokenPipeError: [Errno 32] Broken pipe` when `/trace.json` is fetched via `await fetch(traceUrl);`.

### Steps to reproduce
Issue reproduced on Chrome Version 143.0.7499.193

1. Execute `python perf_takehome.py Tests.test_kernel_trace` to generate a local `trace.json`
2. Run `python watch_trace.py` and wait for a tab of `http://localhost:8000/` to open
3. Select `/trace.json` and press "Open Perfetto"
4. Perfetto tab will not open, and `BrokenPipeError: [Errno 32] Broken pipe` error should appear in your python terminal

### Solution proposal
Investigating further, when calling `/trace.json` directly in the browser actually works fine, when checking the Javascript code responsible for this we see that blob is populated via
```
const resp = await fetch(traceUrl);
const blob = await resp.blob();
```
This raises issues in some browsers as our absence of a Content-Length header (which is fine for streaming) is actually causing the browser to abort the stream if the `/trace.json` is big enough.

Image

To fix this for those browsers, the fetching logic in Javascript can be modified to populate chunks with a reader as they come and then populated into a chunk manually.

```
const resp = await fetch(traceUrl);
const reader = resp.body.getReader();
const chunks = [];

while (true) {
const { done, value } = await reader.read();
if (done) break;
chunks.push(value);
}
const blob = new Blob(chunks);
```
Applying this change allows the request to succeed when called within the Javascript in the tab served by `python watch_trace.py`

Image

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.