Community discussions

MikroTik App
 
dana1975
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 94
Joined: Sat Jul 04, 2009 8:32 pm

script problem for load balancing

Tue Aug 04, 2009 5:28 pm

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]
 
User avatar
Chupaka
Forum Guru
Forum Guru
Posts: 8712
Joined: Mon Jun 19, 2006 11:15 pm
Location: Minsk, Belarus
Contact:

Re: script problem for load balancing

Tue Aug 04, 2009 10:49 pm

maybe you should better use PCC? ECMP from your example will fail on long-term connections (like ICQ, online games)
 
dana1975
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 94
Joined: Sat Jul 04, 2009 8:32 pm

Re: script problem for load balancing

Thu Aug 06, 2009 9:28 pm

chupaka if you can't solve the problem you want to change the question?
but thank you for your recommendation
 
User avatar
Chupaka
Forum Guru
Forum Guru
Posts: 8712
Joined: Mon Jun 19, 2006 11:15 pm
Location: Minsk, Belarus
Contact:

Re: script problem for load balancing

Thu Aug 06, 2009 10:48 pm

not "can't" but "don't want to fix a priori fully non-fixable configuration". I just want to advise much better solution available!
 
dana1975
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 94
Joined: Sat Jul 04, 2009 8:32 pm

Re: script problem for load balancing

Thu Aug 06, 2009 11:40 pm

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
 
User avatar
Chupaka
Forum Guru
Forum Guru
Posts: 8712
Joined: Mon Jun 19, 2006 11:15 pm
Location: Minsk, Belarus
Contact:

Re: script problem for load balancing

Fri Aug 07, 2009 12:59 pm

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]
 
User avatar
NetworkPro
Forum Guru
Forum Guru
Posts: 1376
Joined: Mon Jan 05, 2009 6:23 pm
Location: bit.ly/the-qos
Contact:

Re: script problem for load balancing

Fri Aug 14, 2009 1:52 pm

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 ?
Last edited by NetworkPro on Tue Dec 19, 2017 11:46 pm, edited 1 time in total.
 
dana1975
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 94
Joined: Sat Jul 04, 2009 8:32 pm

Re: script problem for load balancing

Fri Aug 14, 2009 5:13 pm

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
 
User avatar
Chupaka
Forum Guru
Forum Guru
Posts: 8712
Joined: Mon Jun 19, 2006 11:15 pm
Location: Minsk, Belarus
Contact:

Re: script problem for load balancing

Fri Aug 14, 2009 11:21 pm

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...
 
User avatar
NetworkPro
Forum Guru
Forum Guru
Posts: 1376
Joined: Mon Jan 05, 2009 6:23 pm
Location: bit.ly/the-qos
Contact:

Re: script problem for load balancing

Fri Aug 14, 2009 11:56 pm

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
Last edited by NetworkPro on Tue Dec 19, 2017 11:44 pm, edited 2 times in total.
 
User avatar
Chupaka
Forum Guru
Forum Guru
Posts: 8712
Joined: Mon Jun 19, 2006 11:15 pm
Location: Minsk, Belarus
Contact:

Re: script problem for load balancing

Sat Aug 15, 2009 12:19 am

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?..
 
dana1975
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 94
Joined: Sat Jul 04, 2009 8:32 pm

Re: script problem for load balancing

Sat Aug 15, 2009 1:24 am

and NetworkPRO what'us about my script my friend ?
 
User avatar
NetworkPro
Forum Guru
Forum Guru
Posts: 1376
Joined: Mon Jan 05, 2009 6:23 pm
Location: bit.ly/the-qos
Contact:

Re: script problem for load balancing

Sat Aug 15, 2009 9:39 am

need to test it
Last edited by NetworkPro on Tue Dec 19, 2017 11:41 pm, edited 1 time in total.
 
User avatar
Chupaka
Forum Guru
Forum Guru
Posts: 8712
Joined: Mon Jun 19, 2006 11:15 pm
Location: Minsk, Belarus
Contact:

Re: script problem for load balancing

Sat Aug 15, 2009 7:12 pm

NetworkPro?..
 
User avatar
NetworkPro
Forum Guru
Forum Guru
Posts: 1376
Joined: Mon Jan 05, 2009 6:23 pm
Location: bit.ly/the-qos
Contact:

Re: script problem for load balancing

Sat Aug 15, 2009 8:03 pm

need to do a test and improvement
Last edited by NetworkPro on Tue Dec 19, 2017 11:41 pm, edited 1 time in total.
 
User avatar
Chupaka
Forum Guru
Forum Guru
Posts: 8712
Joined: Mon Jun 19, 2006 11:15 pm
Location: Minsk, Belarus
Contact:

Re: script problem for load balancing

Sat Aug 15, 2009 8:54 pm

but what exact rules do you use that are similar to the PCC rules?.. just wonder...
 
rboerom
just joined
Posts: 18
Joined: Mon Mar 17, 2008 3:30 pm

Re: script problem for load balancing

Thu Sep 10, 2009 5:55 am

add the dstination to an address list, and keep the nat to that address list with the same gateway
 
User avatar
NetworkPro
Forum Guru
Forum Guru
Posts: 1376
Joined: Mon Jan 05, 2009 6:23 pm
Location: bit.ly/the-qos
Contact:

Re: script problem for load balancing

Thu Sep 10, 2009 6:14 am

add the dstination to an address list, and keep the nat to that address list with the same gateway
Won't work.
 
User avatar
Chupaka
Forum Guru
Forum Guru
Posts: 8712
Joined: Mon Jun 19, 2006 11:15 pm
Location: Minsk, Belarus
Contact:

Re: script problem for load balancing

Thu Sep 10, 2009 5:09 pm

lists will be very huge if you have many users ;)
 
User avatar
NetworkPro
Forum Guru
Forum Guru
Posts: 1376
Joined: Mon Jan 05, 2009 6:23 pm
Location: bit.ly/the-qos
Contact:

Re: script problem for load balancing

Wed Dec 20, 2017 12:04 am

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.
 
User avatar
Chupaka
Forum Guru
Forum Guru
Posts: 8712
Joined: Mon Jun 19, 2006 11:15 pm
Location: Minsk, Belarus
Contact:

Re: script problem for load balancing

Wed Dec 20, 2017 8:24 am

8 years... =)

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

Who is online

Users browsing this forum: No registered users and 39 guests