mirror of
				https://git.asonix.dog/asonix/relay.git
				synced 2025-10-30 21:12:42 +00:00 
			
		
		
		
	Make signature threads configurable
This commit is contained in:
		
							parent
							
								
									78dcce5a08
								
							
						
					
					
						commit
						8071c6ce3f
					
				
							
								
								
									
										2
									
								
								Cargo.lock
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										2
									
								
								Cargo.lock
									
									
									
										generated
									
									
									
								
							|  | @ -391,7 +391,7 @@ checksum = "3b13c32d80ecc7ab747b80c3784bce54ee8a7a0cc4fbda9bf4cda2cf6fe90854" | ||||||
| 
 | 
 | ||||||
| [[package]] | [[package]] | ||||||
| name = "ap-relay" | name = "ap-relay" | ||||||
| version = "0.3.90" | version = "0.3.91" | ||||||
| dependencies = [ | dependencies = [ | ||||||
|  "activitystreams", |  "activitystreams", | ||||||
|  "activitystreams-ext", |  "activitystreams-ext", | ||||||
|  |  | ||||||
|  | @ -1,7 +1,7 @@ | ||||||
| [package] | [package] | ||||||
| name = "ap-relay" | name = "ap-relay" | ||||||
| description = "A simple activitypub relay" | description = "A simple activitypub relay" | ||||||
| version = "0.3.90" | version = "0.3.91" | ||||||
| authors = ["asonix <asonix@asonix.dog>"] | authors = ["asonix <asonix@asonix.dog>"] | ||||||
| license = "AGPL-3.0" | license = "AGPL-3.0" | ||||||
| readme = "README.md" | readme = "README.md" | ||||||
|  |  | ||||||
|  | @ -108,6 +108,7 @@ PROMETHEUS_PORT=9000 | ||||||
| CLIENT_TIMEOUT=10 | CLIENT_TIMEOUT=10 | ||||||
| CLIENT_POOL_SIZE=20 | CLIENT_POOL_SIZE=20 | ||||||
| DELIVER_CONCURRENCY=8 | DELIVER_CONCURRENCY=8 | ||||||
|  | SIGNATURE_THREADS=2 | ||||||
| ``` | ``` | ||||||
| 
 | 
 | ||||||
| #### Descriptions | #### Descriptions | ||||||
|  | @ -168,6 +169,10 @@ files", you can either decrease this number or increase the ulimit for your syst | ||||||
| ##### `DELIVER_CONCURRENCY` | ##### `DELIVER_CONCURRENCY` | ||||||
| Optional - How many deliver requests the relay should allow to be in-flight per thread. the default | Optional - How many deliver requests the relay should allow to be in-flight per thread. the default | ||||||
| is 8 | is 8 | ||||||
|  | ##### `SIGNATURE_THREADS` | ||||||
|  | Optional - Override number of threads used for signing and verifying requests. Default is | ||||||
|  | `std::thread::available_parallelism()` (It tries to detect how many cores you have). If it cannot | ||||||
|  | detect the correct number of cores, it falls back to 1. | ||||||
| 
 | 
 | ||||||
| ### Subscribing | ### Subscribing | ||||||
| Mastodon admins can subscribe to this relay by adding the `/inbox` route to their relay settings. | Mastodon admins can subscribe to this relay by adding the `/inbox` route to their relay settings. | ||||||
|  |  | ||||||
|  | @ -6,7 +6,7 @@ | ||||||
| 
 | 
 | ||||||
| rustPlatform.buildRustPackage { | rustPlatform.buildRustPackage { | ||||||
|   pname = "relay"; |   pname = "relay"; | ||||||
|   version = "0.3.90"; |   version = "0.3.91"; | ||||||
|   src = ./.; |   src = ./.; | ||||||
|   cargoLock.lockFile = ./Cargo.lock; |   cargoLock.lockFile = ./Cargo.lock; | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -48,6 +48,7 @@ pub(crate) struct ParsedConfig { | ||||||
|     deliver_concurrency: u64, |     deliver_concurrency: u64, | ||||||
|     client_timeout: u64, |     client_timeout: u64, | ||||||
|     client_pool_size: usize, |     client_pool_size: usize, | ||||||
|  |     signature_threads: Option<usize>, | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| #[derive(Clone)] | #[derive(Clone)] | ||||||
|  | @ -74,6 +75,7 @@ pub struct Config { | ||||||
|     deliver_concurrency: u64, |     deliver_concurrency: u64, | ||||||
|     client_timeout: u64, |     client_timeout: u64, | ||||||
|     client_pool_size: usize, |     client_pool_size: usize, | ||||||
|  |     signature_threads: Option<usize>, | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| #[derive(Clone)] | #[derive(Clone)] | ||||||
|  | @ -144,6 +146,7 @@ impl std::fmt::Debug for Config { | ||||||
|             .field("deliver_concurrency", &self.deliver_concurrency) |             .field("deliver_concurrency", &self.deliver_concurrency) | ||||||
|             .field("client_timeout", &self.client_timeout) |             .field("client_timeout", &self.client_timeout) | ||||||
|             .field("client_pool_size", &self.client_pool_size) |             .field("client_pool_size", &self.client_pool_size) | ||||||
|  |             .field("signature_threads", &self.signature_threads) | ||||||
|             .finish() |             .finish() | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  | @ -176,6 +179,7 @@ impl Config { | ||||||
|             .set_default("deliver_concurrency", 8u64)? |             .set_default("deliver_concurrency", 8u64)? | ||||||
|             .set_default("client_timeout", 10u64)? |             .set_default("client_timeout", 10u64)? | ||||||
|             .set_default("client_pool_size", 20u64)? |             .set_default("client_pool_size", 20u64)? | ||||||
|  |             .set_default("signature_threads", None as Option<u64>)? | ||||||
|             .add_source(Environment::default()) |             .add_source(Environment::default()) | ||||||
|             .build()?; |             .build()?; | ||||||
| 
 | 
 | ||||||
|  | @ -250,6 +254,16 @@ impl Config { | ||||||
|             deliver_concurrency: config.deliver_concurrency, |             deliver_concurrency: config.deliver_concurrency, | ||||||
|             client_timeout: config.client_timeout, |             client_timeout: config.client_timeout, | ||||||
|             client_pool_size: config.client_pool_size, |             client_pool_size: config.client_pool_size, | ||||||
|  |             signature_threads: config.signature_threads, | ||||||
|  |         }) | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     pub(crate) fn signature_threads(&self) -> usize { | ||||||
|  |         self.signature_threads.unwrap_or_else(|| { | ||||||
|  |             std::thread::available_parallelism() | ||||||
|  |                 .map(usize::from) | ||||||
|  |                 .map_err(|e| tracing::warn!("Failed to get parallelism, {e}")) | ||||||
|  |                 .unwrap_or(1) | ||||||
|         }) |         }) | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -259,7 +259,7 @@ async fn do_server_main( | ||||||
| 
 | 
 | ||||||
|     let keys = config.open_keys()?; |     let keys = config.open_keys()?; | ||||||
| 
 | 
 | ||||||
|     let spawner = Spawner::build()?; |     let spawner = Spawner::build(config.signature_threads())?; | ||||||
| 
 | 
 | ||||||
|     let bind_address = config.bind_address(); |     let bind_address = config.bind_address(); | ||||||
|     let server = HttpServer::new(move || { |     let server = HttpServer::new(move || { | ||||||
|  |  | ||||||
|  | @ -461,12 +461,7 @@ pub(crate) struct Spawner { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| impl Spawner { | impl Spawner { | ||||||
|     pub(crate) fn build() -> std::io::Result<Self> { |     pub(crate) fn build(threads: usize) -> std::io::Result<Self> { | ||||||
|         let threads = std::thread::available_parallelism() |  | ||||||
|             .map(usize::from) |  | ||||||
|             .map_err(|e| tracing::warn!("Failed to get parallelism, {e}")) |  | ||||||
|             .unwrap_or(1); |  | ||||||
| 
 |  | ||||||
|         let (sender, receiver) = flume::bounded(8); |         let (sender, receiver) = flume::bounded(8); | ||||||
|         let (shutdown, shutdown_rx) = flume::bounded(threads); |         let (shutdown, shutdown_rx) = flume::bounded(threads); | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 asonix
						asonix