Skip to content

Instantly share code, notes, and snippets.

View arunsammit's full-sized avatar
🎃
Focusing

Arun Sammit Pandey arunsammit

🎃
Focusing
  • Indian Institute of Technology, Kharagpur
  • Kharagpur
View GitHub Profile
@arunsammit
arunsammit / MultipleAccessProtocols.py
Last active September 25, 2023 18:04
Simulation of Multiple Access Protocols: Aloha, Slotted Aloha, CSMA (1 persistent, non persistent, p persistent), CSMA-CD assuming poisson traffic
# %%
import matplotlib.pyplot as plt
import numpy as np
import math
from scipy.stats import binom
# %%
@arunsammit
arunsammit / Client.java
Last active September 24, 2021 08:50
simulation of ARQ (stop and wait ) data transfer protocol
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
public class Client {
public static void main(String[] args) throws IOException {
@arunsammit
arunsammit / Client.java
Created September 2, 2021 15:56
Server Client Communication with multiple client support in Java using sockets
import java.net.*;
import java.io.*;
public class Client {
//declearing socket and input output streams
private Socket socket = null;
ObjectOutputStream dout;
ObjectInputStream din;
// constructor to put ip address and port

QEats Module-6

Key Takeaways

  1. Always try to figure out if a code that is crashing on very big environment (ie for this case on 100+ asynchronous connection requests) also fails on a much smaller sized environment (ie for this case on 5+ synchronous connection request)
  2. Try to determine whether you can successfully reproduce the crash on every run of server/code
  3. If the issue can be successfully reproduced with small number of requests on every run of server that means there is issue with the normal flow of the code
  4. If the issue can't be reproduced on every run of server and/or on small sized sequential requests then it means that some part of code is throwing an exception which is inhibiting the normal flow of code.

Elaborate/Exact steps used for debugging

QEats Module-8

Optimum number of threads

I found out that 2 threads are optimum in this case. I tried playing around with number of threads using the variables

numThreads = 2
executor.setCorePoolSize(numThreads);
executor.setMaxPoolSize(numThreads);

When I kept the numThreads to 4, (maybe due to i/o bottle neck or due to number of cores in my pc being 2), the response time was worse compared to the synchronous code. keeping it as 2 made the asynchronous implementation fast enough to beat get lower response time compared t o the synchronous case