Skip to content

Commit ea82f8e

Browse files
committed
Fix benchmark cache reset and log routines
1 parent a2b7042 commit ea82f8e

File tree

5 files changed

+42
-8
lines changed

5 files changed

+42
-8
lines changed

bench/.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
trakxbench
2-
32
__pycache__/
3+
results/

bench/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ The orchestrator will launch Trakx with:
3535
trakx --config bench/trakx.yaml start
3636
```
3737

38-
It also sets `TRAKX_CACHE` to a benchmark-only directory and deletes it between runs.
38+
It deletes the configured cache directory between runs to reset state.
3939

4040
## Orchestrated workflow (recommended)
4141

bench/orchestrator_server.py

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,43 @@ def wait_for_udp(host: str, port: int, timeout: float) -> bool:
105105
return False
106106

107107

108-
def clear_cache(cache_dir: str) -> None:
108+
def default_cache_dir() -> Optional[Path]:
109+
xdg = os.environ.get("XDG_CACHE_HOME")
110+
if xdg:
111+
return Path(xdg) / "trakx"
112+
home = Path.home()
113+
if home:
114+
return home / ".cache" / "trakx"
115+
return None
116+
117+
118+
def read_cache_path(config_path: str, repo_root: Path) -> Optional[Path]:
119+
try:
120+
with open(config_path, "r", encoding="utf-8") as fh:
121+
for line in fh:
122+
stripped = line.strip()
123+
if not stripped or stripped.startswith("#"):
124+
continue
125+
if stripped.startswith("cache:"):
126+
value = stripped[len("cache:") :].strip()
127+
if not value:
128+
return default_cache_dir()
129+
value = value.strip("\"'")
130+
path = Path(value).expanduser()
131+
if not path.is_absolute():
132+
path = repo_root / path
133+
return path
134+
except OSError:
135+
return default_cache_dir()
136+
return default_cache_dir()
137+
138+
139+
def clear_cache(cache_dir: Optional[Path]) -> None:
109140
if not cache_dir:
110141
return
142+
cache_dir = cache_dir.resolve()
143+
if cache_dir == Path("/"):
144+
return
111145
shutil.rmtree(cache_dir, ignore_errors=True)
112146

113147

@@ -132,6 +166,8 @@ def main() -> int:
132166

133167
listen_host, listen_port = parse_hostport(args.listen)
134168
env_base = os.environ.copy()
169+
env_base.pop("TRAKX_CACHE", None)
170+
cache_dir = read_cache_path(args.config, repo_root)
135171

136172
server_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
137173
server_sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
@@ -161,9 +197,7 @@ def main() -> int:
161197
env["TRAKX_HTTP_ROUTINES"] = str(http_routines)
162198

163199
_ = run_cmd([args.trakx_bin, "--config", args.config, "stop"], env=env)
164-
cache_dir = env.get("TRAKX_CACHE")
165-
if cache_dir:
166-
clear_cache(cache_dir)
200+
clear_cache(cache_dir)
167201

168202
start = run_cmd([args.trakx_bin, "--config", args.config, "start"], env=env)
169203
if start.returncode != 0:

tracker/http/httptracker.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func (tracker *Tracker) Serve(ip net.IP, port int, routines int) error {
5555
if err != nil {
5656
return errors.Wrap(err, "Failed to open TCP listen socket")
5757
}
58-
zap.L().Info("Serving HTTP tracker on", zap.String("address", listener.Addr().String()))
58+
zap.L().Info("Serving HTTP tracker", zap.String("address", listener.Addr().String()), zap.Int("routines", routines))
5959

6060
// TODO: figure out what optimal number of goroutines is (benchmark)
6161
// Going to need to write a tool that can simulate a large number of clients

tracker/udp/udptracker.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ func (tracker *Tracker) Serve(ip net.IP, port int, routines int) error {
6666
if err != nil {
6767
return errors.Wrap(err, "Failed to open UDP listen socket")
6868
}
69-
zap.L().Info("Serving UDP tracker on", zap.String("address", tracker.socket.LocalAddr().String()))
69+
zap.L().Info("Serving UDP tracker", zap.String("address", tracker.socket.LocalAddr().String()), zap.Int("routines", routines))
7070

7171
// TODO: figure out what optimal number of goroutines is (benchmark)
7272
// Going to need to write a tool that can simulate a large number of clients

0 commit comments

Comments
 (0)