Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance demo/async/ to allow async dial by client #1770

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

drbitboy
Copy link
Contributor

@drbitboy drbitboy commented Feb 7, 2024

demo/async/client.c

  • Enable client, on dial, to wait for server that has not yet started

demo/async/arun.sh

  • Run async demo with arbitrary start order of server wrt clients

fixes #<N/A>

P.S. I have not been able to make the client nng_aio_send and
nng_aio_recv routines work, but that is an issue for another day.

demo/async/client.c

- Enable client, on dial, to wait for server that has not yet started

demo/async/arun.sh

- Run async demo with arbitrary start order of server wrt clients
@drbitboy
Copy link
Contributor Author

drbitboy commented Feb 7, 2024

If the _build/ CMake subdirectory is used to build nng, and then a sub-directory demo_async/ is created under that,
then copying the contents of the demo/async/ demo sub-dir to there (e.g. rsync -av ../../demo/async/ ./), and
creating the Makefile below will allow building the demo.

EXES=client server

all: $(EXES)
        @true

%: %.c
        gcc -I ../../include $@.c ../libnng.a -pthread -o $@

clean:
        $(RM) $(EXES)

Yes, I know I should figure out how to do it with the CMakeLists.txt, but this was simpler for me.

@drbitboy
Copy link
Contributor Author

drbitboy commented Feb 7, 2024

The new arun.sh (asynchronous-client run) should yield results similar to these:

Run with server starting after all clients

$ ./arun.sh
Starting client 1: server will reply after 1107 msec
Starting client 2: server will reply after 512 msec
Starting client 3: server will reply after 580 msec
Starting client 4: server will reply after 1192 msec
Starting client 5: server will reply after 1172 msec
Starting client 6: server will reply after 1057 msec
Starting client 7: server will reply after 1199 msec
Starting client 8: server will reply after 766 msec
Starting client 9: server will reply after 543 msec
Starting client 10: server will reply after 1309 msec
Starting server after last client - SERVER_PID=15723
Request took 893 milliseconds.
Request took 1162 milliseconds.
Request took 1174 milliseconds.
Request took 1190 milliseconds.
Request took 1193 milliseconds.
Request took 1311 milliseconds.
Request took 1402 milliseconds.
Request took 1413 milliseconds.
Request took 1731 milliseconds.
Request took 2027 milliseconds.

Run with server starting before all clients:

Started server before client 1
Starting client 1: server will reply after 1370 msec
Starting client 2: server will reply after 1187 msec
Starting client 3: server will reply after 730 msec
Starting client 4: server will reply after 1003 msec
Starting client 5: server will reply after 979 msec
Starting client 6: server will reply after 962 msec
Starting client 7: server will reply after 625 msec
Starting client 8: server will reply after 1207 msec
Starting client 9: server will reply after 770 msec
Starting client 10: server will reply after 1088 msec
Request took 626 milliseconds.
Request took 732 milliseconds.
Request took 772 milliseconds.
Request took 964 milliseconds.
Request took 980 milliseconds.
Request took 1005 milliseconds.
Request took 1089 milliseconds.
Request took 1208 milliseconds.
Request took 1371 milliseconds.
Request took 1691 milliseconds.

Run with server starting after first three client and before last seven clients:

$ ./arun.sh  4
Starting client 1: server will reply after 1373 msec
Starting client 2: server will reply after 911 msec
Starting client 3: server will reply after 1201 msec
Started server before client 4
Starting client 4: server will reply after 670 msec
Starting client 5: server will reply after 1313 msec
Starting client 6: server will reply after 697 msec
Starting client 7: server will reply after 948 msec
Starting client 8: server will reply after 851 msec
Starting client 9: server will reply after 578 msec
Starting client 10: server will reply after 543 msec
Request took 797 milliseconds.
Request took 883 milliseconds.
Request took 1110 milliseconds.
Request took 1198 milliseconds.
Request took 1467 milliseconds.
Request took 1679 milliseconds.
Request took 1682 milliseconds.
Request took 1692 milliseconds.
Request took 1775 milliseconds.
Request took 1969 milliseconds.

@drbitboy
Copy link
Contributor Author

drbitboy commented Mar 4, 2024

Merged latest nanomsg/nnsg master (2024-03-04).

Let me know if there is anything you need to review this PR.

Best regards,

Brian T. Carcich

@drbitboy
Copy link
Contributor Author

Hey all,

I added an asynchronous client to the async demo; it also sends multiple (i.e. hardcoded 3) requests to the server.

Let me know if there is anything you need to review this PR, or if it is even worth keeping.

Best regards,

Brian T. Carcich

@gdamore gdamore self-requested a review March 16, 2024 23:18
@gdamore
Copy link
Contributor

gdamore commented Mar 17, 2024

This looks like you're addressing separate issues here. One is to allow non-blocking dialing, and that change looks small and good. The other is the aioclient -- I'm less confident in that.

I'd rather these were separate PRs.

Copy link
Contributor

@gdamore gdamore left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please separate the small async dialing change for the client into its own PR.

@drbitboy
Copy link
Contributor Author

drbitboy commented Mar 17, 2024

Okay, thanks for the review.

... Done; see #1800.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants