[sheepdog] [PATCH 3/3] sheep: let forward_read_obj_req() read random copy

Liu Yuan namei.unix at gmail.com
Wed May 30 04:42:38 CEST 2012


From: Liu Yuan <tailai.ly at taobao.com>

Read random copy from cluster for better load balance, useful for
reading base VM's COW objects

Signed-off-by: Liu Yuan <tailai.ly at taobao.com>
---
 sheep/gateway.c |    9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/sheep/gateway.c b/sheep/gateway.c
index 5672952..78e406c 100644
--- a/sheep/gateway.c
+++ b/sheep/gateway.c
@@ -85,7 +85,7 @@ int forward_read_obj_req(struct request *req)
 	struct sd_vnode *v;
 	struct sd_vnode *obj_vnodes[SD_MAX_COPIES];
 	uint64_t oid = req->rq.obj.oid;
-	int nr_copies;
+	int nr_copies, j;
 
 	memcpy(&fwd_hdr, &req->rq, sizeof(fwd_hdr));
 	fwd_hdr.flags |= SD_FLAG_CMD_IO_LOCAL;
@@ -108,8 +108,13 @@ int forward_read_obj_req(struct request *req)
 	}
 
 read_remote:
+	/* Read random copy from cluster for better load balance, useful for
+	 * reading base VM's COW objects
+	 */
+	j = random();
 	for (i = 0; i < nr_copies; i++) {
-		v = obj_vnodes[i];
+		int idx = (i + j) % nr_copies;
+		v = obj_vnodes[idx];
 		if (vnode_is_local(v))
 			continue;
 
-- 
1.7.10.2




More information about the sheepdog mailing list