0

Shotgun takes > 10s to connect when running in Maya

The Shotgun constructor takes over ten seconds to return when it's called from Maya 2012's script editor.

Where URL is 'mystudio.shotgunstudios.com' and KEY is the API key, an example of a call that takes over ten seconds to return would be:

print Shotgun(URL; 'shotQuery', KEY)

The same line takes less than one second to return if it's executed in a regular, not-embedded-in-Maya Python interpreter.

Why is this, and are there any workarounds?

11件のコメント

  • 0
    Avatar
    KP

    Dugan,

    We are in fact aware of this (specifically on Windows). We've been in touch with Autodesk about the situation as we try and figure out a resolution but it seems to be something related to Maya 2012. Let us know if this is on a different platform though.

    kp

  • 0
    Avatar
    phan

    Hey KP,

    We are experiencing the same issue, please let us know if there are any workarounds.

     

    Thanks

    Phaneendra

  • 0
    Avatar
    Mathieson Facer

    I have something that would maybe remedy this. It is an API wrapper that I am planning on releasing to the public soon. I think it is ready to go, but I have not had a chance to test it full-scale yet.

    The wrapper was designed to improve the speed of scripts, such as frame range fetchers, where all the script is doing is connecting to the Shotgun server, doing one query, and then finishes. I found sometimes that the Shotgun object would take a long time to initialize and really hold things up. The speed tests I was doing on my local box were returning speed improvements of 4x faster, on average. Of 1000 connection attempts via the regular Shotgun object creation method and then 1000 through the wrapper, I saw speed improvements range from 10-100x the speed (the slowest through the wrapper was still 10 times faster than the fastest through creating a Shotgun object. Fastest of the wrapper was 100 times faster than the slowest through creating a Shotgun object).

    I can't guarantee that it will fix the issue with Maya, but it is worth a shot. Send me an email if you're interested. mathiesonfacer@gmail.com

  • 0
    Avatar
    phan

    Thanks Mathieson.

    I'd like to report to you shotgun guys that I'm having the same issue on Windows 64 bit  in Maya 2013 as well.

    ---Phaneendra

  • 0
    Avatar
    Marc Dubrois

    On my side i tried the same test on :

    - python.exe interpreter classic (python.org v2.7.2). Result : 1.8 seconds

    - mayapy.exe interpreter (Maya 2012 x64 bin directory) Result : 2.5 seconds

    - Maya Script Editor (Maya 2012 x64)  Result : 38 seconds (first time) and after 2 seconds

  • 0
    Avatar
    Mathieson Facer

    Thought I would update this thread with my latest findings with regards to this. I did a lot of testing and backtracking through the Shotgun API. The problem is not actually with the Shotgun API itself, but rather a builtin function of Python that conflicts with Autodesk products. I have seen the slowdown in Maya 2012 and 3DS Max 2012 using Blur's Python plugin. The issue has to do with the wrap_socket function inside of the Python built-in ssl module. I was able to set up a test scenario without even importing the Shotgun API and just calling this function with a socket I created instead and was able to re-create the slowdown. So, the ball is in Autodesk's court on this it seems.

    Also, I tested out the Shotgun API wrapper I was mentioning, and I've had good success with it (it still had a few issues the last time I posted). It lowered our query times from approximately 11 seconds down to under one second. I uploaded it to GitHub a few weeks ago, if you want to give it a try: https://github.com/Mathieson/DoubleBarrel Yes, it is called DoubleBarrel :P

    We are still hoping for a solution to the core problem of the slow down. We are hesitant to roll out my API wrapper company wide here because we have multiple studio locations in a drastically different time zones. The wrapper, if unable to connect to a DoubleBarrelServer, will fall back and attempt to do just a straight connection to Shotgun as a safety net. This way, it doesn't fully fail, just takes a bit longer. I was receiving consistent slowdown of 55 seconds on my box when doing a direct Shotgun query through 3DS Max. Our main software is 3DS Max, so this isn't a very good safety net for us. If we were only dealing with the 10 second wait time as a safety net, it wouldn't be as much of an issue.

    If you are wanting to give the wrapper a try and anything isn't clear from the example included in the GitHub repo, just shoot me an email.

  • 0
    Avatar
    Mathieson Facer

    Marc - I was using the mayapy.exe interpreter as well. After running...

    import maya.standalone

    maya.standalone.initialize()

    ... if you run the same code again you will notice a huge spike in the time it takes to run. I used a Timer object to time just the Shotgun query so the time it takes for the Maya standalone to initialize is not included in the calculation.

  • 0
    Avatar
    Marc Dubrois

    After Running

    import maya.standalone

    maya.standalone.initialize()

    - mayapy.exe interpreter (Maya 2012 x64 bin directory) Result : 9.5 seconds 

  • 0
    Avatar
    Matt Daw

    Howdy folks, I just sent the following to the shotgun-dev list... but adding the details here too:

    ====

    Howdy! Great news for developers who have integrated Shotgun with Maya on Windows. We had received several reports that connecting to Shotgun from Maya was taking an unreasonable amount of time, including this thread on our support site.

     

    We have also experienced the same problem in Tank as it makes a connection to Shotgun via our standard Python API. Unfortunately, we weren't able to find a workaround, and we struggled to find the root of the problem. We have been working with Autodesk to explore the best ways to integrate Tank with their suite of products, so we asked for their help to debug this performance issue.

     

    Mark Davies, Software Development Manager at Autodesk, did some hardcore debugging and came up with the answer. The version of the OpenSSL library that ships with Maya's Python interpreter uses the contents of the heap to help it generate secure random numbers. Here's a link to the relevant OpenSSL bug report. The bigger the heap, the longer this takes! The slowdown is compounded by a change in Windows 7, which is pretty nerdy, but if you're interested in the details check them out here.

     

    More recent versions of OpenSSL have addressed this issue by cutting off the heap walking process after one second. To get a fix out to our clients for current versions of Maya, Autodesk has kindly built an updated version of OpenSSL that you can patch into your Maya installation. In our testing, applying this patch reduced the connection time from 44 seconds to 1.7 seconds!

     

    To apply the patch, expand the appropriate version, and copy the _ssl.pyd file into your <Maya Location>\Python\DLLs folder. Please let us know via support if you have questions or concerns.

     

    Maya 2011 or Maya 2012 (64-bit): Maya2012.zip

     

    Maya 2013: Maya2013.zip

     

    A huge thank you to Mark, the Maya development team and Chris Vienneau for helping us out!

  • 0
    Avatar
    Trevor Rowland

    I run this from Maya's userSetup.py

    It creates a thread that connects to SG while Maya is loading, leaving a global connection for the life of the session.

    Cheers

     

    Trevor

     

    class ThreadedConnection(threading.Thread):
        def __init__(self):
            self.SERVER_PATH     = 'https://xxxxxshotgunstudio.com/'
            self.SCRIPT_NAME     = 'xxxxxxx'     
            self.SCRIPT_KEY      = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
            self.sg=None
            self.run()

        def run(self):
            try:
                print "Connecting to %s..." %(self.SERVER_PATH)
                self.sg = Shotgun(self.SERVER_PATH, self.SCRIPT_NAME, self.SCRIPT_KEY)
            except Exception, e:
                exc_type, exc_value, exc_traceback = sys.exc_info()
                print "Unable to connect to Shotgun server. "+str(e)
                return
        
        def __getitem__(self):
            return self.sg

  • 0
    Avatar
    James

    Trevor how the heck are you connecting to that thread from the applications though?

ログインしてコメントを残してください。