This is a static archive of our old Q&A Site. Please post any new questions and answers at ask.wireshark.org.

Lua - Efficient tables

0

I've written a small script, that logs some data about each connection.
Each connection is uniquely identified by IP1,port1,IP2,port2 - where direction doesn't matter.

For small dumps - the script works fine.
However,
as the dumps get bigger, and the number of unique connections follows - the table becomes very large - making the key look-up very long.

Can anyone suggest an efficient way/structure to handle/map unique connections.

asked 07 Dec '11, 09:18

Trevor's gravatar image

Trevor
41448
accept rate: 0%

I think the question is off-topic since it's a pure Lua question. General Lua programming questions should be asked in StackOverflow. The author of Lua (Roberto Ierusalimschy) wrote a gem on Lua performance tips, where he discusses how tables are implemented. It might shed a little light on the situation.

(07 Dec '11, 13:51) helloworld

One Answer:

0

I'm assuming that tables in lua are done with hashes, so it should be pretty efficient anyway. Maybe that's not the case. What I'm saying is, maybe it's your code, not tables. It's hard to tell witout seeing your code.

Each TCP connection has a unique number: tcp.stream. It's how the wireshark "Follow TCP stream" code is implemented. Try using that instead.

Aside: Before the existance of tcp.stream "Follow" used to use the same "unique" pattern. I don't think it was terribly efficient, but it's also not unique, even if it seems so in practice. A truly unique pattern involves the addition of a timestamp: IP1,port1,IP2,port2,time. tcp.stream implicitly incorporates a timestamp, making it truly unique.

You can always resort to segmenting the table. Example: you discover that most of your traffic is coming from 3 IPs in your local network. IP1 = 192.168.1.[123]. You could set up 4 tables, one for each IP, and one for all the other IPs.

answered 07 Dec '11, 13:38

studog's gravatar image

studog
16224
accept rate: 0%