forked from danikf/tik4net
-
Notifications
You must be signed in to change notification settings - Fork 1
Maximizing performance
Ben Thompson edited this page Nov 19, 2017
·
2 revisions
When you call a blank Query() we ask the router to supply all records (of that type), and include all properties on those records. It's important to note though that the router does not keep all properties in memory. Some properties (typically the lesser used ones) may only be stored on disk. So retrieving those properties are relatively expensive. You should always specify the properties that you're interested in to remove unnecessary overheads:
var arps = link.Ip.Arp.Query(
new string[] { // Include only the required properties
nameof(IpArp.Id),
nameof(IpArp.MacAddress)
}
);Many MikroTik routers have 8, 16 or even 32 CPU cores. They're built to be able to handle a large number of parallel tasks. Why then call its API with one request at a time? You can choose your weapon here. Here's a dumb example of updating the comments on all static ARP entries in parallel.
var rnd = new Random();
using (var link = Link.Connect(Credentials.Current.Host, Credentials.Current.Username, Credentials.Current.Password)) {
var arps = link.Ip.Arp.Query(nameof(IpArp.Id), nameof(IpArp.MacAddress), nameof(IpArp.Dynamic));
Parallel.ForEach(arps, arp => {
if (!arp.Dynamic) {
arp.Comment = arp.MacAddress + " " + rnd.Next().ToString();
link.Ip.Arp.Update(arp);
}
});
}