Multiple Instances

Options
htaunay
edited July 2013 in Photon Server
I've been asked to create a second instance on my Photon server, specifically to be able to run unit tests involving all server related methods.
My question is which is the correct approach for this problem: keep using the same default port (5055) on the second instance, and access the different instances through my application(if that is possible); or do I just use different ports, and establish two different connections in my application?

Thanks in advance for any help!

Comments

  • Boris
    Options
    Either way is fine.
    For unit tests I would probably use a second process since untested code might have unwanted side effects .. for example if the server uses a lot of memory and you happen to run photon 32 bit your server might fail with an out of memory exception (2GB process limit).
    Other exception types might unload the test application and right now the only way to get it running again is to restart photon (we are working on solving that) - of course that would disconnect everyone.
    You can configure multiple instances with multiple configuration sections in the PhotonServer.config file, e.g. <Instance1>...</Instance1><Instance2>...</Instance2> and then start each instance per command line (the photon control starts Instance1 only).
    I believe there is a file named _run-Photon-as-application.start.cmd included that you can edit.
  • htaunay
    Options
    So I could just simply copy <Instance1>...</Instance1> to a following <Instance2>, change the UDP port from 5055 to, for example, 5056 in the CONFIG file, then update the *.cmd files to call both Instances, and finally restart the server, so that I could access the different instances/ports independently?
  • Boris
    Options
    100% correct.
  • htaunay
    Options
    First of all, thanks a lot Boris for all your help so far :D

    I've applied the modifications discussed previously, but when I run my tests using the 5056 port in a second instance I keep getting timeouts. I pretty sure that the second instance isn't even being launched since my log folder only has "Photon-Instance1-xxxxxxx" files, no Instance2's anywhere :?

    I've changed the following files to treat correctly the Instance2:
    _run-Photon-as-application.start
    _run-Photon-as-application.stop
    _service.install
    _service.start
    _service.stop
    _service.uninstall

    All of these just by simply adding another instance line (each in the specific formatting), e.g.:

    net start "Photon Socket Server: Instance1"
    net start "Photon Socket Server: Instance2"

    or

    start PhotoSocketServer.exe /debug Instance1
    start PhotoSocketServer.exe /debug Instance2

    Also, I noticed that the PhotonControl.exe.config file also had a specific mention to Instance1, as follows:

    <setting name="Instance" serializeAs="String">
    <value>Instance1</value>
    </setting>

    Since the setting name was a generic "Instance" I still am not sure how would be the correct way to configure two instances, but anyway, I changed it to a single "Instance2", and therefore I imagine it should have worked.

    Am I missing something? Should I change any TCPLIstners or TCPPolicyListners properties?
    The default Instance1 is still passing all tests.
    Sorry for the large post, but I hope it helps.
  • htaunay
    Options
    Update:

    Well, it isn't any surprise that my second instance never was loaded. For some reason Photon is simply ignoring all of its *.cmd scripts.
    First, I went from something like this:
    net start "Photon Socket Server: Instance1"
    
    -> net start "Photon Socket Server: Instance2", nothing...

    then I tried:
    net start "Photon Socket Server: abc"
    
    , and after restarting the server the tests still worked!

    for last, I wanted to check if the problem was just the parameters or the whole script:
    this should never work "Photon Socket Server: Instance1"
    
    , and all tests OK :?

    Does Photon keep any kind of cache for this sort of operation? I double checked all *.cmd's, even the ones in parallel folders (e.g. bin_Win32, bin_Win32_xp, etc) just to be sure different scripts weren't being called.
    On the other hand, the PhotonServer.config is ALWAYS correctly updated, when restarting the server.

    Anyway, after confronting this problem, I did another test just to make sure the non-default port would work. I changed all my configuration files to the default settings. All tests ran OK. Then I change my PhotonServer.config so that my default Instance1 would use the 5056 port, as well as my application to connect to such port. No good =/. Other tests were to change the application to connect to the default port, but leaving the server with the alternative port (5056). Still no good, as well as the vice-versa approach.

    Once again, there must be something I'm doing seriously wrong. Any help is welcome.
  • Boris
    Options
    "net start" is reserved for windows services, use it only if you install both photon instances as service (edit _service.install.cmd). All _service scripts are for services. Remember to execute them as admin.

    You use the _run scripts if you want to run photon as application. Again, you need admin rights.

    If photon starts successfully (see log folder, there is a Photon-Instance2 log file for Instance2) the only thing left to remember is to open the firewall for the new port that you use.

    Instead of using the scripts you can also just change the PhotonControl.config to Instance2. You will probably have to restart the photon control to load the changes. Photon control can only control one photon instance at a time.

    Hope that helps.
  • htaunay
    Options
    Yes it did \o/

    Your admin rights comment gave me the insight to solve the whole script running problem, even though it wasn't directly connected.
    And the firewall reminder also helped, it was correctly configured on the server, but not in the cloud manager :?

    However, now I'm confused over the independent instances subject.
    So I could just simply copy <Instance1>...</Instance1> to a following <Instance2>, change the UDP port from 5055 to, for example, 5056 in the CONFIG file, then update the *.cmd files to call both Instances, and finally restart the server, so that I could access the different instances/ports independently?

    100% correct.

    How can I access both instances independently if Photon cannot control more than one instance at a time?
    Now that all my setup is OK (thanks again!), I noticed that if a load both Instances, only the one that is loaded "works".
    E.g., if I load Instance1 then Instance2 (with different ports), tests only pass with the Instance1 port. Same vice-versa.
  • Boris
    Options
    htaunay wrote:
    How can I access both instances independently if Photon cannot control more than one instance at a time?
    Either create one script for each instance or change the photoncontrol.config (and restart photon control) every time you want to control the other photon instance.
    htaunay wrote:
    Now that all my setup is OK (thanks again!), I noticed that if a load both Instances, only the one that is loaded "works".
    E.g., if I load Instance1 then Instance2 (with different ports), tests only pass with the Instance1 port. Same vice-versa.
    Check the log files. If you just copied the default settings I guess that you are still loading tcp listeners that use the same port. just disable the ones that you don't need.
  • Tobias
    Options
    Just as note: Photon Control will learn to control more than just one instance in the future. It's planned but we don't have a schedule for it yet.
  • Hi there,

    Noticed the last post was in 2011, I was wondering has photon control learned to be capable of handling multiple instances of photon server now?
  • Partially - you can have multiple instances configured in Photon Control (like "Default" and "LoadBalancing"), but only one instance can be started from Photon Control simultaneously.

    So it's useful for development purposes, where you want to start either instance A or B - not so much for running / controlling two instances at the same time.