SAP / PyRFC

Asynchronous, non-blocking SAP NW RFC SDK bindings for Python
http://sap.github.io/PyRFC
Apache License 2.0
500 stars 132 forks source link

Does my code affect on call duration? #307

Closed albertalexandrov closed 1 year ago

albertalexandrov commented 1 year ago

Hi!

Thanks for the lib! It helped me a lot.

I have a question. I hope will help me. The question is about call duration. My code:

import pyrfc 

def get_sap_connection():
    conn_params = {
        'mshost': settings.SAP_MCHOST,
        'sysid': settings.SAP_SYSID,
        'group': settings.SAP_GROUP,
        'user': settings.SAP_USER,
        'passwd': settings.SAP_PASSWD
    }
    return pyrfc.Connection(**conn_params)

def call_fm(fm, **params): 
    conn = get_sap_connection()

    try:
        result = conn.call(fm, **params)
    finally:
        conn.close()

    return result

For some fm it tooks about 3-5 seconds. Some of params are date from and date to. I noticed that changing range between the them does not affect on call duration as one could expect.

I cannot understand where is the slowness happens: in my code, somewhere inside the lib or on our SAP instances. Could you please look at the code above again and say whether it written properly?

bsrdjan commented 1 year ago

Hello @albertalexandrov,

For some fm it tooks about 3-5 seconds

What is expected runtime?

The code looks good and without more details is hard to guess what is eventually slower then expected. The duration of the Python to ABAP call depends on ABAP function module run-time + network time + Python data conversions time. ABAP function module run-time may depend on input parameters which determine the number of selected records for example.

You can run the ABAP function module in ABAP system and compare that run-time with the run-time when called from Python with same parameters. But without more info it is not possible to give a generic answer.

albertalexandrov commented 1 year ago

@bsrdjan , thanks for your answer