private void doMapReduce() { try { Job job = Job.getInstance(); job.getConfiguration().set(OutputFormat.NAMESPACE, "/"); job.getConfiguration().set(OutputFormat.TABLE, "LoadTest"); job.getConfiguration().setInt(OutputFormat.MUTATOR_FLAGS, MutatorFlag.NO_LOG_SYNC.getValue()); job.getConfiguration().setInt(OutputFormat.MUTATOR_FLUSH_INTERVAL, 0); job.getConfiguration().setInt("LoadSplit.TOTAL_ROWS", this.totalRows); job.getConfiguration().setInt("LoadSplit.CLIENTS", this.clients); job.setJarByClass(LoadTest.class); job.setJobName("Hypertable MapReduce connector LoadTest"); job.setInputFormatClass(LoadInputFormat.class); job.setOutputFormatClass(OutputFormat.class); job.setMapOutputKeyClass(KeyWritable.class); job.setMapOutputValueClass(BytesWritable.class); job.setMapperClass(LoadMapper.class); job.setReducerClass(LoadReducer.class); job.setNumReduceTasks(this.clients); job.waitForCompletion(true); } catch (Exception e) { e.printStackTrace(); } }
public HashMap<String, String> getInitialStats() { HashMap<String, String> result = new HashMap<String, String>(); int userCnt = 0; int pendingFriends = 0; int confirmedFriends = 0; int resourceCnt = 0; HashSet<String> users = new HashSet<String>(); HqlResult queryRes; try { /* Get all unique users from user table */ HqlResultAsArrays result_as_arrays = client.hql_query_as_arrays(namespace, "SELECT * from users"); for (List<?> cell_as_array : result_as_arrays.cells) users.add(cell_as_array.get(0).toString()); userCnt = users.size(); /* Iterate all the users */ for (String user : users) { /* get resource cnt */ queryRes = client.hql_query( namespace, "SELECT * from " + ResourceTable + " where creatorid='" + user + "'"); resourceCnt += queryRes.cells.size(); /* get pending friends */ queryRes = client.hql_query( namespace, "SELECT * from " + PendingFriendsTable + " where row='" + user + "'"); pendingFriends += queryRes.cells.size(); /* get confirmed friends */ queryRes = client.hql_query( namespace, "SELECT * from " + ConfirmedFriendsTable + " where row='" + user + "'"); confirmedFriends += queryRes.cells.size(); } /* Calculate average count */ resourceCnt = resourceCnt > 0 ? resourceCnt / userCnt : 0; pendingFriends = pendingFriends > 0 ? pendingFriends / userCnt : 0; confirmedFriends = confirmedFriends > 0 ? confirmedFriends / userCnt : 0; /* Populate hash map */ result.put("usercount", String.valueOf(userCnt)); result.put("resourcesperuser", String.valueOf(resourceCnt)); result.put("avgfriendsperuser", String.valueOf(confirmedFriends)); result.put("avgpendingperuser", String.valueOf(pendingFriends)); return result; } catch (Exception e) { e.printStackTrace(System.out); return null; } }
/* init */ public boolean init() throws DBException { try { client = ThriftClient.create(HOST_IP, PORT_NUM, 16000000, true, 400 * 1024 * 1024); if (!client.namespace_exists(HTNAMESPACE)) { client.namespace_create(HTNAMESPACE); } namespace = client.namespace_open("bgclient"); } catch (Exception e) { e.printStackTrace(System.out); return false; } return true; }
private int run(String[] args) { String rows = "--rows="; String clients = "--clients="; try { for (int ii = 0; ii < args.length; ++ii) { String cmd = args[ii]; if (cmd.startsWith(rows)) { this.totalRows = Integer.parseInt(cmd.substring(rows.length())); } else if (cmd.startsWith(clients)) { this.clients = Integer.parseInt(cmd.substring(clients.length())); } else { printUsage(); return -1; } } doMapReduce(); } catch (Exception e) { e.printStackTrace(); } return 0; }
public int viewProfile( int requesterID, int profileOwnerID, HashMap<String, ByteIterator> result, boolean insertImage, boolean testMode) { // TODO Auto-generated method stub int pendingFriends = 0; int confirmedFriends = 0; int resourceCnt = 0; HqlResult queryRes; try { result.put( "userid", new ObjectByteIterator(String.valueOf(profileOwnerID).getBytes("UTF-8"))); /* Get all unique users from user table */ HqlResultAsArrays result_as_arrays = client.hql_query_as_arrays( namespace, "SELECT * from users where row='" + profileOwnerID + "'"); for (List<?> cell_as_array : result_as_arrays.cells) { if (!insertImage && (cell_as_array.get(1).toString().equalsIgnoreCase("pic") || cell_as_array.get(1).toString().equalsIgnoreCase("tpic"))) { continue; } else { result.put( cell_as_array.get(1).toString(), new ObjectByteIterator(cell_as_array.get(3).toString().getBytes("UTF-8"))); } } /* get resource cnt */ queryRes = client.hql_query( namespace, "SELECT * from " + ResourceTable + " where walluserid='" + profileOwnerID + "'"); resourceCnt += queryRes.cells.size(); /* get pending friends */ if (requesterID == profileOwnerID) { queryRes = client.hql_query( namespace, "SELECT * from " + PendingFriendsTable + " where row='" + profileOwnerID + "'"); pendingFriends += queryRes.cells.size(); result.put( "pendingcount", new ObjectByteIterator(String.valueOf(pendingFriends).getBytes("UTF-8"))); } /* get confirmed friends */ queryRes = client.hql_query( namespace, "SELECT * from " + ConfirmedFriendsTable + " where row='" + profileOwnerID + "'"); confirmedFriends += queryRes.cells.size(); /* Populate hash map */ result.put( "resourcecount", new ObjectByteIterator(String.valueOf(resourceCnt).getBytes("UTF-8"))); result.put( "friendcount", new ObjectByteIterator(String.valueOf(pendingFriends).getBytes("UTF-8"))); } catch (Exception e) { e.printStackTrace(System.out); return -1; } return 0; }