What is the difference between Anycast and GeoDNS / GeoIP wrt HA?

417

Solution 1

The key benefit of GeoDNS is that it resolves the same name to different IP addresses based on the requester's IP address.

An Anycasted DNS server will return the same IP address regardless of who is doing the asking.

The two work at different network layers. Anycast is below GeoDNS since it has no sense of the requester IP address's location, just its place in the network diagram. What may be close to the DNS server may not be close to the resource being requested, and the Anycasted DNS server has no way to tell this.

GeoDNS uses a map of resource locations and performs logic to determine which of those resources is closest to a given requesting IP address, and then returns that IP address.

Unless you're colocating your DNS servers with your network resources, what's close to the DNS server won't always be close to the resource, so using Anycast as your data-locality method is less effective than straight up GeoDNS.

Solution 2

The BGP anycast aspect lets clients send a request to a given DNS server, and get that request sent to a nearby instance of the DNS server by virtue of the BGP routing table, hopefully getting a quick response.

However, a normal ol' DNS server that's geographically distributed and anycasted does not have the capability of responding to queries differently depending on the requesting client's location - this is the extra feature that those "Geo-DNS" services are providing for extra cost, allowing you to send clients to an instance of a service that's close to them.

The reason for this feature to exist is that BGP anycast works just fine for something stateless like DNS, where it's quick and dirty and needs no connection or session persistence, but for something like a web server, you want to stick instances all over the world and make sure a given client will stick to a specific instance - routing changes in the global BGP table mid-connection would break TCP connections, break web application sessions, and generally cause havoc; anycast is generally not used for web servers for this reason.

It's best to provide a user in county X with an IP for an instance in country X via DNS, which is what you're forking the cash over for with a Geo-DNS service.

Solution 3

Traditionally, you will have multiple DNS servers. A client will pick one at random, and ask it for your web server's IP address. This is good if the DNS server is close to the client, but bad if - as is often the case - the DNS server is far away from the client. Either way, the client will get the same IP address as an answer.

Anycast lets multiple servers respond to the same IP address. With anycast DNS, when a client tries to talk to your nameserver, the closest/fastest nameserver responds. This means that the client always gets a fast response to his DNS query. However, he'll still always get the same answer to his DNS query - the IP of your server. If your server is far away from the client, the client experience may not be optimal.

GeoDNS lets a DNS server respond with a different IP address, depending on where the client is. (Obviously this requires you to have multiple geographically distributed servers.) GeoDNS doesn't imply anycast, although typically you'd deploy both, so that a client ends up getting his DNS query answered by a geographically nearby DNS server, which then replies with the IP address of a geographically nearby web server.

Share:
417

Related videos on Youtube

Calum Mccrea
Author by

Calum Mccrea

Updated on September 18, 2022

