Page 1 of 1

script problem for load balancing

Posted: Tue Aug 04, 2009 5:28 pm
by dana1975
what's the problem of this script at end for load balancing? it's not work
# name of interface that should be monitored
# (edit to match your interface name)
:set mInterface2 ether2 ;
:set mInterface3 ether3 ;
:set mInterface4 ether4 ;

# routing mark name used for default route that should be updated
# (edit to match your routing mark name)
:set mRoutingMark SUBNET-LAN ;

/ip address ;
:set mGateway2 [/ip dhcp-client get [/ip dhcp-client find interface=$mInterface2] gateway]
:log info $mGateway2
:set mGateway3 [/ip dhcp-client get [/ip dhcp-client find interface=$mInterface3] gateway]
:log info $mGateway3
:set mGateway4 [/ip dhcp-client get [/ip dhcp-client find interface=$mInterface4] gateway]
:log info $mGateway4

/ip route  add dst-address=0.0.0.0/0 gateway=$mGateway2,$mGateway3,$mGateway4, routing-mark=$mRoutingMark;
and this line is working fine
/ip route  add dst-address=0.0.0.0/0 gateway=$mGateway2 routing-mark=$mRoutingMark;
[/code]

Re: script problem for load balancing

Posted: Tue Aug 04, 2009 10:49 pm
by Chupaka
maybe you should better use PCC? ECMP from your example will fail on long-term connections (like ICQ, online games)

Re: script problem for load balancing

Posted: Thu Aug 06, 2009 9:28 pm
by dana1975
chupaka if you can't solve the problem you want to change the question?
but thank you for your recommendation

Re: script problem for load balancing

Posted: Thu Aug 06, 2009 10:48 pm
by Chupaka
not "can't" but "don't want to fix a priori fully non-fixable configuration". I just want to advise much better solution available!

Re: script problem for load balancing

Posted: Thu Aug 06, 2009 11:40 pm
by dana1975
but this is only one script
and i have problem with this script
it's better that i test al the way and then i can choose the best way to do it
thank you so much for your recommendation for best solution
now I'm waiting to find my answer about the problem in script
regards

Re: script problem for load balancing

Posted: Fri Aug 07, 2009 12:59 pm
by Chupaka
PCQ is by definition better than ECMP, and script for it is easier, something like
/ip route set [find routing-mark="GW2"] gateway=[/ip dhcp-client get [find interface=ether2] gateway]
/ip route set [find routing-mark="GW3"] gateway=[/ip dhcp-client get [find interface=ether3] gateway]
/ip route set [find routing-mark="GW4"] gateway=[/ip dhcp-client get [find interface=ether4] gateway]

Re: script problem for load balancing

Posted: Fri Aug 14, 2009 1:52 pm
by NetworkPro
PCC will connect a client to a server over the same link every time, while ECMP (stabilized with magling and routing) will randomly choose nexthop for each new connection, therefore making downloading with download manager - faster.

You can paste the script into a terminal, to see where the syntax has an error. A comma after the last gateway ?

Re: script problem for load balancing

Posted: Fri Aug 14, 2009 5:13 pm
by dana1975
this is my configuration dear friend in ECMP
/ ip address 
add address=192.168.100.1/24 network=192.168.100.0 broadcast=192.168.100.255 interface=ether1 comment="" disabled=no 

/ ip dhcp-client 
add interface=ether2 add-default-route=yes use-peer-dns=yes use-peer-ntp=yes comment="" disabled=no 
add interface=ether3 add-default-route=yes use-peer-dns=yes use-peer-ntp=yes comment="" disabled=no 
add interface=ether4 add-default-route=yes use-peer-dns=yes use-peer-ntp=yes comment="" disabled=no 

/ ip firewall nat 
add chain=srcnat src-address=192.168.100.0/24 action=masquerade comment="" disabled=no 

/ ip firewall mangle 
add chain=prerouting src-address=192.168.100.0/24 action=mark-routing new-routing-mark=SUBNET-LAN passthrough=yes comment="" disabled=no 

