Git Product home page Git Product logo

Comments (9)

uNetworkingAB avatar uNetworkingAB commented on June 10, 2024

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.

uNetworkingAB avatar uNetworkingAB commented on June 10, 2024

You probably want a pre-allocated ring buffer to add/remove to/from if you benchmark

from usockets.

Zabrane avatar Zabrane commented on June 10, 2024

@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.

Zabrane avatar Zabrane commented on June 10, 2024

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.

uNetworkingAB avatar uNetworkingAB commented on June 10, 2024

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.

Zabrane avatar Zabrane commented on June 10, 2024

@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.

Zabrane avatar Zabrane commented on June 10, 2024

@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.

Zabrane avatar Zabrane commented on June 10, 2024

@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.

uNetworkingAB avatar uNetworkingAB commented on June 10, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.