Comments (9)
That example is doing malloc, memcpy and free every time it streams a chunk to kernel, so I wouldn't use it for benchmarking, esp. not with large data. And if you see double frees then it's pretty broken.
from usockets.
You probably want a pre-allocated ring buffer to add/remove to/from if you benchmark
from usockets.
@uNetworkingAB could you please help us to adapt the echo TCP example to use a pre-allocated ringbuffer
?
Any test code will be more than welcome. I really want to get rid of this proprietary server.
from usockets.
That example is doing malloc, memcpy and free every time it streams a chunk to kernel, so I wouldn't use it for benchmarking, esp. not with large data. And if you see double frees then it's pretty broken.
The benchmark consists of sending and receiving a single character
as fast as possible. Thus, no large data is involved. Just a single char.
from usockets.
void bsd_socket_nodelay(LIBUS_SOCKET_DESCRIPTOR fd, int enabled) {
setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, (void *) &enabled, sizeof(enabled));
}
bsd_socket_nodelay(us_poll_fd((struct us_poll_t *)s), 0);
You probably want to run this in on_open to disable TCP_NODELAY - pretty sure your proprietary variant has TCP_NODELAY=false, we have it true by default
from usockets.
@uNetworkingAB didn't change anything even with static buffer (no malloc involved, 1 big global alloc) and TCP_NODELAY
set to false
per your recommendation.
Linux:
Destination: [127.0.0.1]:3000
Total data sent: 11.7 MiB
Total data received: 6.0 MiB
Bandwidth per channel: 29.729⇅ Mbps
Test duration: 5.00832 s.
from usockets.
@uNetworkingAB Hi. How can i set the socket's buffers
size when using uSockets
?
To get this:
setsockopt(s, SOL_SOCKET, SO_RCVBUF, &sz, sizeof(sz));
setsockopt(s, SOL_SOCKET, SO_SNDBUF, &sz, sizeof(sz));
Does uSockets
set the socket to non-blocking
?
fcntl(s, F_SETFL, O_NONBLOCK, s)
from usockets.
@uNetworkingAB I've noticed that you perform a socket write
in the on_echo_socket_data callback
. Why?
If i don't write
during reads
, the on_echo_socket_writable
callback's never called.
struct us_socket_t *on_echo_socket_data(struct us_socket_t *s, char *data, int length) {
struct echo_socket *es = (struct echo_socket *) us_socket_ext(SSL, s);
/* don't write, just buffer up the number of 'x' to send back */
es->length += length;
return s;
}
Could you please shed some light on the underlying uSockets
design?
from usockets.
If you want to pay for consulting time you can send me such an email and we can set it up. It's becoming obvious that you're benchmarking apples vs. carrots here, as the echo_server doesn't do what your alternative does. With some rough math you can infer that you must be doing 3.8 billion messages (chars) per second, which is 0.1 nanosecond a pop, which is not the case. So it's an apple vs. carrot comparison
from usockets.
Related Issues (20)
- "src/internal/internal.h:119:5: error: unknown type name 'uint32_t'" When building with boost.asio
- Rewrite in Rust
- Zig experiment ? HOT 1
- [regression in 0.8.6] error: use of undeclared identifier 'IP_PKTINFO' HOT 1
- Compile static library on windows HOT 2
- Error initializing structure msg_hdr by UDP, field msg_name
- us_socket_context_connect timeout HOT 6
- Server fails to bind localhost in container
- Memory leak in us_create_timer
- It is good, can it support CMakeLists.txt? HOT 1
- Tests fail to compile: error: comparison between pointer and integer ('void *' and 'int') HOT 2
- us_socket_context_pre_open event
- Are closed fd's being polled? HOT 8
- Build fails without -fPIC flag supplied from outside
- works with letsencrypt ? HOT 2
- Failed to bind to 0.0.0.0
- nullptr access in us_internal_loop_unlink
- Update boringSSL HOT 2
- Upgrade socket from TCP to TLS mid-use
- Compilation issue when using WSL HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from usockets.