I am trying to create a function that sends 100 call per second, and increase to 200 call per second every 60 second. The code is below
for (i = 1; i <= 240; i++) {
for (j = 0; j <= 100; j++) {
send_tcp();
}
sleep(1);
if(i %60 == 0) j=j+200;
else j = j*1;
}
The send_tcp() is basically just open a socket, and send TCP to a certain address. The problem is, for j = 100, it sends every second correctly. However, when j=300, it goes to 3 second to send 300 tcp, and it takes 10 second to send 500 tcp request. Basically when the j goes in number, I can not get j call/second.
I am thinking this is just a logic mistake, but I can not figure out how to send J call/second, no matter what number j is…
Would Appreciate for any response
–sorry for my bad english, basically I need to do j number of “send_tcp” / second. However, when J goes bigger, it appears that J number of “send_tcp” is not / second but becomes / 3 seconds or more..
Yes, there is a logic error. You are confusing your loop counter with the number of iterations you want. This is what you need to do instead: