Tibor17 commented on issue #240: [SUREFIRE-1658] TCP/IP Channel for forked Surefire JVM. Extensions API and SPI. Polymorphism for remote and local process communication. URL: https://github.com/apache/maven-surefire/pull/240#issuecomment-547583722 > > > I will plan to implement both TCP and UDP, and we can do a performance comparison by running it on real projects' test suites. I am not sure that the difference will be that significant, and if it isn't, supporting both can risk end-user misconfigurations (and in general increase the complexity of the configuration for surefire, which presumably should be avoided if possible). As it looks like you’ve already found out, for small messages that come in bursts, `TCP_NO_DELAY` can provide a significant performacne improvement for TCP connections. I expect the TCP/UDP roundtrip cca 1 microsecond or even shorter. So you may see a difference when you transmit all system properties or another bunch of data and encoded data wih Base64 + Header. The UDP is simpler a bit in the Java code but that's all benefit I would say. I expected a simple and polymorphic configuration. That's why we have the classes `ForkedChannelServer` (custom impl of the server) and `ForkedChannel` (customozed impl of data encoder/decoder). If you use `ForkedChannel` in the POM, it may look like this: (with URI as simple XSD value) ``` <forkedChannelServer implements="com.abc.MessagingQueueProducer"> tcp://127.0.0.1:61616?maximumConnections=1000&wireFormat.maxFrameSize=104857600 <forkedChannelServer> ``` (with complex XSD type, elements are not in ForkedChannelServer and they come **from dependency added by the user in the plugin section in user's POM**) ``` <forkedChannelServer implements="com.abc.MessagingQueueProducer"> <host>127.0.0.1</host> <port>61616</port> <options>maximumConnections=1000, wireFormat.maxFrameSize=104857600</options> <forkedChannelServer> ``` (default, tcp, does not need to be written in POM at all) ``` <forkedChannelServer/> ``` but we can with udp://127.0.0.1:<random>, e.g. ``` <forkedChannelServer>udp://</forkedChannelServer> ``` legacy interprocess channel with pipes ``` <forkedChannelServer>pipe://</forkedChannelServer> ``` > > I tried to understand what you’ve got here but am having difficulty due to lack of documentation, and because things are not fully connected. Should `ForkedChannelServer` implement `DifferedChannelCommandSender`? I am sorry for missing doc. That's why the work is still ongoing and iterative which means that still we cnn changge anything. I tried not to tightly couple `ForkedChannelServer` and `DifferedChannelCommandSender`; otherwise we would never be able to decouple them for whatever reason in the future. Also I wanted to hide some information in the configuration and prevent the user to call methods which should not be propagated outside in POM. > If so, why is it in `surefire-extensions-api` and not in `maven-surefire-common`? Do you have any design documentation to point me to? If not, how set are you on this architecture? Good questios. The `maven-surefire-common` holds the default implementations of two MOJOs. The server does not need to `know` the MOJO details. That's why we isolated `surefire-extensions-api` and plugin impl. Suppose, if we coupled all together in `maven-surefire-common`, we could have a big problem because the user may specify plugin version `B` and add her/his dependency with customized server below the plugin. The dependency would be would be dependent on `maven-surefire-common:A` where `B > A`. This means some incompatibility between these two versions. Even if we are doing our best to retain backwards compatibility, sometimes we have to change a little detail in the common due to bugfixes. This detail may be important for the user who implemented `surefire-extensions-api` in his dependency. This way we decouple API abstractions in `surefire-extensions-api` and `surefire-api` from the MOJO implementation in `maven-surefire-common`. Notice that `surefire-extensions-api` depends only on `surefire-api`. If we do not break the abstraction, we are on safe side, hopefuly until new version 4.0 or 5.0. You'r right, the documentation is missing and needs to be written. That's true! btw, we can still change some names of methods in the interfaces since we are cutting milestone release versions. > > At a high level, how I would plan to do this is: > In `ForkStarter.fork`, we will instantiate some new helper class (called, for instance, `ForkedProcessServer` that will be responsible for creating and managing a `ServerSocket` (or `DatagramSocket` if UDP). This will bind to a random port, then pass that port to the forked process as a parameter. It will be the responsibility of `ForkedProcessServer` to provide the glue between the `ForkClient` the socket? The `ForkedProcessServer` is abstract class. So the will be default impl unless the user specifies her/his impl in the POM. This means that we do not call `ForkedProcessServer` but Maven is instantiating the `ForkedProcessServer`. It's like IoC. It looks like this in MOJO and therefore I did not complete it because I have not finished the concrete class and the tests would fail without it today. Similar extensions already exist but they are not abstract because they must not be. I guess we have to make them non-abstract here too. I had a problem to specify default impl because it simply does work in the Maven. So this is the IoC injection for another extension but the principle would be the same for us as well: ``` @Parameter private SurefireStatelessReporter statelessTestsetReporter; ``` > > The `ForkProcessServer` will set up `StreamPumper`s similarly to how `CommandLineUtils.executeCommandLine` does right now, but instead of connecting to `stdin` and `stdout`, they will connect to the socket’s streams. I was planning to have a 1:1 mapping of `SocketServer`s to forks, rather than create a single `SocketServer` to keep alive for all forks. The impl of server was initially a bit simple so that the server would be only one. The I started to implement it in my GH and I realized that I had problem with recognizing multiple `TCP/accepts` from the client. And suddenly simple idea became more complex. Then I read this your comment where you wrote that each fork should have its own server. I think your idea solved all my troubles with recognizing the ID of the fork on the other side, because no recognition needs to be performed since we implicitely expct only one fork. So and I think your approach is better. > It greatly simplifies the implementation and fits better to the existing architecture (which effectively has a dedicated stream for every fork). We already implemented this and did not find significant delays from binding that many `ServerSocket`s, finding that performance still improved dramatically over `stdin`/`stdout` communication (again, see [discussion here](https://github.com/gmu-swe/maven-surefire/pull/2) for a performance breakdown of what we have so far hacked out). > > How does this all sound to you, @Tibor17 (architecturally) and @Col-E (in terms of feasibility based on what you’ve already implemented)? I agree with you, and as I said, my practicle experiences forced me to do it as you have described above. > > I assume that the desired level of configuration is to allow for users to keep on using `stdin`/`stdout` instead of sockets, likely keeping existing behavior by default. The socket setup will be annoying to anyone with an OS that will bring up a GUI warning whenever a process tries to bind to a socket. I suppose that when the first server successfully binds to a socket, usually the next should bind too unless we are out of resources. Due to the forks start in parallel, we can shutdown the fork N-1 when the server N has failed and the N+1 would be ignored and the MOJO plugin should fail abruptly with reasonable error message on the console. Notice that the order is: + start server N and wait while binding to the socket + and then start the fork JVM still in the same thread where N is the fork ordinal in the thread pool. > > If it's an eventual goal, then it might also be worthwhile co-designing support for spawning `ForkedBooter`s on separate physical machines and using the socket for communication. I did some work for some clients who used a network file system to replicate the build environment across a cluster of machines. Assuming this is a typical practice, then it may be easy enough to just allow users to specify an IP address to bind to and advertise (or look up whatever `getLocalHostName` resolves to by default), and then also allow users to specify an arbitrary command string to prepend to the `ForkedBooter` process CommandLine (e.g. to specify an `ssh` command, resulting in the command running on a remote machine. Do you have any specific feature requestors who can provide a little more detail on their setups in order to help define the interface for this? I agree with you that this is the must but unfortunatelly I do not have any abstractions for remote resources dissipation simply because of lack of the time. So we need to have the conept, docu and all which is needed to cover this as well.
---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services
