| Crates.io | vma-socket |
| lib.rs | vma-socket |
| version | 0.1.5 |
| created_at | 2025-03-09 13:15:55.541573+00 |
| updated_at | 2025-06-03 07:10:26.306528+00 |
| description | High-level Rust bindings for Mellanox/NVIDIA VMA (Messaging Accelerator) sockets |
| homepage | |
| repository | https://github.com/JunbeomL22/vma-socket |
| max_upload_size | |
| id | 1585466 |
| size | 221,079 |
A flexible high-level Rust API for TCP/UDP sockets leveraging Mellanox/NVIDIA VMA (Messaging Accelerator) for low-latency networking.
vma-socket provides a clean, ergonomic Rust interface to the VMA library, allowing developers to access the performance benefits of VMA while working with a familiar and safe API. The library offers:
libvma.so)Add this to your Cargo.toml:
[dependencies]
vma-socket = "0.1"
use std::time::Duration;
use vma_socket::udp::VmaUdpSocket;
use vma_socket::common::VmaOptions;
// Create a UDP socket
let mut socket = VmaUdpSocket::new()?;
// Or with custom options
let options = VmaOptions::low_latency();
let mut socket = VmaUdpSocket::with_options(options)?;
// Server: bind to an address
socket.bind("0.0.0.0", 5001)?;
// Client: connect to a server
socket.connect("192.168.1.100", 5001)?;
socket.send("Hello".as_bytes())?;
// Receive data with timeout
let mut buffer = vec![0; 4096];
match socket.recv_from(&mut buffer, Some(Duration::from_millis(100)))? {
Some(packet) => println!("Received: {}",
String::from_utf8_lossy(&packet.data)),
None => println!("No data received (timeout)"),
}
use std::time::Duration;
use vma_socket::tcp::VmaTcpSocket;
use vma_socket::common::VmaOptions;
// Server example
let mut server = VmaTcpSocket::new()?;
server.bind("0.0.0.0", 5002)?;
server.listen(10)?;
if let Some(mut client) = server.accept(Some(Duration::from_secs(1)))? {
let mut buffer = vec![0u8; 1024];
let received = client.recv(&mut buffer, Some(Duration::from_millis(100)))?;
client.send(&buffer[0..received])?;
}
// Client example
let mut client = VmaTcpSocket::new()?;
if client.connect("192.168.1.100", 5002, Some(Duration::from_secs(5)))? {
client.send("Hello".as_bytes())?;
}
The library allows flexible configuration:
// Use predefined profiles
let low_latency = VmaOptions::low_latency();
let high_throughput = VmaOptions::high_throughput();
// Or customize your own
let custom_options = VmaOptions {
use_socketxtreme: true,
optimize_for_latency: true,
use_polling: true,
ring_count: 2,
buffer_size: 8192,
// ... other options
};
To use the VMA acceleration, preload the VMA library when running your application:
LD_PRELOAD=/usr/lib64/libvma.so.x.x.x ./your_application
For testing examples, use the included run.sh script:
# Terminal 1: Run UDP server
./run.sh udp_test [server|client] [address] [port]
# Terminal 2: Run UDP client
./run.sh udp_test [server|client] [address] [port]
You can also specify addresses and ports:
./run.sh tcp_test server 0.0.0.0 5002
./run.sh tcp_test client 192.168.1.100 5002
This project is licensed under the MIT or Apache-2.0 License.