Groophy
Groophy
Explore posts from servers
CC#
Created by Groophy on 1/25/2024 in #help
392,2 MB allocated in SOH
I'm not sure if ProcessRequestsAsync really works correctly, I haven't used lock before, I came across an example on the internet and it solved it for a short time, but I may have used it wrong or I don't think it really works async.
8 replies
CC#
Created by Groophy on 1/25/2024 in #help
392,2 MB allocated in SOH
It's absolutely memory leak
8 replies
CC#
Created by Groophy on 1/25/2024 in #help
392,2 MB allocated in SOH
No description
8 replies
CC#
Created by Groophy on 1/25/2024 in #help
392,2 MB allocated in SOH
Like able to see in photos, It tooks 40s which just totally 23mb. :/
8 replies
CC#
Created by Groophy on 1/25/2024 in #help
392,2 MB allocated in SOH
and it's gets so much allocate also after one time, can't handle requests.
8 replies
CC#
Created by Groophy on 1/25/2024 in #help
392,2 MB allocated in SOH
RequestPool.cs
public class RequestPool
{
private int _poolSize;
private Queue<IAsyncResult> _pool;
private Action<IAsyncResult> _action;
private List<Task> _workerTasks;

public RequestPool(int poolSize)
{
_poolSize = poolSize;
_pool = new Queue<IAsyncResult>();
_action = (_) => {};
_workerTasks = new List<Task>();

for (int i = 0; i < _poolSize; i++)
{
_workerTasks.Add(Task.Run(() => ProcessRequestsAsync(i)));
}
}

public void AddToPool(IAsyncResult request)
{
lock (_pool)
{
_pool.Enqueue(request);
}
}

public void SetAction(Action<IAsyncResult> action)
{
_action = action;
}

private async Task ProcessRequestsAsync(int i)
{
int taskCount = 0;
bool inProg = false;
while (true)
{
IAsyncResult request;

lock (_pool)
{
if (_pool.Count == 0 || inProg)
{
continue; // No requests to process, wait for new ones
}

request = _pool.Dequeue();
inProg = true;
}
Console.WriteLine($"Pool[{i}] took {taskCount}nd task.");

// Perform the action on the request
_action(request);

inProg = false;
taskCount++;
}
}
}
public class RequestPool
{
private int _poolSize;
private Queue<IAsyncResult> _pool;
private Action<IAsyncResult> _action;
private List<Task> _workerTasks;

public RequestPool(int poolSize)
{
_poolSize = poolSize;
_pool = new Queue<IAsyncResult>();
_action = (_) => {};
_workerTasks = new List<Task>();

for (int i = 0; i < _poolSize; i++)
{
_workerTasks.Add(Task.Run(() => ProcessRequestsAsync(i)));
}
}

public void AddToPool(IAsyncResult request)
{
lock (_pool)
{
_pool.Enqueue(request);
}
}

public void SetAction(Action<IAsyncResult> action)
{
_action = action;
}

private async Task ProcessRequestsAsync(int i)
{
int taskCount = 0;
bool inProg = false;
while (true)
{
IAsyncResult request;

lock (_pool)
{
if (_pool.Count == 0 || inProg)
{
continue; // No requests to process, wait for new ones
}

request = _pool.Dequeue();
inProg = true;
}
Console.WriteLine($"Pool[{i}] took {taskCount}nd task.");

// Perform the action on the request
_action(request);

inProg = false;
taskCount++;
}
}
}
8 replies
CC#
Created by Groophy on 1/25/2024 in #help
392,2 MB allocated in SOH
I'm gonna host some files which mostly dll files. And I get 200req/s so I made an pool system but It seems not work async and so much allocate, so after three days, I may need help. NetworkListener.cs
var listener = listenerList[i].listener;
var port = listenerList[i].port;
var requestPool = new RequestPool(10);

// call before action
action?.Invoke(port);

listener.Start();

await Task.Run(() =>
{
requestPool.SetAction(async callback =>
{
TcpClient client = listener.EndAcceptTcpClient(callback);

// Store endpoint
var endPoint = client.Client.LocalEndPoint;

// handle client request and response
await HandleClient(path, client);

// closes client if not closed.
if (GetState(endPoint) != TcpState.Closed)
client.Close();
});

while (true)
{
// If server was trying to stop.
if (listenFixer.isJobFixed) break;

// Accept to connect request
listener.BeginAcceptTcpClient(
async (callback)
=> requestPool.AddToPool(callback),
null);
}

listener.Stop();
listenFixer.SetState(State.Done);
});
var listener = listenerList[i].listener;
var port = listenerList[i].port;
var requestPool = new RequestPool(10);

// call before action
action?.Invoke(port);

listener.Start();

await Task.Run(() =>
{
requestPool.SetAction(async callback =>
{
TcpClient client = listener.EndAcceptTcpClient(callback);

// Store endpoint
var endPoint = client.Client.LocalEndPoint;

// handle client request and response
await HandleClient(path, client);

// closes client if not closed.
if (GetState(endPoint) != TcpState.Closed)
client.Close();
});

while (true)
{
// If server was trying to stop.
if (listenFixer.isJobFixed) break;

// Accept to connect request
listener.BeginAcceptTcpClient(
async (callback)
=> requestPool.AddToPool(callback),
null);
}

listener.Stop();
listenFixer.SetState(State.Done);
});
and it's gets so much allocate also after one time, can't handle requests.
8 replies
CC#
Created by Groophy on 1/13/2024 in #help
I can't understand
It's just my bad which 'Result<Thinker>' said and I gonna fixed
111 replies
CC#
Created by Groophy on 1/13/2024 in #help
I can't understand
it's not hard
111 replies
CC#
Created by Groophy on 1/13/2024 in #help
I can't understand
Maybe you are right, I will think about switching to PascalCase
111 replies
CC#
Created by Groophy on 1/13/2024 in #help
I can't understand
Done
111 replies
CC#
Created by Groophy on 1/13/2024 in #help
I can't understand
Thanks you I'll
111 replies
CC#
Created by Groophy on 1/13/2024 in #help
I can't understand
as now 😄
111 replies
CC#
Created by Groophy on 1/13/2024 in #help
I can't understand
Having such a standard As I said, a lot of things can be standard, but I think this is something that should be a developer choice.
111 replies
CC#
Created by Groophy on 1/13/2024 in #help
I can't understand
_
111 replies
CC#
Created by Groophy on 1/13/2024 in #help
I can't understand
I know why and what the standards are, it just doesn't make sense.
111 replies
CC#
Created by Groophy on 1/13/2024 in #help
I can't understand
uhm
111 replies