Project

General

Profile

Feature #11275

Add UDS (Unix Domain Socket) support for communication between FWD client and server

Added by Teodor Gorghe 5 months ago. Updated 4 months ago.

Status:
Review
Priority:
Urgent
Assignee:
Target version:
-
Start date:
Due date:
% Done:

100%

billable:
No
vendor_id:
GCD
case_num:
version_reported:
version_resolved:
production:
No
env_name:
topics:

History

#1 Updated by Teodor Gorghe 5 months ago

  • Status changed from New to WIP
  • Assignee set to Teodor Gorghe

There are two types of Sockets available on the major operating systems Windows/Linux/MacOS:
- Network Sockets (Stream sockets and Datagram sockets)
- Unix Domain Sockets.

Unix Domain Sockets were introduced in Java 16+ and is the fastest method for IPC (Inter-process communication). The only constraint to use this method is that the processes needs to be on the same machine.

In FWD, we currently use Stream sockets, which they use TCP/IP under the hood, which is was slower than UDS. Most FWD Server + Client configurations are in the same machine.
On converted 4GL applications, there are plenty of scenarios where the FWD server communicates heavily with the client (e.g. reading/writing a file, creating a report, etc.)

Initial implementation (from #11259-69) proved that for a scenario which writes to a stream, row by row, 10000 times, the improvement is about 25% (INSECURE loopback vs UDS).

It is worth pointing out that for loopback configuration, when switching to UDS, the SECURE protocol is no longer needed because UDS is much safer (you can't intercept the traffic unless you have the access to that file).

#4 Updated by Alexandru Lungu 5 months ago

Teodor, feel free to commit any intermediary work on #11275. I intend to also make some tests on another customer for early performance analysis, exactly like you do for your customer.

#5 Updated by Teodor Gorghe 5 months ago

I will commit the changes soon, I need to fix the web clients real quick.

#6 Updated by Teodor Gorghe 5 months ago

  • % Done changed from 0 to 10

Created task branch 11275a.
Committed revision 16458 on task branch 11275a:
- Make Appservers and FWD client to work on UDS.

How to make FWD server and appservers to run on UDS:
- add net:server:uds=/tmp/fwd-0.sock to your existing FWD server startup command

To make FWD client to connect through UDS, use net:server:uds=/tmp/fwd-0.sock.

#7 Updated by Teodor Gorghe 5 months ago

Committed revision 16459 on task branch 11275a:
- Allow only UDS clients to authenticate on the process account. Additional fixes.
- For INSECURE connections, the process ID sent through protocol is ignored. It should behave exactly the same as before.
- Added support for Web clients.

#8 Updated by Teodor Gorghe 5 months ago

  • % Done changed from 10 to 40

Committed revision 16460 on task branch 11275a:
- Added probing mechanism which guarantees that only one instance can bind to the same file.

#9 Updated by Constantin Asofiei 5 months ago

Teodor, I think the path of the UDS file needs to be calculated automatically by FWD, using some random UUID and placed in the temporary folder. More, these files need to be cleaned (by the FWD server) when the client terminates, otherwise they will never be cleaned up.

Next: is p2j.net.SessionListener.terminate notification still working?

#10 Updated by Teodor Gorghe 5 months ago

Constantin Asofiei wrote:

Next: is p2j.net.SessionListener.terminate notification still working?

Yes, is still working and I don't see why it might not work after the changes.

Constantin Asofiei wrote:

Teodor, I think the path of the UDS file needs to be calculated automatically by FWD, using some random UUID and placed in the temporary folder. More, these files need to be cleaned (by the FWD server) when the client terminates, otherwise they will never be cleaned up.

Currently, the UDS path is provided by server Bootstrap config. On my setup, I have changed server.sh so it adds this parameter:

uds_params="net:server:uds=/tmp/fwd-${appname}-${instance}.sock" 

# run the FWD server
JAVA_CMD="$prog $dump $perf $hprof $maxheap $srvr $jmx $dtxt $agent $spi $open_api $cpath $cdsparams $entrypoint $mode $batch $cfg $port $uds_params $profile" 

#11 Updated by Teodor Gorghe 5 months ago

Constantin Asofiei wrote:

More, these files need to be cleaned (by the FWD server) when the client terminates, otherwise they will never be cleaned up.

There are multiple scenarios when you can't guarantee the execution of shut down logic of FWD server, like OOME, server crash, system crash/power outage, etc. This is why I have added the probing mechanism, which makes it behave similar like a TCP port.

Also, I don't quite understand what do you mean by cleaning when the FWD client terminates, as long as the FWD server is still running. These files are per server, like how you are using a TCP port for accepting socket connections.

#12 Updated by Constantin Asofiei 5 months ago

Teodor Gorghe wrote:

Also, I don't quite understand what do you mean by cleaning when the FWD client terminates, as long as the FWD server is still running. These files are per server, like how you are using a TCP port for accepting socket connections.

Then please explain something: is this single file used by all FWD clients connected to the FWD server?

#13 Updated by Teodor Gorghe 5 months ago

Yes, the same file is used by all clients and appserver and all data transfer is done in memory.

UDS can simulate Stream (TCP), Datagram (UDP) or RAW.
In case of Stream sockets, connection multiplexing and demultiplexing is done at kernel level and you don't have to worry about this aspect, it is like how you use one TCP port (and handle a TCP Java NIO socket).

#14 Updated by Constantin Asofiei 5 months ago

Teodor Gorghe wrote:

Yes, the same file is used by all clients and appserver and all data transfer is done in memory.

OK, I thought there are some different files created for each connection. Then, I'd still rather compute this filename automatically and place it in the temp-folder as reported by JVM. And in the bootstrap config, just let a flag to enable UDS.

#15 Updated by Teodor Gorghe 5 months ago

Constantin Asofiei wrote:

Teodor Gorghe wrote:

Yes, the same file is used by all clients and appserver and all data transfer is done in memory.

OK, I thought there are some different files created for each connection. Then, I'd still rather compute this filename automatically and place it in the temp-folder as reported by JVM. And in the bootstrap config, just let a flag to enable UDS.

The idea is that you need to know this path before running the FWD server. Swing/ChUI clients needs to know this port in order to connect through UDS.

#16 Updated by Teodor Gorghe 5 months ago

  • % Done changed from 40 to 100
  • reviewer Constantin Asofiei added

Committed revision 16461 on task branch 11275a:
- Added javadocs and reverted AppServerHelper changes.

Constantin, please review the changes and see what might be missing/wrong.

#17 Updated by Teodor Gorghe 5 months ago

  • Status changed from WIP to Review

#18 Updated by Teodor Gorghe 5 months ago

Please also take in consideration the fact that for database UDS, we still use junixsocket.
This was introduced for Java 8 because there is no native support for this version.

#19 Updated by Alexandru Lungu 4 months ago

Teodor, I did the trivial patch of #11275-6. I did not saw any performance improvement per se, but I want to ensure that:

java -Xmx64m -Djava.awt.headless=true -Djava.library.path=[...] -classpath [...] com.goldencode.p2j.main.ClientDriver net:server:host=localhost net:socket:nio=false net:ssl:trackSeqNo=false net:connection:secure=true net:server:secure_port=3333 net:server:uds=/tmp/fwd-0.sock client:mode:batch=true client:driver:background=true security:provider:name=conscrypt server:spawner:uuid=b4ab6301-1c8b-4970-8826-392e1ba32c4c server:clientConfig:outputToFile=/dev/null

These are the right Java client args. Is there any need to secure_port, secure? This is for an appserver.

java -Xmx512m -Djava.awt.headless=true -Duser.country=NL -Duser.language=nl -Djava.library.path=[...] -classpath [...] com.goldencode.p2j.main.ClientDriver net:server:host=localhost net:socket:nio=false net:ssl:trackSeqNo=false net:connection:secure=true net:server:secure_port=3333 net:server:uds=/tmp/fwd-0.sock server:spawner:uuid=006a61c2-ab5a-4461-a8b7-414b5c51abeb

Same question about host, secure, and secure_port. This is a web client.

com.goldencode.p2j.main.FwdLauncher server.xml net:connection:secure=true net:server:secure_port=3333 net:server:insecure_port=3433 net:server:uds=/tmp/fwd-0.sock

Server has this config; again, is the secure_prot, secure and insecure_port required?

Last but not least, are all clients communicating within the same socket? I guess yes, considering that a single port was used for tcp/ip.

#20 Updated by Teodor Gorghe 4 months ago

Alexandru Lungu wrote:

Server has this config; again, is the secure_prot, secure and insecure_port required?

net:server:secure_port=3333 net:server:insecure_port=3433 are not required and I think your FWD clients has connected through UDS.

Alexandru Lungu wrote:

Last but not least, are all clients communicating within the same socket? I guess yes, considering that a single port was used for tcp/ip.

Yes, all clients are connected through the same socket, provided at server startup.

#21 Updated by Teodor Gorghe 4 months ago

I will also considering testing the scenario which you are trying, to see if there is something else.

#22 Updated by Teodor Gorghe 4 months ago

Also, I have a question. For web clients to connect on UDS, you need to use revision 16459.
I think you are using revision 16458, which web clients are not supported.

#23 Updated by Alexandru Lungu 4 months ago

Also, I have a question. For web clients to connect on UDS, you need to use revision 16459.

I used 11275a/rev. 16461.

I will also considering testing the scenario which you are trying, to see if there is something else.

I am testing #11184 mostly (the one that triggered my comment in the first place), but also #11242.

I saw you made a comment on #11242 - that is the one that is really intensive in terms on server-client communication - many (>150) with >1MB of data in total.

Also available in: Atom PDF