From 3b89ae82ea9468d54c60a63fd03b9a829748a0ac Mon Sep 17 00:00:00 2001 From: eunhhu Date: Sat, 26 Sep 2026 04:53:55 +0100 Subject: Serve modules through the runtime core with group commits pure-connections-module offers the document server's HTTP contract with an aup module: GET is its show message and PUT its edit message. Requests go through the runtime core as before (work slots, payload budget, ingress, replies borrowed from the request), and effects are taken on the owner thread with the core's asynchronous interface. Each poll round is one burst: every ready request is applied to the app with deferred saving, one save stores them, and only then are the tickets completed and answered. A failed save fails the whole burst, reads too. A key seen again ends the burst first, and the module server accepts every waiting connection at once so concurrent requests share a burst. On the Pi's SD card eight clients' 240 edits take 0.59 s instead of 2.14 s. --- docs/design/008-module-format.md | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'docs/design/008-module-format.md') diff --git a/docs/design/008-module-format.md b/docs/design/008-module-format.md index 4c5a9ac..2d30003 100644 --- a/docs/design/008-module-format.md +++ b/docs/design/008-module-format.md @@ -197,6 +197,25 @@ text·리스트가 남을 때만 위치를 유지한다. 실패하면 묶음 전체가 되돌려지고, 저장 중 프로세스가 죽으면 묶음 전체가 남거나 전혀 남지 않는다. 비용(Pi 5, SD의 ext4): 저장하는 이벤트 하나에 약 10.6 ms가 더 든다. 대부분 두 번의 `fsync`다. 300항목 리스트에서 인덱스 이동 한 번은 파일을 약 220 B 키운다(압축 전). -아직 런타임 코어(`runtime.c`)의 작업·예산 모델과 연결하지 않았다. 호스트가 직접 호출한다. 실행기 코드는 +## 런타임 코어 위의 HTTP 서버 + +`pure-connections-module --module 앱.pmod --store 경로`는 기존 문서 서버(`server.c`)와 같은 HTTP 계약을 모듈로 +제공한다. `GET /objects/키`는 모듈의 `show` 메시지, `PUT`(`If-Match`/`If-None-Match`)은 `edit` 메시지다. 요청은 +런타임 코어(`runtime.c`)를 그대로 거친다. 작업 슬롯 8개, 입력 바이트 예산, 코어가 소유한 ingress, 입력에서 빌린 +PUT 응답이 모두 기존과 같다. 효과는 비동기 인터페이스(`pure_runtime_take`/`pure_runtime_complete`)로 소유 스레드에서 +처리한다. + +- **poll 한 바퀴가 묶음 하나다.** 준비된 요청을 모두 꺼내 지연 저장 모드의 앱에 차례로 적용하고, `pure_app_save` + 한 번으로 저장한 **뒤에** 티켓을 완료하고 응답한다. 저장이 실패하면 그 묶음의 읽기까지 모두 실패한다. 저장되지 + 않은 상태를 본 응답은 나가지 않는다. 같은 키가 다시 오면 묶음을 먼저 끝낸다. 모듈 서버는 기다리는 연결을 한 번에 + 모두 받아 동시 요청이 같은 묶음에 들어가게 한다. +- GET 응답은 코어 예산에 계상되는 자원으로 복사한다. PUT 응답은 코어 계약대로 요청 본문에서 빌려야 하므로 `edit` + 핸들러는 메시지 필드만 응답할 수 있다(`reply edit.insert`). 시작할 때 확인한다. +- 검증(aup `make check`): `editor.aup`를 실행하는 모듈 서버와 `editor.pure`를 실행하는 기존 서버가 무작위 요청 + (새 키, 오래된 리비전, 범위 밖, 짧은 본문, 5,000 B 삽입)에 상태 코드·ETag·오류·본문까지 같게 답한다. 동시 편집 중 + `kill -9`로 죽여도 확인 응답을 받은 편집은 다시 시작한 서버에 모두 있다. Pi 5 SD(ext4)에서 동시 클라이언트 8개의 + PUT 240건: 기존 서버 2.14 s, 모듈 서버 0.59 s(묶음 61개). + +아직 모듈 앱을 런타임 코어의 효과 단위로 세분하지는 않았다(`runtime.c`의 `definition`은 앱 전체다). 호스트가 직접 호출한다. 실행기 코드는 `module.c` 33.1 KB, `module-text.c` 3.6 KB, `module-list.c` 5.7 KB, `module-save.c` 5.3 KB(`-O2` text)로 v1(7.4 KB)보다 크다. 줄이는 것이 남은 일이다. 항목 text를 읽을 때마다 복사하는 비용도 남아 있다. -- cgit v1.2.3