Inserts to temp table too slow

MemSQL Version: 6.7.15

This is a fairly common and simple use case. I am creating a temp table and inserting records to it. It’s taking ~2 mins to insert 1000 records. So to insert 150K records it would take around 5 hours. This is too slow. Any idea why it’s taking so much time?

CREATE TEMPORARY TABLE temp_KFcCwZvs ( PartitionId INT(20), Offset BIGINT(20), RowId VARCHAR(32), PositionType VARCHAR(22), Security VARCHAR(255), BusinessDate DATE )

INSERT INTO temp_KFcCwZvs (PartitionId, Offset, RowId, PositionType, Security, BusinessDate) VALUES ( ?, ?, ?, ?, ?, ? )

Relevant JAVA code:

final int batchSize = 1000;
int thisBatchSize = 0;
long bookmarkTime = System.currentTimeMillis();
try(final PreparedStatement stmt = connection.prepareStatement(insertTempTableSQL)) {
  logger.info("Got prepared statement. Time taken in seconds: " + ((System.currentTimeMillis()-bookmarkTime)/1000) );
  bookmarkTime = System.currentTimeMillis();
  for(T item: items.keySet()) {
    setInsertValues(stmt, item);
    stmt.addBatch();
    thisBatchSize++;
    if(thisBatchSize == batchSize) {
      stmt.executeBatch();
      logger.info("  Inserted " + thisBatchSize + " records. Total time taken for the batch: " +((System.currentTimeMillis()-bookmarkTime)/1000) );
      thisBatchSize=0;
      bookmarkTime = System.currentTimeMillis();
    }
  }
  stmt.executeBatch();


}catch (Exception ex) {
  throw new RuntimeException("Error while inserting temp table.", ex);
}

logs:
2019/08/16 09:01:37.351 [jsilink-launcher] INFO [ClassName] - Got prepared statement. Time taken in seconds: 0
2019/08/16 09:03:41.646 [jsilink-launcher] INFO [ClassName] - Inserted 1000 records. Total time taken for the batch: 124
2019/08/16 09:05:45.671 [jsilink-launcher] INFO [ClassName] - Inserted 1000 records. Total time taken for the batch: 124
2019/08/16 09:07:45.568 [jsilink-launcher] INFO [ClassName] - Inserted 1000 records. Total time taken for the batch: 119
2019/08/16 09:10:03.174 [jsilink-launcher] INFO [ClassName] - Inserted 1000 records. Total time taken for the batch: 137

Hello SBT,

Sorry for the very delayed response. Not sure if you already figured out why the Java code is running so slowly. Were you able to compare with a direct insert or load data into MemSQL? Here is a test we did directly on a MemSQL cluster.
Scenario 1: Inserting data into Temporary table through INSERT INTO query

The INSERT INTO query having 1000 records was run on MemSQL 7. The query run is attached below.
The Time taken to Run the query is 0.07 secs

Scenario 2: Inserting data into Temporary table through LOAD DATA query.

The LOAD DATA query was run for a csv file having 1000 records.

LOAD DATA INFILE ‘/dev/shm/CSV_INSERT_2.csv’ INTO TABLE Test.temp3 COLUMNS TERMINATED BY ‘,’ OPTIONALLY ENCLOSED BY ‘"’ LINES TERMINATED BY ‘\n’;

The Time taken to Run the query is 0.01 secs

We tested on a cluster of 1 Master 2 Aggregators and 4 leaves on AWS EC2 m4.2xlarge each.

If you can share your complete Java code, we can do a test and let you know the performance.

Thanks,

The images are not visible. Was it done in Java code or using some memsql client?

Are you using Google Chrome? For me it displays the images (png) just fine. It was run using native MySQL client connecting to MemSQL. No Java code.