Skip to content

Commit 778d169

Browse files
committed
add custom env option
1 parent 5a31963 commit 778d169

File tree

6 files changed

+246
-285
lines changed

6 files changed

+246
-285
lines changed

Makefile

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,11 @@ ifneq (,$(wildcard ./.env))
55
endif
66

77
###############################################################################
8-
.PHONY: launch # | Run with INFO logs in release mode
9-
launch:
10-
cargo run --release --bin dkn-compute
11-
12-
.PHONY: run # | Run with INFO logs
13-
run:
14-
cargo run --bin dkn-compute
15-
16-
.PHONY: monitor # | Run monitor node with INFO logs
17-
monitor:
18-
cargo run --bin dkn-monitor
19-
208
.PHONY: debug # | Run with DEBUG logs with INFO log-level workflows
219
debug:
2210
RUST_LOG=warn,dkn_compute=debug,dkn_workflows=debug,dkn_p2p=debug,ollama_workflows=info \
2311
cargo run --bin dkn-compute
2412

25-
.PHONY: trace # | Run with TRACE logs
26-
trace:
27-
RUST_LOG=warn,dkn_compute=trace,libp2p=debug \
28-
cargo run --bin dkn-compute
29-
3013
.PHONY: build # | Build
3114
build:
3215
cargo build --workspace

README.md

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,13 @@ If you would like to run the node from source (which is really handy during deve
6565
make help
6666
```
6767

68-
You will need OpenSSL installed as well, see shorthand commands [here](https://github.com/sfackler/rust-openssl/issues/855#issuecomment-450057552). While running Ollama elsewhere (if you are using it) or with an OpenAI API key provided, you can run the compute node with:
68+
You will need OpenSSL installed, see shorthand commands [here](https://github.com/sfackler/rust-openssl/issues/855#issuecomment-450057552).
6969

7070
```sh
71-
make run # info-level logs
72-
make debug # debug-level logs
71+
cargo run
72+
73+
# specify custom .env file
74+
DKN_COMPUTE_ENV=./path/to/.env cargo run
7375
```
7476

7577
If you have a valid `.env` file, you can run the latest Docker image via compose as well:
@@ -112,6 +114,28 @@ make lint # clippy
112114
make format # rustfmt
113115
```
114116

117+
### Profiling
118+
119+
We have scripts to profile both CPU and Memory usage. A special build is created for profiling, via a custom `profiling` feature, such that the output inherits `release` mode but also has debug symbols.
120+
121+
Furthermore, the profiling build will exit automatically after a certain time, as if CTRL+C has been pressed. This is needed by the memory profiling tool in particular.
122+
123+
**CPU Profiling**: To create a [flamegraph](https://crates.io/crates/flamegraph) of the application, the command below will create a profiling build that inherits `release` mode, except with debug information:
124+
125+
```sh
126+
make profile-cpu
127+
```
128+
129+
> [!NOTE]
130+
>
131+
> CPU profiling may require super-user access.
132+
133+
**Memory Profiling**: To profile memory usage, we make use of [cargo-instruments](https://crates.io/crates/cargo-instruments):
134+
135+
```sh
136+
make profile-mem
137+
```
138+
115139
## License
116140

117141
This project is licensed under the [Apache License 2.0](https://opensource.org/license/Apache-2.0).

compute/src/main.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ use workers::task::TaskWorker;
77

88
#[tokio::main]
99
async fn main() -> Result<()> {
10-
let dotenv_result = dotenvy::dotenv();
10+
// load a particular env, or `.env` by default
11+
let env_path = env::var("DKN_COMPUTE_ENV").unwrap_or_else(|_| ".env".to_string());
12+
let dotenv_result = dotenvy::from_path(&env_path);
1113

1214
env_logger::builder()
1315
.format_timestamp(Some(env_logger::TimestampPrecision::Millis))
@@ -33,8 +35,8 @@ async fn main() -> Result<()> {
3335

3436
// log about env usage
3537
match dotenv_result {
36-
Ok(path) => log::info!("Loaded .env file at: {}", path.display()),
37-
Err(e) => log::warn!("Could not load .env file: {}", e),
38+
Ok(_) => log::info!("Loaded environment file from {}", env_path),
39+
Err(e) => log::warn!("Could not load environment file from {}: {}", env_path, e),
3840
}
3941

4042
// task tracker for multiple threads

docs/NODE_PERFORMANCE.md

Lines changed: 0 additions & 51 deletions
This file was deleted.

0 commit comments

Comments
 (0)