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

  • SEARCH
  • Home
  • 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 8271237
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T06:47:22+00:00 2026-06-08T06:47:22+00:00

I have multiple different keys generated in the following format: 71 1 2, 69

  • 0

I have multiple different keys generated in the following format:

“71 1 2”, “69 2 3”, “68 5 6”, etc.

But, I find that most of these pairs go to same reducers.

Even if I implement a custom partitioner, the getNumPartitioner method, in which we use, hash_val % numReducers, mostly returns values, which group to few reducers loading them, whereas, other reducers remain free.
,
According to my understanding, we can use WritableComparator to sort the keys but cannot control keys to go to different reducers.

Is there a way to improve load balancing? Pls help.

I am attaching some code below to make my explanation clear:

String a = "71 1 2";
String b = "72 1 1";
String c = "70 1 3";

int hash_a = a.hashCode();
int hash_b = b.hashCode();
int hash_c = c.hashCode();

int part_a = hash_a % 10;
int part_b = hash_b % 10;
int part_c = hash_c % 10;

System.out.println("hash a: "+hash_a+" part_a: "+part_a);
System.out.println("hash b: "+hash_b+" part_b: "+part_b);
System.out.println("hash c: "+hash_c+" part_c: "+part_c);

Output:

hash a: 1620857277 part_a: 7
hash b: 1621780797 part_b: 7
hash c: 1619933757 part_c: 7

As we see different keys tend to map to same reducer.

Please help! Thanks!

  • 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-06-08T06:47:24+00:00Added an answer on June 8, 2026 at 6:47 am

    First of all, you cannot simply take the java modulus operation because sometimes hashcode might be negative and surely there isn’t something called a negative partition. So you might probably take an absolute value.

    Second here is a strong hash function which I found on the internet. Instead of the normal 32 bit int, it generates a 64bit long. Again this suffers from the problem of negative partitions too, but you can correct that for yourself.

    private static long[] byteTable;
    private static final long HSTART = 0xBB40E64DA205B064L;
    private static final long HMULT = 7664345821815920749L;
    
    private static long[] createLookupTable() {
    byteTable = new long[256];
    long h = 0x544B2FBACAAF1684L;
    for (int i = 0; i < 256; i++) {
      for (int j = 0; j < 31; j++) {
        h = (h >>> 7) ^ h;
        h = (h << 11) ^ h;
        h = (h >>> 10) ^ h;
      }
      byteTable[i] = h;
    }
    return byteTable;
    }
    public static long hash(String s) {
    byte[] data = s.getBytes();
    long h = HSTART;
    final long hmult = HMULT;
    final long[] ht = createLookupTable();
    for (int len = data.length, i = 0; i < len; i++) {
      h = (h * hmult) ^ ht[data[i] & 0xff];
    }
    return h;
    } 
    
    public static void main(String[] args) {
    
    String a = "71 1 2";
    String b = "72 1 1";
    String c = "70 1 3";
    
    long hash_a = hash(a);
    long hash_b = hash(b);
    long hash_c = hash(c);
    
    long part_a = hash_a % 10;
    long part_b = hash_b % 10;
    long part_c = hash_c % 10;
    
    System.out.println("hash a: "+hash_a+" part_a: "+part_a);
    System.out.println("hash b: "+hash_b+" part_b: "+part_b);
    System.out.println("hash c: "+hash_c+" part_c: "+part_c);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have multiple classes that will store similar data for different uses and I
If I have multiple textboxes which have different ID's but all id's start with
I need to have multiple keys in my client to access two different accounts
I have a need for a dictionary with multiple keys of 2 different types
Is it possible to have multiple inputs with multiple different mappers in Hadoop MapReduce?
I have map with multiple different colors markers with some info window. Everything works
I have multiple functions the do different animations to different parts of the HTML.
I have a Form with multiple different controls like ComboBox , TextBox and CheckBox
I have an issue wherein multiple different kinds of logins in a Tomcat backend
I have multiple nested movieclip in its own different movieclip, and i would like

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.