Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

What can be done for packet loss? #445

Closed
jeffRTC opened this issue Jun 9, 2021 · 3 comments
Closed

What can be done for packet loss? #445

jeffRTC opened this issue Jun 9, 2021 · 3 comments

Comments

@jeffRTC
Copy link

jeffRTC commented Jun 9, 2021

@mfontanini

Thank you building this abstraction and it really helped me to put together a prototype, but I'm now running into packet loss when capturing packets. I notice a lot of times packets like TCP SYN are missing, but I can find TCP ACK PSH packets perfectly when queried.

I'm using following configuration when setting up capturing loop ,

    // Capture only incoming packets
    config.set_direction(PCAP_D_IN);

    // Capture only TCP packets that goes to 80Port
    config.set_filter("tcp port 80");

    // Capture packets faster
    config.set_immediate_mode(true);

The only thing I do at the callback is pushing the parsed packet into MongoDB Database and I don't think this causing packet loss because it's pretty fast.

@mfontanini
Copy link
Owner

Writing into MongoDB for every packet you see is going to create a giant bottleneck. Your database may be fast but you're talking about thousands of packets a second, it will definitely not be able to handle that scale, especially if you're doing a single write per packet.

You'll need to create a queue, push your packets in there and process them asynchronously. Your packet sniffing thread should be as fast as possible, doing as little blocking operations as you can. If you write them in batches into mongo (e.g. use bulk operations), it may be able to handle the load, depending on how complex your documents are. Ideally you would aggregate the few bits of data you want and not write a single document per packet as that's a ton of data.

e.g. something like this

ProcessCicle

@jeffRTC
Copy link
Author

jeffRTC commented Jun 10, 2021

@mfontanini Thank you!

@jeffRTC jeffRTC closed this as completed Jun 10, 2021
@jeffRTC
Copy link
Author

jeffRTC commented Jul 20, 2021

@mfontanini I have one issue with periodically writing in batches because I want to query the packet data for IP real-time without extra delay. So, is there any problem with the consuming thread directly writing to MongoDB without batching?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants