IBM i Access Client Solutions

 View Only
Expand all | Collapse all

IBM i access ODBC for Linux low network performance

  • 1.  IBM i access ODBC for Linux low network performance

    Posted Fri January 05, 2024 02:05 AM
    Edited by Borui Li Fri January 05, 2024 03:02 AM

    Hi all. I'm looking for someone with a better knowledge about ODBC performance, who can help me in this situation.

    Environment:

    Centos7.9

    ibm-iaccess-1.1.0.27-1.0.x86_64

    unixODBC-2.3.1-14.el7.x86_64
    unixODBC-devel-2.3.1-14.el7.x86_64

    Scenario

    Connect to PUB400 and send a SQL like (SELECT DATA FROM TESTTAB LIMIT 200) 

    When I use embedded SQL, this query statment can return all data in 1 seconds, and the network speed can reach 100KB/s.

    But when I use ODBC to query, it may take more than 20 seconds, and the network speed only 10KB/s or more slow.

     Even I set attribute below:

        SQLSetStmtAttr(hstmt, SQL_ATTR_ROW_ARRAY_SIZE, (SQLPOINTER)20, 0); // get 20 rows on 1 SQLFetch(stmt);
        SQLSetStmtAttr(hstmt, SQL_ATTR_ROW_BIND_TYPE, (SQLPOINTER)SQL_BIND_BY_COLUMN, 0);
        SQLBindCol(hstmt, 1, SQL_C_BINARY, dbData, 1024, NULL);
    In odbc.ini
    [pub400]
    Description = System i Access ODBC Driver DSN for i5/OS
    Driver = IBM i Access ODBC Driver 64-bit
    System =
    UserID =
    Password =
    Naming = 0
    DefaultLibraries =
    Database =
    ConnectionType = 0
    CommitMode = 2
    ExtendedDynamic = 1
    DefaultPkgLibrary =
    DefaultPackage = A/DEFAULT(IBM),2,0,1,1,512
    AllowDataCompression = 1
    LibraryView = 0
    AllowUnsupportedChar = 0
    ForceTranslation = 0
    Trace = 0
    ExtendedColInfo = 1
    MULTICONTEXT = 1
    CONNECTTYPE = 1
    MaxFieldLength = 2097152
    QueryTimeout = 1



    ------------------------------
    BR L
    ------------------------------



  • 2.  RE: IBM i access ODBC for Linux low network performance

    IBM Champion
    Posted Mon January 08, 2024 07:16 AM

    I'm not really an ODBC guy.  In fact, I had to add a monthly calendar entry to remind me of certain oddities about it.  One of the things in that are these notes.  Maybe they apply to your situation?

    openquery is just MS SQL Server's technique for a "linked server".  Some sql engines always do it.  Some do it within setup or connection configuration.

    openquery:

    I assume you're trying to set up a linked server?

    https://www-01.ibm.com/support/docview.wss?uid=nas8N1014514

    Once you get connected, note the following:

    -- Pull all rows from the table(s) back to MS SQL server and do the where
    locally
    select * from LINKEDSVR.MYIBMI.MYLIB.MYTBL where locnbr = '00335';

    -- Sends the statement to linked server for processing
    select * from openquery(LINKEDSVR, 'select * from MYTBL where locnbr =
    ''00335''');

    --OPENQUERY() isn't just for SELECTS
    delete from openquery(LINKEDSVR, 'select * from MYTBL where locnbr =
    ''00335''');



    ------------------------------
    Robert Berendt IBMChampion
    ------------------------------



  • 3.  RE: IBM i access ODBC for Linux low network performance

    IBM Champion
    Posted Mon January 08, 2024 10:05 AM

    Check the block size setting in your config or connection string.  The default is quite small (256KB), which means the client has to run back and forth repeatedly, retrieving tiny bits of data at at time.

    https://www.ibm.com/docs/en/i/7.4?topic=details-connection-string-keywords



    ------------------------------
    Steven Riedmueller
    Certified IBM i Admin
    Speaker, Mentor, and Advocate
    ------------------------------



  • 4.  RE: IBM i access ODBC for Linux low network performance

    IBM Champion
    Posted Tue January 09, 2024 03:57 AM
    Edited by Satid Singkorapoom Tue January 09, 2024 04:00 AM

    I notice that the ODBC parameters  DefaultLibraries =  and DefaultPkgLibrary = are both left blank.  Please assign at least QGPL for both. Or if you want to isolate all system objects created by ODBC (such as SQL package objects) from Linux clients, just create and specify a library for both parameters.

    Please also add more parameters into your  obdc.ini   file :  

    BlockFetch  = 1

    BlockSizeKB   = 256 (or try 512 or even 1024)  which should be the same as Steven's suggestion.

    I use this as the reference :  ibm-iaccess for Linux ODBC Configuration at  https://www.ibm.com/support/pages/ibm-iaccess-linux-odbc-configuration  



    ------------------------------
    Chance favors only the prepared mind.
    -- Louis Pasteur
    ------------------------------
    Satid S.
    ------------------------------



  • 5.  RE: IBM i access ODBC for Linux low network performance

    Posted Tue January 09, 2024 09:32 AM

    Thank you for your reply.

    I have tried several configurations mentioned above, but none seem to have a clear effect. 

    It seems that even if configured to retrieve multiple rows at once, SQLFetch still runs in the same way as sending a request to the server once per row.

    here is my connect string: 

    driver={IBM i Access ODBC Driver 64-bit}; DSN=pub400; System=185.113.5.134; database=pub400; hostname=185.113.5.134; port=446; UID=LIBR; PWD=xxxxxxxxxxxx; AUTOCOMMIT=0; CONNECTTYPE=1; DBQ=LIBR1; DFTPKGLIB=LIBR1;QUERYTIMEOUT=1;BLOCKFETCH=1;MAXFIELDLEN=2097152;EXTCOLINFO=0;COMPRESSION=1;BLOCKSIZE=8192

    And my source code:

    And program out put:

    When fetch multiple rows

    network:

    When fetch one row //set SQL_ATTR_ROW_ARRAY_SIZE to 1

    network:

    It seems that fetch multiple rows at once is no different from fetch a single row at once



    ------------------------------
    BR L
    ------------------------------



  • 6.  RE: IBM i access ODBC for Linux low network performance

    IBM Champion
    Posted Wed January 10, 2024 01:31 AM

    By connecting to PUB400.com machine over the internet, you cannot expect much improvement when compared to using embedded SQL.   Once you have made sure your ODBC connection parameters are at its best, the next factor is in the internet connection such as the MTU size used by any routers involved (and we have no idea how many are involved in your connection) and there is not much you can now do but be content with what you get. 



    ------------------------------
    Chance favors only the prepared mind.
    -- Louis Pasteur
    ------------------------------
    Satid S.
    ------------------------------



  • 7.  RE: IBM i access ODBC for Linux low network performance

    IBM Champion
    Posted Wed January 10, 2024 01:51 AM

    It would be interesting to see how the isql utility performs.  Do a few test queries with that.

    It could come down to bandwidth as Satid mentioned.



    ------------------------------
    Richard Schoen
    Owner/President
    MobiGoGo LLC
    Minneapolis MN
    612-315-1745
    ------------------------------



  • 8.  RE: IBM i access ODBC for Linux low network performance

    Posted Wed January 10, 2024 04:32 AM

    odbc.ini:

    Do query:

    This query contains 200 rows and takes 45 seconds

    Bandwidth:

    Embeded SQL:

    Static SQL:

    EXEC SQL DECLARE clog CURSOR FOR SELECT CURRENT_TIMESTAMP, ENTRY_TIMESTAMP, SEQUENCE_NUMBER, JOURNAL_CODE, JOURNAL_ENTRY_TYPE, ENTRY_DATA, NULL_VALUE_INDICATORS, OBJECT, COMMIT_CYCLE FROM TABLE(QSYS2.DISPLAY_JOURNAL(:schema, :jnrname, STARTING_SEQUENCE => :curSeq1, ENDING_SEQUENCE => :curSeq1 + 200, STARTING_RECEIVER_LIBRARY => :rcvlib, STARTING_RECEIVER_NAME => :rcvname));

    Program out put:

    And bandwidth

    I think the problem that may lead to low query efficiency is network latency rather than bandwidth.

    So is there any way to reduce the number of interactions, similar to receive multiple rows at once.



    ------------------------------
    BR L
    ------------------------------



  • 9.  RE: IBM i access ODBC for Linux low network performance

    IBM Champion
    Posted Wed January 10, 2024 07:25 AM

    Try this:

    Create a table which contains only the rows you want.

    Then, using ODBC, select the rows from that table.

    Was it significantly faster?  If so, then I suspect my earlier question about 'linked server' comes into play.

    Basically, without a linked server, all rows from the table are downloaded to the client and the WHERE clause is executed locally.  So you have that download time to deal with.  With a linked server, the WHERE clause is executed on the server and only the rows which meet that where clause are returned to the client.  Much less data transmission.



    ------------------------------
    Robert Berendt IBMChampion
    ------------------------------



  • 10.  RE: IBM i access ODBC for Linux low network performance

    Posted Wed January 10, 2024 09:58 AM

    No, it still very slow.

    200 rows, isql use about 45 seconds

    Perhaps the query speed is related to network latency?

    And the RTT for communication with PUB400 is about 200 ms, so approximately 5 rows of records can be obtained per second?

    However, when fetching multiple rows (set SQL_ATTR_ROW_ARRAY_SIZE to 100), it seems that the number of interactions with the database is the same as when fetching a single row.



    ------------------------------
    BR L
    ------------------------------



  • 11.  RE: IBM i access ODBC for Linux low network performance

    IBM Champion
    Posted Thu January 11, 2024 06:19 AM
    Edited by Satid Singkorapoom Thu January 11, 2024 06:21 AM

    BR L

    >>>> And the RTT for communication with PUB400 is about 200 ms, so approximately 5 rows of records can be obtained per second? <<<<

    Using PING response time as a reference is NOT a sensible way. PING works on ICMP protocol which is different from TCP and IP that ODBC uses.

    >>>> However, when fetching multiple rows (set SQL_ATTR_ROW_ARRAY_SIZE to 100), it seems that the number of interactions with the database is the same as when fetching a single row. <<<<

    ODBC also has protocol exchanges between client and server that contributes handsomely to performance overhead when it goes on wide area network such as internet.  MTU size that is not large used by IP gateways along the way can be another negative performance factor.  In summary, you do not have much control over these external factors.



    ------------------------------
    Chance favors only the prepared mind.
    -- Louis Pasteur
    ------------------------------
    Satid S.
    ------------------------------



  • 12.  RE: IBM i access ODBC for Linux low network performance

    Posted Thu January 11, 2024 09:00 AM

    I have tried many methods, including using SQLBindCol interface and setting up SQL_ ATTR_ ROW_ SET_ SIZE, using BLOCKFETCH, BLOCKSIZE, and so on, it seems that only SQLBindCol can bring significant performance improvements(Compared to SQLGetData, the query time has been reduced by half), as SQLBindCol does indeed reduce the number of interactions with the database when obtaining LOB data, and interaction in such a network environment is expensive. 

    It seems that there is no other way to further reduce the number of interactions.

    Fortunately, the efficiency improvement of using multiple ODBC connections for parallel queries is very significant.

    Thanks for your help!



    ------------------------------
    BR L
    ------------------------------



  • 13.  RE: IBM i access ODBC for Linux low network performance

    IBM Champion
    Posted Thu January 11, 2024 02:00 AM

    Dear Robert

    >>>> Was it significantly faster?  If so, then I suspect my earlier question about 'linked server' comes into play. <<<<

    MS Linked Server runs only in Windows, This is the case of query running in Linux.



    ------------------------------
    Chance favors only the prepared mind.
    -- Louis Pasteur
    ------------------------------
    Satid S.
    ------------------------------