Skip to content

Commit

Permalink
using fork to fix mem and cpu issues
Browse files Browse the repository at this point in the history
  • Loading branch information
erhant committed Aug 19, 2024
1 parent 7c2888c commit e013ba5
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 43 deletions.
62 changes: 34 additions & 28 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 21 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "dkn-compute"
version = "0.1.4"
version = "0.1.5"
edition = "2021"
license = "Apache-2.0"
readme = "README.md"
Expand All @@ -19,6 +19,7 @@ async-trait = "0.1.81"
reqwest = "0.12.5"

# utilities
dotenvy = "0.15.7"
base64 = "0.22.0"
hex = "0.4.3"
hex-literal = "0.4.1"
Expand All @@ -42,14 +43,30 @@ fastbloom-rs = "0.5.9"
ollama-workflows = { git = "https://github.com/andthattoo/ollama-workflows", rev = "25467d2" }

# peer-to-peer
libp2p = { git = "https://github.com/anilaltuner/rust-libp2p.git", rev = "eb0e57b", features = ["dcutr", "ping", "relay", "autonat", "identify", "tokio", "gossipsub", "mdns", "noise", "macros", "tcp", "yamux", "quic", "kad"] }
libp2p = { git = "https://github.com/anilaltuner/rust-libp2p.git", rev = "84b6d6f", features = [
"dcutr",
"ping",
"relay",
"autonat",
"identify",
"tokio",
"gossipsub",
"mdns",
"noise",
"macros",
"tcp",
"yamux",
"quic",
"kad",
] }

libp2p-identity = { version = "0.2.9", features = ["secp256k1", "ed25519"] }
tracing = { version = "0.1.40" }
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
public-ip = "0.2.2"
dotenvy = "0.15.7"
getrandom = "0.2.15"

# TODO: solves ecies dependency issue
# getrandom = "0.2.15"


[dev-dependencies]
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ launch:

.PHONY: run # | Run with INFO log-level
run:
RUST_LOG=warn,dkn_compute=info cargo run
RUST_LOG=none,dkn_compute=info cargo run

.PHONY: debug # | Run with DEBUG log-level with INFO log-level workflows
debug:
Expand Down
2 changes: 1 addition & 1 deletion src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ impl DriaComputeNode {
// handle message w.r.t topic
if std::matches!(topic_str, PINGPONG_LISTEN_TOPIC | WORKFLOW_LISTEN_TOPIC) {
// ensure that the message is from a valid source (origin)
let source_peer_id = message.source.clone();
let source_peer_id = message.source;
// let source_peer_id = match message.source.clone() {
// Some(peer) => peer,
// None => {
Expand Down
14 changes: 7 additions & 7 deletions src/p2p/behaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@ impl DriaBehaviour {
fn create_kademlia_behavior(local_peer_id: PeerId) -> kad::Behaviour<MemoryStore> {
use kad::{Behaviour, Config};

let mut cfg = Config::default();
cfg.set_protocol_names(vec![DRIA_PROTO_NAME])
.set_query_timeout(Duration::from_secs(5 * 60));
const QUERY_TIMEOUT_SECS: u64 = 5 * 60; // 5 minutes

let mut cfg = Config::new(DRIA_PROTO_NAME);
cfg.set_query_timeout(Duration::from_secs(QUERY_TIMEOUT_SECS));

Behaviour::with_config(local_peer_id, MemoryStore::new(local_peer_id), cfg)
}
Expand Down Expand Up @@ -79,9 +80,7 @@ fn create_autonat_behavior(key: PublicKey) -> autonat::Behaviour {
/// Configures the Gossipsub behavior for pub/sub messaging across peers.
#[inline]
fn create_gossipsub_behavior(id_keys: Keypair) -> gossipsub::Behaviour {
use gossipsub::{
Behaviour, ConfigBuilder, Message, MessageAuthenticity, MessageId, ValidationMode,
};
use gossipsub::{Behaviour, ConfigBuilder, Message, MessageAuthenticity, MessageId};

/// Message TTL in seconds
const MESSAGE_TTL: u64 = 100;
Expand All @@ -107,8 +106,9 @@ fn create_gossipsub_behavior(id_keys: Keypair) -> gossipsub::Behaviour {
.message_id_fn(message_id_fn)
.message_ttl(Duration::from_secs(MESSAGE_TTL))
.message_capacity(MESSAGE_CAPACITY)
.max_ihave_length(100)
.build()
.expect("Valid config"), // TODO: better error handling
)
.expect("Valid behaviour") // TODO: better error handling
.expect("Valid behaviour") // TODO: better error handling
}
5 changes: 3 additions & 2 deletions src/p2p/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl P2PClient {
let mut swarm = SwarmBuilder::with_existing_identity(keypair)
.with_tokio()
.with_tcp(
tcp::Config::default().port_reuse(true),
tcp::Config::default(),
noise::Config::new,
yamux::Config::default,
)
Expand Down Expand Up @@ -237,7 +237,8 @@ impl P2PClient {
)) => self.handle_closest_peers_result(result),
SwarmEvent::Behaviour(DriaBehaviourEvent::Identify(identify::Event::Received {
peer_id,
info, connection_id
info,
..
})) => self.handle_identify_event(peer_id, info),
SwarmEvent::Behaviour(DriaBehaviourEvent::Gossipsub(gossipsub::Event::Message {
propagation_source: peer_id,
Expand Down

0 comments on commit e013ba5

Please sign in to comment.