コード例 #1
0
FeedUserPropertyData FeedUserPropertyClient::Get(Ice::Int uid){
  char key[32];
  GetUserKey(uid, key, 32);
  pair<int, MemcachedClient*> cli = pool_.GetClient(uid); 
  if(!cli.second){
    return FeedUserPropertyData();
  }
	TimeStat1 ts;
  vector<string> keys;
  keys.push_back(key);
  map<string, string> res;
  map<string, int> flags;
  cli.second->Get(keys, res, flags);
	float cost_mem = ts.getTime();
	string ip = cli.second->GetIp();
  pool_.ReleaseClient(cli.first, cli.second);
  if(res.size()!=1){
    return FeedUserPropertyData();
  }
	if( cost_mem < 160) {
		MCE_INFO("FeedUserPropertyClient::Get --> uid:" << uid << " cost_total:" << cost_mem << " ip:" << ip);
	} else {
		MCE_WARN("FeedUserPropertyClient::Get --> uid:" << uid << " cost_total:" << cost_mem << " ip:" << ip);
	}
  return FeedUserPropertyData(res[key]);
}
コード例 #2
0
ファイル: feed_memc_client.cpp プロジェクト: bradenwu/oce
FeedContentDict FeedMemcClient::GetFeedDict(const MyUtil::LongSeq& ids) {
  float cost_mem;
  float cost_decom;
  vector<string> feedids;
  for(size_t i=0; i<ids.size(); i++){
    char data[64] = {0};
    snprintf(data, 64, "FEED#%ld", ids.at(i));
    feedids.push_back(data);
  }
  FeedContentDict dict;
  pair<int, MemcachedClient*> cli = pool_.GetClient(ids.at(0)); 
  if(!cli.second){
    return FeedContentDict();
  }
  map<string, string> res;
  map<string, int> flags;
  TimeStat1 ts;
  bool succ = cli.second->Get(feedids, res, flags);
  //MCE_INFO("FeedMemcClient::GetFeedDict --> get end, " << cli.first << " " << res.size() << " " << flags.size());
  cost_mem = ts.getTime();
  //if(!succ){
  //  return FeedContentDict();
  //}
  ts.reset();
  map<string, string>::iterator it = res.begin();
  for(; it!=res.end(); ++it){
    Ice::Long fid = GetFeedId(it->first.c_str(), it->first.size());
    if(it->second == kEmptyFeed){
      dict.insert(make_pair(fid, FeedContentPtr(NULL)));
      continue;
    } 
    int flag = flags[it->first.c_str()];
    PbFeedContent pb;
    if(flag & 0x01) {
      string decompressed;
      CompressWrap::instance().Decompress(it->second.c_str(), &decompressed);
      pb.ParseFromArray(decompressed.data(), decompressed.size());
    } else {
       pb.ParseFromArray(it->second.c_str(), it->second.size());
    }

    FeedContentPtr content = new FeedContent();
    FeedContentPbToIce(pb, content);
    content->data->weight &= 0xFFFF0000;
    if(content->reply){
      content->data->weight |= (content->reply->count&0xFFFF);
    }
    dict.insert(make_pair(content->data->feed, content));
  }
  cost_decom = ts.getTime();
  string ip = cli.second->GetIp();
  pool_.ReleaseClient(cli.first, cli.second);
  MCE_INFO("FeedMemcClient::GetFeedDict --> ids:" << ids.size() << " res:" << dict.size() 
          << " cost_mem:" << cost_mem << " cost_par:" << cost_decom << " cost_total:" << (cost_mem+cost_decom)
          << " ip:" << ip);
  return dict;
}
コード例 #3
0
bool FeedUserPropertyClient::Set(int uid, FeedUserPropertyData& data){
  char key[32];
  GetUserKey(uid, key, 32);
  pair<int, MemcachedClient*> cli = pool_.GetClient(uid); 
	if(!cli.second)
		return false;
	TimeStat1 ts;
  bool res = cli.second->Set(key, data.GetOriginalData(), 0);
	float cost_mem = ts.getTime();
	string ip = cli.second->GetIp();
  pool_.ReleaseClient(cli.first, cli.second);
	if( cost_mem < 160) {
		MCE_INFO("FeedUserPropertyClient::set --> uid:" << uid << " cost_total:" << cost_mem << " ip:" << ip);
	} else {
		MCE_WARN("FeedUserPropertyClient::set --> uid:" << uid << " cost_total:" << cost_mem << " ip:" << ip);
	}
  return res;
}