You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@zookeeper.apache.org by "Stephen Tyree (JIRA)" <ji...@apache.org> on 2011/03/15 13:49:29 UTC
[jira] Created: (ZOOKEEPER-1018) The connection permutation in
get_addrs uses a weak and inefficient shuffle
The connection permutation in get_addrs uses a weak and inefficient shuffle
---------------------------------------------------------------------------
Key: ZOOKEEPER-1018
URL: https://issues.apache.org/jira/browse/ZOOKEEPER-1018
Project: ZooKeeper
Issue Type: Improvement
Components: c client
Affects Versions: 3.3.2
Reporter: Stephen Tyree
Priority: Minor
After determining all of the addresses in the get_addrs function in the C client, the connection is permuted using the following code:
setup_random();
/* Permute */
for(i = 0; i < zh->addrs_count; i++) {
struct sockaddr_storage *s1 = zh->addrs + random()%zh->addrs_count;
struct sockaddr_storage *s2 = zh->addrs + random()%zh->addrs_count;
if (s1 != s2) {
struct sockaddr_storage t = *s1;
*s1 = *s2;
*s2 = t;
}
}
Not only does this shuffle produce an uneven permutation, but it is half as efficient as the Fisher-Yates shuffle which produces an unbiased one. It seems like it would be a simple fix to increase the randomness and efficiency of the shuffle by switching over to using Fisher-Yates.
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira
[jira] [Commented] (ZOOKEEPER-1018) The connection permutation in
get_addrs uses a weak and inefficient shuffle
Posted by "Mahadev konar (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/ZOOKEEPER-1018?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13011917#comment-13011917 ]
Mahadev konar commented on ZOOKEEPER-1018:
------------------------------------------
+1 looks good.
pat, since the test passes now and is fixed, do you think we need another test case or should this suffice?
> The connection permutation in get_addrs uses a weak and inefficient shuffle
> ---------------------------------------------------------------------------
>
> Key: ZOOKEEPER-1018
> URL: https://issues.apache.org/jira/browse/ZOOKEEPER-1018
> Project: ZooKeeper
> Issue Type: Improvement
> Components: c client
> Affects Versions: 3.3.2
> Reporter: Stephen Tyree
> Assignee: Stephen Tyree
> Priority: Minor
> Fix For: 3.4.0
>
> Attachments: ZOOKEEPER-1018.patch
>
> Original Estimate: 2h
> Remaining Estimate: 2h
>
> After determining all of the addresses in the get_addrs function in the C client, the connection is permuted using the following code:
> setup_random();
> /* Permute */
> for(i = 0; i < zh->addrs_count; i++) {
> struct sockaddr_storage *s1 = zh->addrs + random()%zh->addrs_count;
> struct sockaddr_storage *s2 = zh->addrs + random()%zh->addrs_count;
> if (s1 != s2) {
> struct sockaddr_storage t = *s1;
> *s1 = *s2;
> *s2 = t;
> }
> }
> Not only does this shuffle produce an uneven permutation, but it is half as efficient as the Fisher-Yates shuffle which produces an unbiased one. It seems like it would be a simple fix to increase the randomness and efficiency of the shuffle by switching over to using Fisher-Yates.
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira
[jira] [Updated] (ZOOKEEPER-1018) The connection permutation in
get_addrs uses a weak and inefficient shuffle
Posted by "Mahadev konar (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/ZOOKEEPER-1018?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Mahadev konar updated ZOOKEEPER-1018:
-------------------------------------
Fix Version/s: 3.4.0
> The connection permutation in get_addrs uses a weak and inefficient shuffle
> ---------------------------------------------------------------------------
>
> Key: ZOOKEEPER-1018
> URL: https://issues.apache.org/jira/browse/ZOOKEEPER-1018
> Project: ZooKeeper
> Issue Type: Improvement
> Components: c client
> Affects Versions: 3.3.2
> Reporter: Stephen Tyree
> Assignee: Stephen Tyree
> Priority: Minor
> Fix For: 3.4.0
>
> Attachments: ZOOKEEPER-1018.patch
>
> Original Estimate: 2h
> Remaining Estimate: 2h
>
> After determining all of the addresses in the get_addrs function in the C client, the connection is permuted using the following code:
> setup_random();
> /* Permute */
> for(i = 0; i < zh->addrs_count; i++) {
> struct sockaddr_storage *s1 = zh->addrs + random()%zh->addrs_count;
> struct sockaddr_storage *s2 = zh->addrs + random()%zh->addrs_count;
> if (s1 != s2) {
> struct sockaddr_storage t = *s1;
> *s1 = *s2;
> *s2 = t;
> }
> }
> Not only does this shuffle produce an uneven permutation, but it is half as efficient as the Fisher-Yates shuffle which produces an unbiased one. It seems like it would be a simple fix to increase the randomness and efficiency of the shuffle by switching over to using Fisher-Yates.
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira
[jira] [Commented] (ZOOKEEPER-1018) The connection permutation in
get_addrs uses a weak and inefficient shuffle
Posted by "Hadoop QA (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/ZOOKEEPER-1018?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13015520#comment-13015520 ]
Hadoop QA commented on ZOOKEEPER-1018:
--------------------------------------
+1 overall. Here are the results of testing the latest attachment
http://issues.apache.org/jira/secure/attachment/12474749/ZOOKEEPER-1018.patch
against trunk revision 1087821.
+1 @author. The patch does not contain any @author tags.
+1 tests included. The patch appears to include 3 new or modified tests.
+1 javadoc. The javadoc tool did not generate any warning messages.
+1 javac. The applied patch does not increase the total number of javac compiler warnings.
+1 findbugs. The patch does not introduce any new Findbugs (version 1.3.9) warnings.
+1 release audit. The applied patch does not increase the total number of release audit warnings.
+1 core tests. The patch passed core unit tests.
+1 contrib tests. The patch passed contrib unit tests.
Test results: https://hudson.apache.org/hudson/job/PreCommit-ZOOKEEPER-Build/220//testReport/
Findbugs warnings: https://hudson.apache.org/hudson/job/PreCommit-ZOOKEEPER-Build/220//artifact/trunk/build/test/findbugs/newPatchFindbugsWarnings.html
Console output: https://hudson.apache.org/hudson/job/PreCommit-ZOOKEEPER-Build/220//console
This message is automatically generated.
> The connection permutation in get_addrs uses a weak and inefficient shuffle
> ---------------------------------------------------------------------------
>
> Key: ZOOKEEPER-1018
> URL: https://issues.apache.org/jira/browse/ZOOKEEPER-1018
> Project: ZooKeeper
> Issue Type: Improvement
> Components: c client
> Affects Versions: 3.3.2
> Reporter: Stephen Tyree
> Assignee: Stephen Tyree
> Priority: Minor
> Fix For: 3.4.0
>
> Attachments: ZOOKEEPER-1018.patch
>
> Original Estimate: 2h
> Remaining Estimate: 2h
>
> After determining all of the addresses in the get_addrs function in the C client, the connection is permuted using the following code:
> setup_random();
> /* Permute */
> for(i = 0; i < zh->addrs_count; i++) {
> struct sockaddr_storage *s1 = zh->addrs + random()%zh->addrs_count;
> struct sockaddr_storage *s2 = zh->addrs + random()%zh->addrs_count;
> if (s1 != s2) {
> struct sockaddr_storage t = *s1;
> *s1 = *s2;
> *s2 = t;
> }
> }
> Not only does this shuffle produce an uneven permutation, but it is half as efficient as the Fisher-Yates shuffle which produces an unbiased one. It seems like it would be a simple fix to increase the randomness and efficiency of the shuffle by switching over to using Fisher-Yates.
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira
[jira] Commented: (ZOOKEEPER-1018) The connection permutation in
get_addrs uses a weak and inefficient shuffle
Posted by "Patrick Hunt (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/ZOOKEEPER-1018?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13008817#comment-13008817 ]
Patrick Hunt commented on ZOOKEEPER-1018:
-----------------------------------------
Would be great to have new tests for this, not sure how to declare success/failure though as we don't want false failure indications... Any ideas?
> The connection permutation in get_addrs uses a weak and inefficient shuffle
> ---------------------------------------------------------------------------
>
> Key: ZOOKEEPER-1018
> URL: https://issues.apache.org/jira/browse/ZOOKEEPER-1018
> Project: ZooKeeper
> Issue Type: Improvement
> Components: c client
> Affects Versions: 3.3.2
> Reporter: Stephen Tyree
> Assignee: Stephen Tyree
> Priority: Minor
> Attachments: ZOOKEEPER-1018.patch
>
> Original Estimate: 2h
> Remaining Estimate: 2h
>
> After determining all of the addresses in the get_addrs function in the C client, the connection is permuted using the following code:
> setup_random();
> /* Permute */
> for(i = 0; i < zh->addrs_count; i++) {
> struct sockaddr_storage *s1 = zh->addrs + random()%zh->addrs_count;
> struct sockaddr_storage *s2 = zh->addrs + random()%zh->addrs_count;
> if (s1 != s2) {
> struct sockaddr_storage t = *s1;
> *s1 = *s2;
> *s2 = t;
> }
> }
> Not only does this shuffle produce an uneven permutation, but it is half as efficient as the Fisher-Yates shuffle which produces an unbiased one. It seems like it would be a simple fix to increase the randomness and efficiency of the shuffle by switching over to using Fisher-Yates.
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira
[jira] Assigned: (ZOOKEEPER-1018) The connection permutation in
get_addrs uses a weak and inefficient shuffle
Posted by "Patrick Hunt (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/ZOOKEEPER-1018?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Patrick Hunt reassigned ZOOKEEPER-1018:
---------------------------------------
Assignee: Stephen Tyree
> The connection permutation in get_addrs uses a weak and inefficient shuffle
> ---------------------------------------------------------------------------
>
> Key: ZOOKEEPER-1018
> URL: https://issues.apache.org/jira/browse/ZOOKEEPER-1018
> Project: ZooKeeper
> Issue Type: Improvement
> Components: c client
> Affects Versions: 3.3.2
> Reporter: Stephen Tyree
> Assignee: Stephen Tyree
> Priority: Minor
> Attachments: ZOOKEEPER-1018.patch
>
> Original Estimate: 2h
> Remaining Estimate: 2h
>
> After determining all of the addresses in the get_addrs function in the C client, the connection is permuted using the following code:
> setup_random();
> /* Permute */
> for(i = 0; i < zh->addrs_count; i++) {
> struct sockaddr_storage *s1 = zh->addrs + random()%zh->addrs_count;
> struct sockaddr_storage *s2 = zh->addrs + random()%zh->addrs_count;
> if (s1 != s2) {
> struct sockaddr_storage t = *s1;
> *s1 = *s2;
> *s2 = t;
> }
> }
> Not only does this shuffle produce an uneven permutation, but it is half as efficient as the Fisher-Yates shuffle which produces an unbiased one. It seems like it would be a simple fix to increase the randomness and efficiency of the shuffle by switching over to using Fisher-Yates.
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira
[jira] Updated: (ZOOKEEPER-1018) The connection permutation in
get_addrs uses a weak and inefficient shuffle
Posted by "Stephen Tyree (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/ZOOKEEPER-1018?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Stephen Tyree updated ZOOKEEPER-1018:
-------------------------------------
Attachment: ZOOKEEPER-1018.patch
> The connection permutation in get_addrs uses a weak and inefficient shuffle
> ---------------------------------------------------------------------------
>
> Key: ZOOKEEPER-1018
> URL: https://issues.apache.org/jira/browse/ZOOKEEPER-1018
> Project: ZooKeeper
> Issue Type: Improvement
> Components: c client
> Affects Versions: 3.3.2
> Reporter: Stephen Tyree
> Priority: Minor
> Attachments: ZOOKEEPER-1018.patch, ZOOKEEPER-1018.patch
>
> Original Estimate: 2h
> Remaining Estimate: 2h
>
> After determining all of the addresses in the get_addrs function in the C client, the connection is permuted using the following code:
> setup_random();
> /* Permute */
> for(i = 0; i < zh->addrs_count; i++) {
> struct sockaddr_storage *s1 = zh->addrs + random()%zh->addrs_count;
> struct sockaddr_storage *s2 = zh->addrs + random()%zh->addrs_count;
> if (s1 != s2) {
> struct sockaddr_storage t = *s1;
> *s1 = *s2;
> *s2 = t;
> }
> }
> Not only does this shuffle produce an uneven permutation, but it is half as efficient as the Fisher-Yates shuffle which produces an unbiased one. It seems like it would be a simple fix to increase the randomness and efficiency of the shuffle by switching over to using Fisher-Yates.
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira
[jira] Commented: (ZOOKEEPER-1018) The connection permutation in
get_addrs uses a weak and inefficient shuffle
Posted by "Hadoop QA (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/ZOOKEEPER-1018?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13007284#comment-13007284 ]
Hadoop QA commented on ZOOKEEPER-1018:
--------------------------------------
-1 overall. Here are the results of testing the latest attachment
http://issues.apache.org/jira/secure/attachment/12473695/ZOOKEEPER-1018.patch
against trunk revision 1081936.
+1 @author. The patch does not contain any @author tags.
-1 tests included. The patch doesn't appear to include any new or modified tests.
Please justify why no new tests are needed for this patch.
Also please list what manual steps were performed to verify this patch.
-1 patch. The patch command could not apply the patch.
Console output: https://hudson.apache.org/hudson/job/PreCommit-ZOOKEEPER-Build/190//console
This message is automatically generated.
> The connection permutation in get_addrs uses a weak and inefficient shuffle
> ---------------------------------------------------------------------------
>
> Key: ZOOKEEPER-1018
> URL: https://issues.apache.org/jira/browse/ZOOKEEPER-1018
> Project: ZooKeeper
> Issue Type: Improvement
> Components: c client
> Affects Versions: 3.3.2
> Reporter: Stephen Tyree
> Priority: Minor
> Attachments: ZOOKEEPER-1018.patch
>
> Original Estimate: 2h
> Remaining Estimate: 2h
>
> After determining all of the addresses in the get_addrs function in the C client, the connection is permuted using the following code:
> setup_random();
> /* Permute */
> for(i = 0; i < zh->addrs_count; i++) {
> struct sockaddr_storage *s1 = zh->addrs + random()%zh->addrs_count;
> struct sockaddr_storage *s2 = zh->addrs + random()%zh->addrs_count;
> if (s1 != s2) {
> struct sockaddr_storage t = *s1;
> *s1 = *s2;
> *s2 = t;
> }
> }
> Not only does this shuffle produce an uneven permutation, but it is half as efficient as the Fisher-Yates shuffle which produces an unbiased one. It seems like it would be a simple fix to increase the randomness and efficiency of the shuffle by switching over to using Fisher-Yates.
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira
[jira] Commented: (ZOOKEEPER-1018) The connection permutation in
get_addrs uses a weak and inefficient shuffle
Posted by "Stephen Tyree (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/ZOOKEEPER-1018?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13007304#comment-13007304 ]
Stephen Tyree commented on ZOOKEEPER-1018:
------------------------------------------
Is the problem that I didn't run 'svn diff' from the root? If so I'll do that and resubmit.
> The connection permutation in get_addrs uses a weak and inefficient shuffle
> ---------------------------------------------------------------------------
>
> Key: ZOOKEEPER-1018
> URL: https://issues.apache.org/jira/browse/ZOOKEEPER-1018
> Project: ZooKeeper
> Issue Type: Improvement
> Components: c client
> Affects Versions: 3.3.2
> Reporter: Stephen Tyree
> Priority: Minor
> Attachments: ZOOKEEPER-1018.patch
>
> Original Estimate: 2h
> Remaining Estimate: 2h
>
> After determining all of the addresses in the get_addrs function in the C client, the connection is permuted using the following code:
> setup_random();
> /* Permute */
> for(i = 0; i < zh->addrs_count; i++) {
> struct sockaddr_storage *s1 = zh->addrs + random()%zh->addrs_count;
> struct sockaddr_storage *s2 = zh->addrs + random()%zh->addrs_count;
> if (s1 != s2) {
> struct sockaddr_storage t = *s1;
> *s1 = *s2;
> *s2 = t;
> }
> }
> Not only does this shuffle produce an uneven permutation, but it is half as efficient as the Fisher-Yates shuffle which produces an unbiased one. It seems like it would be a simple fix to increase the randomness and efficiency of the shuffle by switching over to using Fisher-Yates.
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira
[jira] [Commented] (ZOOKEEPER-1018) The connection permutation in
get_addrs uses a weak and inefficient shuffle
Posted by "Stephen Tyree (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/ZOOKEEPER-1018?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13012985#comment-13012985 ]
Stephen Tyree commented on ZOOKEEPER-1018:
------------------------------------------
What is the status on this? Is adjusting the unit test for shuffling sufficient or is there more I need to do here?
> The connection permutation in get_addrs uses a weak and inefficient shuffle
> ---------------------------------------------------------------------------
>
> Key: ZOOKEEPER-1018
> URL: https://issues.apache.org/jira/browse/ZOOKEEPER-1018
> Project: ZooKeeper
> Issue Type: Improvement
> Components: c client
> Affects Versions: 3.3.2
> Reporter: Stephen Tyree
> Assignee: Stephen Tyree
> Priority: Minor
> Fix For: 3.4.0
>
> Attachments: ZOOKEEPER-1018.patch
>
> Original Estimate: 2h
> Remaining Estimate: 2h
>
> After determining all of the addresses in the get_addrs function in the C client, the connection is permuted using the following code:
> setup_random();
> /* Permute */
> for(i = 0; i < zh->addrs_count; i++) {
> struct sockaddr_storage *s1 = zh->addrs + random()%zh->addrs_count;
> struct sockaddr_storage *s2 = zh->addrs + random()%zh->addrs_count;
> if (s1 != s2) {
> struct sockaddr_storage t = *s1;
> *s1 = *s2;
> *s2 = t;
> }
> }
> Not only does this shuffle produce an uneven permutation, but it is half as efficient as the Fisher-Yates shuffle which produces an unbiased one. It seems like it would be a simple fix to increase the randomness and efficiency of the shuffle by switching over to using Fisher-Yates.
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira
[jira] [Commented] (ZOOKEEPER-1018) The connection permutation in
get_addrs uses a weak and inefficient shuffle
Posted by "Hudson (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/ZOOKEEPER-1018?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13015852#comment-13015852 ]
Hudson commented on ZOOKEEPER-1018:
-----------------------------------
Integrated in ZooKeeper-trunk #1144 (See [https://hudson.apache.org/hudson/job/ZooKeeper-trunk/1144/])
ZOOKEEPER-1018. The connection permutation in get_addrs uses a weak and inefficient shuffle
> The connection permutation in get_addrs uses a weak and inefficient shuffle
> ---------------------------------------------------------------------------
>
> Key: ZOOKEEPER-1018
> URL: https://issues.apache.org/jira/browse/ZOOKEEPER-1018
> Project: ZooKeeper
> Issue Type: Improvement
> Components: c client
> Affects Versions: 3.3.2
> Reporter: Stephen Tyree
> Assignee: Stephen Tyree
> Priority: Minor
> Fix For: 3.4.0
>
> Attachments: ZOOKEEPER-1018.patch
>
> Original Estimate: 2h
> Remaining Estimate: 2h
>
> After determining all of the addresses in the get_addrs function in the C client, the connection is permuted using the following code:
> setup_random();
> /* Permute */
> for(i = 0; i < zh->addrs_count; i++) {
> struct sockaddr_storage *s1 = zh->addrs + random()%zh->addrs_count;
> struct sockaddr_storage *s2 = zh->addrs + random()%zh->addrs_count;
> if (s1 != s2) {
> struct sockaddr_storage t = *s1;
> *s1 = *s2;
> *s2 = t;
> }
> }
> Not only does this shuffle produce an uneven permutation, but it is half as efficient as the Fisher-Yates shuffle which produces an unbiased one. It seems like it would be a simple fix to increase the randomness and efficiency of the shuffle by switching over to using Fisher-Yates.
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira
[jira] Commented: (ZOOKEEPER-1018) The connection permutation in
get_addrs uses a weak and inefficient shuffle
Posted by "Hadoop QA (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/ZOOKEEPER-1018?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13008821#comment-13008821 ]
Hadoop QA commented on ZOOKEEPER-1018:
--------------------------------------
-1 overall. Here are the results of testing the latest attachment
http://issues.apache.org/jira/secure/attachment/12473801/ZOOKEEPER-1018.patch
against trunk revision 1082362.
+1 @author. The patch does not contain any @author tags.
-1 tests included. The patch doesn't appear to include any new or modified tests.
Please justify why no new tests are needed for this patch.
Also please list what manual steps were performed to verify this patch.
+1 javadoc. The javadoc tool did not generate any warning messages.
+1 javac. The applied patch does not increase the total number of javac compiler warnings.
+1 findbugs. The patch does not introduce any new Findbugs (version 1.3.9) warnings.
+1 release audit. The applied patch does not increase the total number of release audit warnings.
-1 core tests. The patch failed core unit tests.
+1 contrib tests. The patch passed contrib unit tests.
Test results: https://hudson.apache.org/hudson/job/PreCommit-ZOOKEEPER-Build/194//testReport/
Findbugs warnings: https://hudson.apache.org/hudson/job/PreCommit-ZOOKEEPER-Build/194//artifact/trunk/build/test/findbugs/newPatchFindbugsWarnings.html
Console output: https://hudson.apache.org/hudson/job/PreCommit-ZOOKEEPER-Build/194//console
This message is automatically generated.
> The connection permutation in get_addrs uses a weak and inefficient shuffle
> ---------------------------------------------------------------------------
>
> Key: ZOOKEEPER-1018
> URL: https://issues.apache.org/jira/browse/ZOOKEEPER-1018
> Project: ZooKeeper
> Issue Type: Improvement
> Components: c client
> Affects Versions: 3.3.2
> Reporter: Stephen Tyree
> Assignee: Stephen Tyree
> Priority: Minor
> Attachments: ZOOKEEPER-1018.patch
>
> Original Estimate: 2h
> Remaining Estimate: 2h
>
> After determining all of the addresses in the get_addrs function in the C client, the connection is permuted using the following code:
> setup_random();
> /* Permute */
> for(i = 0; i < zh->addrs_count; i++) {
> struct sockaddr_storage *s1 = zh->addrs + random()%zh->addrs_count;
> struct sockaddr_storage *s2 = zh->addrs + random()%zh->addrs_count;
> if (s1 != s2) {
> struct sockaddr_storage t = *s1;
> *s1 = *s2;
> *s2 = t;
> }
> }
> Not only does this shuffle produce an uneven permutation, but it is half as efficient as the Fisher-Yates shuffle which produces an unbiased one. It seems like it would be a simple fix to increase the randomness and efficiency of the shuffle by switching over to using Fisher-Yates.
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira
[jira] Commented: (ZOOKEEPER-1018) The connection permutation in
get_addrs uses a weak and inefficient shuffle
Posted by "Stephen Tyree (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/ZOOKEEPER-1018?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13007494#comment-13007494 ]
Stephen Tyree commented on ZOOKEEPER-1018:
------------------------------------------
Updated, this time taking the diff from the root directory.
> The connection permutation in get_addrs uses a weak and inefficient shuffle
> ---------------------------------------------------------------------------
>
> Key: ZOOKEEPER-1018
> URL: https://issues.apache.org/jira/browse/ZOOKEEPER-1018
> Project: ZooKeeper
> Issue Type: Improvement
> Components: c client
> Affects Versions: 3.3.2
> Reporter: Stephen Tyree
> Priority: Minor
> Attachments: ZOOKEEPER-1018.patch
>
> Original Estimate: 2h
> Remaining Estimate: 2h
>
> After determining all of the addresses in the get_addrs function in the C client, the connection is permuted using the following code:
> setup_random();
> /* Permute */
> for(i = 0; i < zh->addrs_count; i++) {
> struct sockaddr_storage *s1 = zh->addrs + random()%zh->addrs_count;
> struct sockaddr_storage *s2 = zh->addrs + random()%zh->addrs_count;
> if (s1 != s2) {
> struct sockaddr_storage t = *s1;
> *s1 = *s2;
> *s2 = t;
> }
> }
> Not only does this shuffle produce an uneven permutation, but it is half as efficient as the Fisher-Yates shuffle which produces an unbiased one. It seems like it would be a simple fix to increase the randomness and efficiency of the shuffle by switching over to using Fisher-Yates.
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira
[jira] Updated: (ZOOKEEPER-1018) The connection permutation in
get_addrs uses a weak and inefficient shuffle
Posted by "Stephen Tyree (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/ZOOKEEPER-1018?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Stephen Tyree updated ZOOKEEPER-1018:
-------------------------------------
Attachment: (was: ZOOKEEPER-1018.patch)
> The connection permutation in get_addrs uses a weak and inefficient shuffle
> ---------------------------------------------------------------------------
>
> Key: ZOOKEEPER-1018
> URL: https://issues.apache.org/jira/browse/ZOOKEEPER-1018
> Project: ZooKeeper
> Issue Type: Improvement
> Components: c client
> Affects Versions: 3.3.2
> Reporter: Stephen Tyree
> Priority: Minor
> Attachments: ZOOKEEPER-1018.patch
>
> Original Estimate: 2h
> Remaining Estimate: 2h
>
> After determining all of the addresses in the get_addrs function in the C client, the connection is permuted using the following code:
> setup_random();
> /* Permute */
> for(i = 0; i < zh->addrs_count; i++) {
> struct sockaddr_storage *s1 = zh->addrs + random()%zh->addrs_count;
> struct sockaddr_storage *s2 = zh->addrs + random()%zh->addrs_count;
> if (s1 != s2) {
> struct sockaddr_storage t = *s1;
> *s1 = *s2;
> *s2 = t;
> }
> }
> Not only does this shuffle produce an uneven permutation, but it is half as efficient as the Fisher-Yates shuffle which produces an unbiased one. It seems like it would be a simple fix to increase the randomness and efficiency of the shuffle by switching over to using Fisher-Yates.
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira
[jira] Commented: (ZOOKEEPER-1018) The connection permutation in
get_addrs uses a weak and inefficient shuffle
Posted by "Stephen Tyree (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/ZOOKEEPER-1018?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13006969#comment-13006969 ]
Stephen Tyree commented on ZOOKEEPER-1018:
------------------------------------------
Running 1000 times with the old way, I get the following distribution:
308 The connected host is: (address 1):2181
369 The connected host is: (address 2):2181
324 The connected host is: (address 3):2181
Running 1000 times with the new way, I get the following distribution:
333 The connected host is: (address 1):2181
325 The connected host is: (address 2):2181
343 The connected host is: (address 3):2181
Hardly scientific, but an indication that the new way is better or at the least as good.
> The connection permutation in get_addrs uses a weak and inefficient shuffle
> ---------------------------------------------------------------------------
>
> Key: ZOOKEEPER-1018
> URL: https://issues.apache.org/jira/browse/ZOOKEEPER-1018
> Project: ZooKeeper
> Issue Type: Improvement
> Components: c client
> Affects Versions: 3.3.2
> Reporter: Stephen Tyree
> Priority: Minor
> Attachments: zookeeper.c.patch
>
> Original Estimate: 2h
> Remaining Estimate: 2h
>
> After determining all of the addresses in the get_addrs function in the C client, the connection is permuted using the following code:
> setup_random();
> /* Permute */
> for(i = 0; i < zh->addrs_count; i++) {
> struct sockaddr_storage *s1 = zh->addrs + random()%zh->addrs_count;
> struct sockaddr_storage *s2 = zh->addrs + random()%zh->addrs_count;
> if (s1 != s2) {
> struct sockaddr_storage t = *s1;
> *s1 = *s2;
> *s2 = t;
> }
> }
> Not only does this shuffle produce an uneven permutation, but it is half as efficient as the Fisher-Yates shuffle which produces an unbiased one. It seems like it would be a simple fix to increase the randomness and efficiency of the shuffle by switching over to using Fisher-Yates.
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira
[jira] Commented: (ZOOKEEPER-1018) The connection permutation in
get_addrs uses a weak and inefficient shuffle
Posted by "Hadoop QA (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/ZOOKEEPER-1018?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13007505#comment-13007505 ]
Hadoop QA commented on ZOOKEEPER-1018:
--------------------------------------
-1 overall. Here are the results of testing the latest attachment
http://issues.apache.org/jira/secure/attachment/12473801/ZOOKEEPER-1018.patch
against trunk revision 1081936.
+1 @author. The patch does not contain any @author tags.
-1 tests included. The patch doesn't appear to include any new or modified tests.
Please justify why no new tests are needed for this patch.
Also please list what manual steps were performed to verify this patch.
+1 javadoc. The javadoc tool did not generate any warning messages.
+1 javac. The applied patch does not increase the total number of javac compiler warnings.
+1 findbugs. The patch does not introduce any new Findbugs (version 1.3.9) warnings.
+1 release audit. The applied patch does not increase the total number of release audit warnings.
-1 core tests. The patch failed core unit tests.
+1 contrib tests. The patch passed contrib unit tests.
Test results: https://hudson.apache.org/hudson/job/PreCommit-ZOOKEEPER-Build/192//testReport/
Findbugs warnings: https://hudson.apache.org/hudson/job/PreCommit-ZOOKEEPER-Build/192//artifact/trunk/build/test/findbugs/newPatchFindbugsWarnings.html
Console output: https://hudson.apache.org/hudson/job/PreCommit-ZOOKEEPER-Build/192//console
This message is automatically generated.
> The connection permutation in get_addrs uses a weak and inefficient shuffle
> ---------------------------------------------------------------------------
>
> Key: ZOOKEEPER-1018
> URL: https://issues.apache.org/jira/browse/ZOOKEEPER-1018
> Project: ZooKeeper
> Issue Type: Improvement
> Components: c client
> Affects Versions: 3.3.2
> Reporter: Stephen Tyree
> Priority: Minor
> Attachments: ZOOKEEPER-1018.patch
>
> Original Estimate: 2h
> Remaining Estimate: 2h
>
> After determining all of the addresses in the get_addrs function in the C client, the connection is permuted using the following code:
> setup_random();
> /* Permute */
> for(i = 0; i < zh->addrs_count; i++) {
> struct sockaddr_storage *s1 = zh->addrs + random()%zh->addrs_count;
> struct sockaddr_storage *s2 = zh->addrs + random()%zh->addrs_count;
> if (s1 != s2) {
> struct sockaddr_storage t = *s1;
> *s1 = *s2;
> *s2 = t;
> }
> }
> Not only does this shuffle produce an uneven permutation, but it is half as efficient as the Fisher-Yates shuffle which produces an unbiased one. It seems like it would be a simple fix to increase the randomness and efficiency of the shuffle by switching over to using Fisher-Yates.
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira
[jira] Commented: (ZOOKEEPER-1018) The connection permutation in
get_addrs uses a weak and inefficient shuffle
Posted by "Mahadev konar (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/ZOOKEEPER-1018?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13006967#comment-13006967 ]
Mahadev konar commented on ZOOKEEPER-1018:
------------------------------------------
stephen, please do.
> The connection permutation in get_addrs uses a weak and inefficient shuffle
> ---------------------------------------------------------------------------
>
> Key: ZOOKEEPER-1018
> URL: https://issues.apache.org/jira/browse/ZOOKEEPER-1018
> Project: ZooKeeper
> Issue Type: Improvement
> Components: c client
> Affects Versions: 3.3.2
> Reporter: Stephen Tyree
> Priority: Minor
> Attachments: zookeeper.c.patch
>
> Original Estimate: 2h
> Remaining Estimate: 2h
>
> After determining all of the addresses in the get_addrs function in the C client, the connection is permuted using the following code:
> setup_random();
> /* Permute */
> for(i = 0; i < zh->addrs_count; i++) {
> struct sockaddr_storage *s1 = zh->addrs + random()%zh->addrs_count;
> struct sockaddr_storage *s2 = zh->addrs + random()%zh->addrs_count;
> if (s1 != s2) {
> struct sockaddr_storage t = *s1;
> *s1 = *s2;
> *s2 = t;
> }
> }
> Not only does this shuffle produce an uneven permutation, but it is half as efficient as the Fisher-Yates shuffle which produces an unbiased one. It seems like it would be a simple fix to increase the randomness and efficiency of the shuffle by switching over to using Fisher-Yates.
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira
[jira] Updated: (ZOOKEEPER-1018) The connection permutation in
get_addrs uses a weak and inefficient shuffle
Posted by "Stephen Tyree (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/ZOOKEEPER-1018?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Stephen Tyree updated ZOOKEEPER-1018:
-------------------------------------
Attachment: ZOOKEEPER-1018.patch
Patch to implement the enhancement.
> The connection permutation in get_addrs uses a weak and inefficient shuffle
> ---------------------------------------------------------------------------
>
> Key: ZOOKEEPER-1018
> URL: https://issues.apache.org/jira/browse/ZOOKEEPER-1018
> Project: ZooKeeper
> Issue Type: Improvement
> Components: c client
> Affects Versions: 3.3.2
> Reporter: Stephen Tyree
> Priority: Minor
> Attachments: ZOOKEEPER-1018.patch, zookeeper.c.patch
>
> Original Estimate: 2h
> Remaining Estimate: 2h
>
> After determining all of the addresses in the get_addrs function in the C client, the connection is permuted using the following code:
> setup_random();
> /* Permute */
> for(i = 0; i < zh->addrs_count; i++) {
> struct sockaddr_storage *s1 = zh->addrs + random()%zh->addrs_count;
> struct sockaddr_storage *s2 = zh->addrs + random()%zh->addrs_count;
> if (s1 != s2) {
> struct sockaddr_storage t = *s1;
> *s1 = *s2;
> *s2 = t;
> }
> }
> Not only does this shuffle produce an uneven permutation, but it is half as efficient as the Fisher-Yates shuffle which produces an unbiased one. It seems like it would be a simple fix to increase the randomness and efficiency of the shuffle by switching over to using Fisher-Yates.
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira
[jira] [Updated] (ZOOKEEPER-1018) The connection permutation in
get_addrs uses a weak and inefficient shuffle
Posted by "Stephen Tyree (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/ZOOKEEPER-1018?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Stephen Tyree updated ZOOKEEPER-1018:
-------------------------------------
Attachment: ZOOKEEPER-1018.patch
The reason the unit tests failed was due to the change in how random numbers impacted the order of servers. The code for shuffling addresses is correct, and making everything work just required changing a few numbers in the Mock_random generator.
> The connection permutation in get_addrs uses a weak and inefficient shuffle
> ---------------------------------------------------------------------------
>
> Key: ZOOKEEPER-1018
> URL: https://issues.apache.org/jira/browse/ZOOKEEPER-1018
> Project: ZooKeeper
> Issue Type: Improvement
> Components: c client
> Affects Versions: 3.3.2
> Reporter: Stephen Tyree
> Assignee: Stephen Tyree
> Priority: Minor
> Attachments: ZOOKEEPER-1018.patch
>
> Original Estimate: 2h
> Remaining Estimate: 2h
>
> After determining all of the addresses in the get_addrs function in the C client, the connection is permuted using the following code:
> setup_random();
> /* Permute */
> for(i = 0; i < zh->addrs_count; i++) {
> struct sockaddr_storage *s1 = zh->addrs + random()%zh->addrs_count;
> struct sockaddr_storage *s2 = zh->addrs + random()%zh->addrs_count;
> if (s1 != s2) {
> struct sockaddr_storage t = *s1;
> *s1 = *s2;
> *s2 = t;
> }
> }
> Not only does this shuffle produce an uneven permutation, but it is half as efficient as the Fisher-Yates shuffle which produces an unbiased one. It seems like it would be a simple fix to increase the randomness and efficiency of the shuffle by switching over to using Fisher-Yates.
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira
[jira] [Commented] (ZOOKEEPER-1018) The connection permutation in
get_addrs uses a weak and inefficient shuffle
Posted by "Benjamin Reed (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/ZOOKEEPER-1018?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13015619#comment-13015619 ]
Benjamin Reed commented on ZOOKEEPER-1018:
------------------------------------------
thanx Stephen!
> The connection permutation in get_addrs uses a weak and inefficient shuffle
> ---------------------------------------------------------------------------
>
> Key: ZOOKEEPER-1018
> URL: https://issues.apache.org/jira/browse/ZOOKEEPER-1018
> Project: ZooKeeper
> Issue Type: Improvement
> Components: c client
> Affects Versions: 3.3.2
> Reporter: Stephen Tyree
> Assignee: Stephen Tyree
> Priority: Minor
> Fix For: 3.4.0
>
> Attachments: ZOOKEEPER-1018.patch
>
> Original Estimate: 2h
> Remaining Estimate: 2h
>
> After determining all of the addresses in the get_addrs function in the C client, the connection is permuted using the following code:
> setup_random();
> /* Permute */
> for(i = 0; i < zh->addrs_count; i++) {
> struct sockaddr_storage *s1 = zh->addrs + random()%zh->addrs_count;
> struct sockaddr_storage *s2 = zh->addrs + random()%zh->addrs_count;
> if (s1 != s2) {
> struct sockaddr_storage t = *s1;
> *s1 = *s2;
> *s2 = t;
> }
> }
> Not only does this shuffle produce an uneven permutation, but it is half as efficient as the Fisher-Yates shuffle which produces an unbiased one. It seems like it would be a simple fix to increase the randomness and efficiency of the shuffle by switching over to using Fisher-Yates.
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira
[jira] Commented: (ZOOKEEPER-1018) The connection permutation in
get_addrs uses a weak and inefficient shuffle
Posted by "Stephen Tyree (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/ZOOKEEPER-1018?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13007307#comment-13007307 ]
Stephen Tyree commented on ZOOKEEPER-1018:
------------------------------------------
Also, should I be adding tests? Or should I be listing what I did to test this?
> The connection permutation in get_addrs uses a weak and inefficient shuffle
> ---------------------------------------------------------------------------
>
> Key: ZOOKEEPER-1018
> URL: https://issues.apache.org/jira/browse/ZOOKEEPER-1018
> Project: ZooKeeper
> Issue Type: Improvement
> Components: c client
> Affects Versions: 3.3.2
> Reporter: Stephen Tyree
> Priority: Minor
> Attachments: ZOOKEEPER-1018.patch
>
> Original Estimate: 2h
> Remaining Estimate: 2h
>
> After determining all of the addresses in the get_addrs function in the C client, the connection is permuted using the following code:
> setup_random();
> /* Permute */
> for(i = 0; i < zh->addrs_count; i++) {
> struct sockaddr_storage *s1 = zh->addrs + random()%zh->addrs_count;
> struct sockaddr_storage *s2 = zh->addrs + random()%zh->addrs_count;
> if (s1 != s2) {
> struct sockaddr_storage t = *s1;
> *s1 = *s2;
> *s2 = t;
> }
> }
> Not only does this shuffle produce an uneven permutation, but it is half as efficient as the Fisher-Yates shuffle which produces an unbiased one. It seems like it would be a simple fix to increase the randomness and efficiency of the shuffle by switching over to using Fisher-Yates.
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira
[jira] Updated: (ZOOKEEPER-1018) The connection permutation in
get_addrs uses a weak and inefficient shuffle
Posted by "Stephen Tyree (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/ZOOKEEPER-1018?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Stephen Tyree updated ZOOKEEPER-1018:
-------------------------------------
Attachment: (was: zookeeper.c.patch)
> The connection permutation in get_addrs uses a weak and inefficient shuffle
> ---------------------------------------------------------------------------
>
> Key: ZOOKEEPER-1018
> URL: https://issues.apache.org/jira/browse/ZOOKEEPER-1018
> Project: ZooKeeper
> Issue Type: Improvement
> Components: c client
> Affects Versions: 3.3.2
> Reporter: Stephen Tyree
> Priority: Minor
> Attachments: ZOOKEEPER-1018.patch
>
> Original Estimate: 2h
> Remaining Estimate: 2h
>
> After determining all of the addresses in the get_addrs function in the C client, the connection is permuted using the following code:
> setup_random();
> /* Permute */
> for(i = 0; i < zh->addrs_count; i++) {
> struct sockaddr_storage *s1 = zh->addrs + random()%zh->addrs_count;
> struct sockaddr_storage *s2 = zh->addrs + random()%zh->addrs_count;
> if (s1 != s2) {
> struct sockaddr_storage t = *s1;
> *s1 = *s2;
> *s2 = t;
> }
> }
> Not only does this shuffle produce an uneven permutation, but it is half as efficient as the Fisher-Yates shuffle which produces an unbiased one. It seems like it would be a simple fix to increase the randomness and efficiency of the shuffle by switching over to using Fisher-Yates.
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira
[jira] Commented: (ZOOKEEPER-1018) The connection permutation in
get_addrs uses a weak and inefficient shuffle
Posted by "Mahadev konar (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/ZOOKEEPER-1018?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13006948#comment-13006948 ]
Mahadev konar commented on ZOOKEEPER-1018:
------------------------------------------
thanks stephen, I have seen quite some instances where the connections are uneven for a lot of client connections. Would you be able to verify this change with lets say running 3 zookeeper servers and having a lot of connections (100's) and seeing how its affected?
Also, can you please look at the java code and see if it faces the same issue?
> The connection permutation in get_addrs uses a weak and inefficient shuffle
> ---------------------------------------------------------------------------
>
> Key: ZOOKEEPER-1018
> URL: https://issues.apache.org/jira/browse/ZOOKEEPER-1018
> Project: ZooKeeper
> Issue Type: Improvement
> Components: c client
> Affects Versions: 3.3.2
> Reporter: Stephen Tyree
> Priority: Minor
> Attachments: zookeeper.c.patch
>
> Original Estimate: 2h
> Remaining Estimate: 2h
>
> After determining all of the addresses in the get_addrs function in the C client, the connection is permuted using the following code:
> setup_random();
> /* Permute */
> for(i = 0; i < zh->addrs_count; i++) {
> struct sockaddr_storage *s1 = zh->addrs + random()%zh->addrs_count;
> struct sockaddr_storage *s2 = zh->addrs + random()%zh->addrs_count;
> if (s1 != s2) {
> struct sockaddr_storage t = *s1;
> *s1 = *s2;
> *s2 = t;
> }
> }
> Not only does this shuffle produce an uneven permutation, but it is half as efficient as the Fisher-Yates shuffle which produces an unbiased one. It seems like it would be a simple fix to increase the randomness and efficiency of the shuffle by switching over to using Fisher-Yates.
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira
[jira] [Updated] (ZOOKEEPER-1018) The connection permutation in
get_addrs uses a weak and inefficient shuffle
Posted by "Stephen Tyree (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/ZOOKEEPER-1018?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Stephen Tyree updated ZOOKEEPER-1018:
-------------------------------------
Attachment: (was: ZOOKEEPER-1018.patch)
> The connection permutation in get_addrs uses a weak and inefficient shuffle
> ---------------------------------------------------------------------------
>
> Key: ZOOKEEPER-1018
> URL: https://issues.apache.org/jira/browse/ZOOKEEPER-1018
> Project: ZooKeeper
> Issue Type: Improvement
> Components: c client
> Affects Versions: 3.3.2
> Reporter: Stephen Tyree
> Assignee: Stephen Tyree
> Priority: Minor
> Attachments: ZOOKEEPER-1018.patch
>
> Original Estimate: 2h
> Remaining Estimate: 2h
>
> After determining all of the addresses in the get_addrs function in the C client, the connection is permuted using the following code:
> setup_random();
> /* Permute */
> for(i = 0; i < zh->addrs_count; i++) {
> struct sockaddr_storage *s1 = zh->addrs + random()%zh->addrs_count;
> struct sockaddr_storage *s2 = zh->addrs + random()%zh->addrs_count;
> if (s1 != s2) {
> struct sockaddr_storage t = *s1;
> *s1 = *s2;
> *s2 = t;
> }
> }
> Not only does this shuffle produce an uneven permutation, but it is half as efficient as the Fisher-Yates shuffle which produces an unbiased one. It seems like it would be a simple fix to increase the randomness and efficiency of the shuffle by switching over to using Fisher-Yates.
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira
[jira] Updated: (ZOOKEEPER-1018) The connection permutation in
get_addrs uses a weak and inefficient shuffle
Posted by "Stephen Tyree (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/ZOOKEEPER-1018?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Stephen Tyree updated ZOOKEEPER-1018:
-------------------------------------
Attachment: zookeeper.c.patch
Patch to implement the change. I'm not sure if I diff'd this correctly, but this is it.
> The connection permutation in get_addrs uses a weak and inefficient shuffle
> ---------------------------------------------------------------------------
>
> Key: ZOOKEEPER-1018
> URL: https://issues.apache.org/jira/browse/ZOOKEEPER-1018
> Project: ZooKeeper
> Issue Type: Improvement
> Components: c client
> Affects Versions: 3.3.2
> Reporter: Stephen Tyree
> Priority: Minor
> Attachments: zookeeper.c.patch
>
> Original Estimate: 2h
> Remaining Estimate: 2h
>
> After determining all of the addresses in the get_addrs function in the C client, the connection is permuted using the following code:
> setup_random();
> /* Permute */
> for(i = 0; i < zh->addrs_count; i++) {
> struct sockaddr_storage *s1 = zh->addrs + random()%zh->addrs_count;
> struct sockaddr_storage *s2 = zh->addrs + random()%zh->addrs_count;
> if (s1 != s2) {
> struct sockaddr_storage t = *s1;
> *s1 = *s2;
> *s2 = t;
> }
> }
> Not only does this shuffle produce an uneven permutation, but it is half as efficient as the Fisher-Yates shuffle which produces an unbiased one. It seems like it would be a simple fix to increase the randomness and efficiency of the shuffle by switching over to using Fisher-Yates.
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira
[jira] Commented: (ZOOKEEPER-1018) The connection permutation in
get_addrs uses a weak and inefficient shuffle
Posted by "Stephen Tyree (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/ZOOKEEPER-1018?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13006962#comment-13006962 ]
Stephen Tyree commented on ZOOKEEPER-1018:
------------------------------------------
Although I am less familiar with the Java code, I found this snippet in org/main/apache/zookeeper/client/StaticHostProvider.java:
Collections.shuffle(this.serverAddresses);
This tells me that the Java library lacks this problem. Do you want me to package this up more neatly with an svn diff?
> The connection permutation in get_addrs uses a weak and inefficient shuffle
> ---------------------------------------------------------------------------
>
> Key: ZOOKEEPER-1018
> URL: https://issues.apache.org/jira/browse/ZOOKEEPER-1018
> Project: ZooKeeper
> Issue Type: Improvement
> Components: c client
> Affects Versions: 3.3.2
> Reporter: Stephen Tyree
> Priority: Minor
> Attachments: zookeeper.c.patch
>
> Original Estimate: 2h
> Remaining Estimate: 2h
>
> After determining all of the addresses in the get_addrs function in the C client, the connection is permuted using the following code:
> setup_random();
> /* Permute */
> for(i = 0; i < zh->addrs_count; i++) {
> struct sockaddr_storage *s1 = zh->addrs + random()%zh->addrs_count;
> struct sockaddr_storage *s2 = zh->addrs + random()%zh->addrs_count;
> if (s1 != s2) {
> struct sockaddr_storage t = *s1;
> *s1 = *s2;
> *s2 = t;
> }
> }
> Not only does this shuffle produce an uneven permutation, but it is half as efficient as the Fisher-Yates shuffle which produces an unbiased one. It seems like it would be a simple fix to increase the randomness and efficiency of the shuffle by switching over to using Fisher-Yates.
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira