Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6137773
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:46:08+00:00 2026-05-23T17:46:08+00:00

I need to split data evenly across n nodes in a distributed cache. The

  • 0

I need to split data evenly across n nodes in a distributed cache.

The following code will take a cache key and determine which Node to use:

public static int GetNodeIDByCacheKey(string key)
{
    return Math.Abs(key.GetHashCode()) % TotalNumberOfNodes();
}

Unfortunatly the code isn’t reliable across different machine instances.
In testing it seems it will sometimes return a different Node for the same key.

Any thoughts or ideas on getting something to work better?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T17:46:08+00:00Added an answer on May 23, 2026 at 5:46 pm

    You should not rely on the implementation of string‘s GetHashCode() other than the fact that strings of equal value will produce the same hash code – but what the particular value of the hash code will be is only required to be consistent as per the documentation for the current execution of an application – a different hash code can be returned if the application is run again.

    Also the implementation of GetHashCode might be different if you have different .NET CLR versions on the machines in question:

    The behavior of GetHashCode is dependent on its implementation, which
    might change from one version of the common language runtime to
    another. A reason why this might happen is to improve the performance
    of GetHashCode.

    Instead you could just define a consistent mapping from your string key to a numeric value which would allow you to bin your nodes consistently across restarts and machine boundaries, this i.e. could be achieved by converting the string into a byte array (i.e using Encoding.UTF8.GetBytes() ) and then converting the byte array to a number (either using a lossy conversion using just 64 bits or i.e using BigInteger)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a long string (multiple paragraphs) which I need to split into a
I need to split some info from a asterisk delimitted data. Data Format: NAME*ADRESS
I need to split a byte[]. I have some data in an original byte[]
Code: while True: data = irc.recv(4096) if data.find('PING') != -1: irc.send('PONG '+ data.split() [1]
I am wondering how will i proceed with the following requirement. I need to
I am reading a file which has source code. I need to append 2
I need split string by commas and spaces, but ignore the inside quotes, single
I need to split an flv file into chunks of the known size on
I need to split my string input into an array at the commas. Is
I need to split ABAP date like 20091101 --> "01", "november", "2009" The "01"

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.