/ ip route 
add dst-address=0.0.0.0/0 gateway=X.X.224.1,X.X.128.1,X.X.160.1 check-gateway=arp scope=255 target-scope=10 routing-mark=SUBNET-LAN comment="" disabled=no 
at the end of my configuration i added 3 gateway manually
i want to change this section with this script
:set mInterface2 ether2 ;
:set mInterface3 ether3 ;
:set mInterface4 ether4 ;

:set mRoutingMark SUBNET-LAN ;

/ip address ;
:set mGateway2 [/ip dhcp-client get [/ip dhcp-client find interface=$mInterface2] gateway]
:log info $mGateway2
:set mGateway3 [/ip dhcp-client get [/ip dhcp-client find interface=$mInterface3] gateway]
:log info $mGateway3
:set mGateway4 [/ip dhcp-client get [/ip dhcp-client find interface=$mInterface4] gateway]
:log info $mGateway4

/ip route  add dst-address=0.0.0.0/0 gateway=$mGateway2,$mGateway3,$mGateway4 routing-mark=$mRoutingMark;
ultimate line not working fine

Re: script problem for load balancing

Posted: Fri Aug 14, 2009 11:21 pm
by Chupaka
PCC will connect a client to a server over the same link every time, while ECMP (stabilized with magling and routing) will readnomly choose nexthop for each new connection, therefore making downloading with download manager - faster.
well, you tell about PCC with 'address' classifier. if you use 'address+port' classifier, it will distribute all conections to the same server via different gateways.

ECMP uses gateways in round-robin manner, but its weakness is routing cache (see http://wiki.mikrotik.com/wiki/Route#For ... ation_Base ). cache is being cleaned every xxx minutes (security reason?), so sometimes new gateway is selected different, so connection having been broken...

Re: script problem for load balancing

Posted: Fri Aug 14, 2009 11:56 pm
by NetworkPro
ECMP will break connections each ~10 minutes , when routing table flushing occurs

I can avoid it, using my own config similar to PCC

Improved results with PCC for lower ports and ECMP for higher ports

I made a WiKi article

Re: script problem for load balancing

Posted: Sat Aug 15, 2009 12:19 am
by Chupaka
routing rules that are similar to the PCC rules
maybe you'll share your solution? ;)
In my opinion the best load balance is PCC for lower ports and ECMP for higher ports >:]
mmm... ports?..

Re: script problem for load balancing

Posted: Sat Aug 15, 2009 1:24 am
by dana1975
and NetworkPRO what'us about my script my friend ?

Re: script problem for load balancing

Posted: Sat Aug 15, 2009 9:39 am
by NetworkPro
need to test it

Re: script problem for load balancing

Posted: Sat Aug 15, 2009 7:12 pm
by Chupaka
NetworkPro?..

Re: script problem for load balancing

Posted: Sat Aug 15, 2009 8:03 pm
by NetworkPro
need to do a test and improvement

Re: script problem for load balancing

Posted: Sat Aug 15, 2009 8:54 pm
by Chupaka
but what exact rules do you use that are similar to the PCC rules?.. just wonder...

Re: script problem for load balancing

Posted: Thu Sep 10, 2009 5:55 am
by rboerom
add the dstination to an address list, and keep the nat to that address list with the same gateway

Re: script problem for load balancing

Posted: Thu Sep 10, 2009 6:14 am
by NetworkPro
add the dstination to an address list, and keep the nat to that address list with the same gateway
Won't work.

Re: script problem for load balancing

Posted: Thu Sep 10, 2009 5:09 pm
by Chupaka
lists will be very huge if you have many users ;)

Re: script problem for load balancing

Posted: Wed Dec 20, 2017 12:04 am
by NetworkPro
but what exact rules do you use that are similar to the PCC rules?.. just wonder...
1. Let ECMP route the first packet of a connection randomly
2. Mark connection based on outgoing interface, after ECMP has done it's randomness
3. Mark routing to force the packets to use the specific route even after route flush occurs.

Re: script problem for load balancing

Posted: Wed Dec 20, 2017 8:24 am
by Chupaka
8 years... =)

IIRC, we discussed that ECMP+Marking in Skype. Nostalgia :)