Comments

  • Calum Mccrea
    Calum Mccrea almost 2 years

    I've searched a lot on how to communicate between fragments using SlidingTabLayout but haven't really got a good answer. (Although I am still quit new to android) I don't think I am too far from the solution - any help would be appreciated. Currently making a Pedometer project and I am trying to update a TextView in a SlidingTabLayout when a Step is detected. I have a StepListener Interface which is notified when a Step is detected, thought my Tabs could simply implement the interface and be notified thus incrementing my TextView as I go but having no success.

    I have tried this. When debuggin noticed that it reaches the stepsChanged Method in the Tab1 but then the App crashes. Any help is appreciated.

    My MainActivity....

    public class PedometerActivity extends ActionBarActivity implements StepListener, ServiceConnection {
    
        // applying buissness rules
        public static final int DAILY_GOAL = 10000;
    
        public float currentSteps;
    
    
        // Declaring Your View and Variables for the UI
        Toolbar toolbar;
        ViewPager pager;
        ViewPagerAdapter adapter;
        SlidingTabLayout tabs;
        CharSequence Titles[] = {"Home", "MyStats"};
        int Numboftabs = 2;
    
        //declaring Variables for acess to Db and Prefs
        UserLocalStore userLocalStore;
        SharedPreferences sharedPreferences;
    
        //declaring variables for the Step\Service
        private StepService mStepService = null;
    
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_pedometer);
            userLocalStore = new UserLocalStore(this);
    
            this.startStepService();
            this.bindStepService();
    
           /* sharedPreferences = getSharedPreferences("steps", Context.MODE_PRIVATE);
            SharedPreferences.Editor editor = sharedPreferences.edit();
            editor.putInt("currentSteps", numSteps); TODO remove this
            editor.commit();*/
    
            // Creating The Toolbar and setting it as the Toolbar for the activity
            toolbar = (Toolbar) findViewById(R.id.tool_bar);
            setSupportActionBar(toolbar);
    
    
            // Creating The ViewPagerAdapter and Passing Fragment Manager, Titles fot the Tabs and Number Of Tabs.
            adapter = new ViewPagerAdapter(getSupportFragmentManager(), Titles, Numboftabs);
    
            // Assigning ViewPager View and setting the adapter
            pager = (ViewPager) findViewById(R.id.pager);
            pager.setAdapter(adapter);
    
            // Assiging the Sliding Tab Layout View
            tabs = (SlidingTabLayout) findViewById(R.id.tabs);
            tabs.setDistributeEvenly(true); // To make the Tabs Fixed set this true, This makes the tabs Space Evenly in Available width
    
            // Setting Custom Color for the Scroll bar indicator of the Tab View
            tabs.setCustomTabColorizer(new SlidingTabLayout.TabColorizer() {
                @Override
                public int getIndicatorColor(int position) {
                    return getResources().getColor(R.color.tabsScrollColor);
                }
            });
    
    
            // Setting the ViewPager For the SlidingTabsLayout
            tabs.setViewPager(pager);
    
    
        }
    
        @Override
        public void stepsChanged(float numSteps) {
    
    
            //TODO /////
    
            for (int loop = 0; loop < adapter.getCount(); loop++) {
    
                if (adapter.getItem(0) instanceof StepListener) {
                    ((StepListener) adapter.getItem(0)).stepsChanged(numSteps);
                }//end of if
            }// end of for loop
    
        }
    
        public float getCurrentSteps(float currentSteps) {
    
            return currentSteps;
    
        }
    
    
        /**
         * currently unused....code
         *
         * @return
         */
        private boolean authenticate() {
            return userLocalStore.getUserLoggedIn();
        }
    
        @Override
        public boolean onCreateOptionsMenu(Menu menu) {
            // Inflate the menu; this adds items to the action bar if it is present.
            getMenuInflater().inflate(R.menu.menu_main, menu);
            return true;
        }
    
        @Override
        public boolean onOptionsItemSelected(MenuItem item) {
            // Handle action bar item clicks here. The action bar will
            // automatically handle clicks on the Home/Up button, so long
            // as you specify a parent activity in AndroidManifest.xml.
            int id = item.getItemId();
    
            //noinspection SimplifiableIfStatement
            if (id == R.id.action_settings) {
                return true;
            }
    
            return super.onOptionsItemSelected(item);
        }
    
    
        @Override
        protected void onPostResume() {
            super.onPostResume();
        }
    
        private void startStepService() {
            this.startService(new Intent(PedometerActivity.this, StepService.class));
    
        }
    
        /**
         * binds Pedometer Activity to the Service class
         * (I.e this service is going to communicate to this Activity)
         * must implement the ServiceConnection interface here
         */
        private void bindStepService() {
            this.bindService(new Intent(PedometerActivity.this, StepService.class),
                    this, Context.BIND_AUTO_CREATE + Context.BIND_DEBUG_UNBIND);
    
        }
    
        @Override
        public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
    
            mStepService = ((StepService.StepBinder) iBinder).getService();
            mStepService.registerStepListener(this);
    
        }
    
        @Override
        public void onServiceDisconnected(ComponentName componentName) {
    
        }
    
    
    }
    

    my Tab1....

    public class Tab1 extends Fragment implements StepListener {
    
        private static final int DAILY_GOAL = 10000;
    
        UserLocalStore userLocalStore;
    
        TextView tvStepValue;
    
        //float currentSteps;
    
        Database db;
    
        private Activity activity;
        private PieChart mPieChart;
        private PieModel sliceGoal, sliceCurrent;
    
        StepCounter mStepCounter;
    
    
        public Tab1() {
            // Required empty public constructor
        }
    
    
        @Override
        public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
            View v = inflater.inflate(R.layout.tab_1, container, false);
    
    
            tvStepValue = (TextView) v.findViewById(R.id.tvStepValue);
    
    
            // mPieChart = (PieChart) v.findViewById(R.id.piechart);
            // load data to PieCHart
    
            return v;
        }
    
        /**
         * method needed in Order to give the fragment a context to be used in conjunction with SharedPref/Database
         *
         * @param activity
         */
        @Override
        public void onAttach(Activity activity) {
            this.activity = activity;
            super.onAttach(activity);
        }
    
        private void loadData(View v) {
    
    
        }
    
    
        @Override
        public void stepsChanged(float numSteps) {
            tvStepValue.setText(String.valueOf(numSteps));
        }
    
    
    }
    

    my error message when the App crashes....

       09-10 17:21:29.748  26336-26336/com.example.calum.myslidingtablayout E/AndroidRuntime﹕ FATAL EXCEPTION: main
    java.lang.NullPointerException
            at com.example.calum.myslidingtablayout.Tab1.stepsChanged(Tab1.java:81)
            at com.example.calum.myslidingtablayout.PedometerActivity.stepsChanged(PedometerActivity.java:100)
            at com.example.calum.myslidingtablayout.StepCounter.onSensorChanged(StepCounter.java:50)
            at android.hardware.SystemSensorManager$ListenerDelegate$1.handleMessage(SystemSensorManager.java:250)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:137)
            at android.app.ActivityThread.main(ActivityThread.java:4867)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:511)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1007)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:774)
            at dalvik.system.NativeStart.main(Native Method)
    
  • Jonathan Adam
    Jonathan Adam over 12 years
    Spot on, I wasn't even considering the 2-stages of resolving the address (first finding the DNS server itself, then finding the targeted server). Thanks!