AWS Lambda Java Multithreading

Hello, I created an AWS Lambda function for a Kinesis stream for a batch size of 100, and I'm trying to execute it in a multi-threaded environment, but the problem is that in a multi-threaded environment it works very slowly, threaded. How can I share numbers with you: for 512 MB with a timeout of 60 seconds, the Lambda function performs 955 entries in 684 ms and 1031 entries in 435 ms, and for multi-threaded - 430 entries in 878808 ms and 433 entries in 893862 ms for (t .e. 512 MB and 60 seconds timeout)

Below is my Lambda function code that runs in multithreaded mode:

public String myHandler(final KinesisEvent kinesisEvent, final Context context) {
      Thread thread = new Thread(new Runnable(){

            //@Override
            public void run() {
                int singleRecord=0;
                long starttime=System.currentTimeMillis();
                //LambdaLogger lambdaLogger=context.getLogger();
                for(KinesisEventRecord rec : kinesisEvent.getRecords())
                {
                    singleRecord=0;
                    System.out.println("Kinesis Record inside is:"+new String(rec.getKinesis().getData().array()));
                    //count++;
                    singleRecord++;
                    //  System.out.println(new String(rec.getKinesis().getData().array()));
                }
                count=count+singleRecord;
                long endtime=System.currentTimeMillis();
                long totaltime = endtime-starttime;
                time=time+totaltime;
                System.out.println("Time required to execute single Lambda function for "+singleRecord+" records is"+" :: "+totaltime+" milliseconds");
                System.out.println("Total time required to execute Lambda function for "+count+" records is"+" :: "+time+" milliseconds");
            }
        });
        thread.start();
        return null;
    } //end of handler method

Lambda ? , ? , , , ?

+4
1

:

  • SDK lambdas, ()
  • Lambda , .
+1

Source: https://habr.com/ru/post/1619208/


All Articles