package cloudSimulator;

import cloudSimulator.dao.HttpRequestOpperations;
import cloudSimulator.dto.RequestDetails;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Comparator;

@SpringBootApplication
public class Client implements CommandLineRunner {


    @Autowired
    private HttpRequestOpperations httpRequestOpperations;


    public static void main (String[] args) {
        SpringApplication.run(Client.class, args);
    }


    @Override
    public void run(String... strings) throws Exception {
        httpRequestOpperations.deleteAll();
        Files.walk(Paths.get("traces"))
                .filter(Files::isRegularFile)           // only consider files
                .filter(filePath -> filePath.toString().contains("traces_"))    // only files that contain traces in name
                .sorted(Comparator.naturalOrder())      // sort file name
                .forEach(filePath -> {                  // for each file
                    System.out.println(filePath);
                    try {
                        Files.lines(Paths.get(filePath.toString()), Charset.forName("Cp1252"))  // Open file and read lines
                                .map(line -> line.split("\\s+")[1])     // extract the second record from the file
                                .map(line -> Double.parseDouble(line))
                                .forEach(line -> count(line));
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
        });

        System.out.println("cloudSimulator.dao.HttpRequestOpperations time outed " + requestsTimeout);
        System.out.println("Average response time is: " + totalDelay / counter);
    }

    private int FACTOR = 10; // 1 = 1 sec; 10 = 1/10 sec
    private long REQUESTS_SECOND = 3000 / FACTOR;
    private double TIME_INTERVAL = 1.0 / FACTOR;
    private  double time = -1;
    private long requestCounter = REQUESTS_SECOND;
    private long requestsTimeout = 0;
    private long counter;
    private double totalDelay = 0;
    private double delay = 0;

    public void count(double requestTime) {
        if (time < 0) {
            time = Math.ceil(requestTime * FACTOR ) / FACTOR;
            //time = (long)requestTime;
        }

        if (requestTime + 5 >= time) {
            requestCounter--;
            counter++;
            delay = time - requestTime;
            totalDelay += delay;
            httpRequestOpperations.save(new RequestDetails(0, delay));
        }
        else {
            requestsTimeout++;
        }


        if (requestCounter == 0 || requestTime >= time) {
            time += TIME_INTERVAL;
            requestCounter = REQUESTS_SECOND;
        }
    }
}

@@ -1860,40 +1860,9 @@
 ln(%22
-cloudSimulator.dao.HttpRequestOp
+O
 pera
@@ -1971,17 +1971,24 @@
 Delay / 
-c
+requestC
 ounter);
@@ -2011,232 +2011,25 @@
 ate 
-int FACTOR = 10; // 1 = 1 sec; 10 = 1/10 sec%0A    private long REQUESTS_SECOND = 3000 / FACTOR;%0A    private double TIME_INTERVAL = 1.0 / FACTOR;%0A    private  double time = -1;%0A    private long requestCounter = REQUESTS_SECOND
+ double time = -1
 ;%0A  
@@ -2081,17 +2081,24 @@
 te long 
-c
+requestC
 ounter;%0A
@@ -2163,16 +2163,65 @@
 y = 0;%0A%0A
+    private double timePerRequest = 1.0 / 1000;%0A%0A
     publ
@@ -2303,50 +2303,66 @@
 e = 
-Math.ceil(requestTime * FACTOR ) / FACTOR;
+requestTime;%0A        %7D%0A%0A        if (requestTime %3E= time) %7B
 %0A   
@@ -2374,23 +2374,15 @@
     
-//
 time = 
-(long)
 requ
@@ -2456,25 +2456,32 @@
     
-requestCounter--;
+time += timePerRequest;%0A
 %0A   
@@ -2489,17 +2489,24 @@
         
-c
+requestC
 ounter++
@@ -2647,24 +2647,25 @@
 0, delay));%0A
+%0A
         %7D%0A  
@@ -2723,158 +2723,8 @@
  %7D%0A%0A
-%0A        if (requestCounter == 0 %7C%7C requestTime %3E= time) %7B%0A            time += TIME_INTERVAL;%0A            requestCounter = REQUESTS_SECOND;%0A        %7D%0A
     

Remove the notion of inserts per second and replace it with time per insert. The logic is greatly simplified because only the notion of time is used.