开源 企业版 高校版 私有云 模力方舟 AI 队友
代码拉取完成,页面将自动刷新
开源项目 > WEB应用开发 > RPC开发框架 &&
捐赠
捐赠前请先登录
扫描微信二维码支付
取消
支付完成
支付提示
将跳转至支付宝完成支付
确定
取消
7 Star 4 Fork 7

cxxjava/Tars

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
已有帐号? 立即登录
文件
master
分支 (1)
master
master
分支 (1)
master
克隆/下载
克隆/下载
提示
下载代码请复制以下命令到终端执行
为确保你提交的代码身份被 Gitee 正确识别,请执行以下命令完成配置
初次使用 SSH 协议进行代码克隆、推送等操作时,需按下述提示完成 SSH 配置
1 生成 RSA 密钥
2 获取 RSA 公钥内容,并配置到 SSH公钥
在 Gitee 上使用 SVN,请访问 使用指南
使用 HTTPS 协议时,命令行会出现如下账号密码验证步骤。基于安全考虑,Gitee 建议 配置并使用私人令牌 替代登录密码进行克隆、推送等操作
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # 私人令牌
master
分支 (1)
master
Tars
/
cpp
/
framework
/
NodeServer
/
ServerObject.cpp
Tars
/
cpp
/
framework
/
NodeServer
/
ServerObject.cpp
ServerObject.cpp 24.34 KB
一键复制 编辑 原始数据 按行查看 历史
cxxjava 提交于 2017年04月10日 16:40 +08:00 . 1. 添加对mac osx的支持;
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825
/**
* Tencent is pleased to support the open source community by making Tars available.
*
* Copyright (C) 2016THL A29 Limited, a Tencent company. All rights reserved.
*
* Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* https://opensource.org/licenses/BSD-3-Clause
*
* Unless required by applicable law or agreed to in writing, software distributed
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
#include "ServerObject.h"
#include "RegistryProxy.h"
#include "util/tc_clientsocket.h"
#include "servant/Communicator.h"
#include "NodeServer.h"
#include "CommandStart.h"
#include "CommandNotify.h"
#include "CommandStop.h"
#include "CommandDestroy.h"
#include "CommandAddFile.h"
#include "NodeRollLogger.h"
#ifdef __APPLE__
#include <sys/resource.h>
#endif
ServerObject::ServerObject( const ServerDescriptor& tDesc)
: _tarsServer(true)
, _loaded(false)
, _patched(true)
, _noticed(false)
, _noticeFailTimes(0)
, _enSynState(true)
, _pid(0)
, _state(ServerObject::Inactive)
, _limitStateUpdated(false)
, _started(false)
{
//60秒内最多启动10次,达到10次启动仍失败后,每隔600秒再重试一次
_activatorPtr = new Activator(60,10,600);
//服务相关修改集中放到setServerDescriptor函数中
setServerDescriptor(tDesc);
_serviceLimitResource = new ServerLimitResource(5,10,60,_application,_serverName);
}
void ServerObject::setServerDescriptor( const ServerDescriptor& tDesc )
{
TLOGDEBUG("ServerObject::setServerDescriptor "<< tDesc.application << "." << tDesc.serverName <<endl);
_desc = tDesc;
_application = tDesc.application;
_serverName = tDesc.serverName;
_serverId = _application+"."+_serverName;
_desc.settingState == "active"?_enabled = true:_enabled = false;
time_t now = TNOW;
_adapterKeepAliveTime.clear();
map<string, AdapterDescriptor>::const_iterator itAdapters;
for( itAdapters = _desc.adapters.begin(); itAdapters != _desc.adapters.end(); itAdapters++)
{
_adapterKeepAliveTime[itAdapters->first] = now;
}
_adapterKeepAliveTime["AdminAdapter"] = now;
setLastKeepAliveTime(now);
}
bool ServerObject::isAutoStart()
{
Lock lock(*this);
TLOGDEBUG( "ServerObject::isAutoStart "<< _application << "." << _serverName <<"|"<<_enabled<<"|"<<_loaded<<"|"<<_patched<<"|"<<toStringState(_state)<<endl);
NODE_LOG("KeepAliveThread")->debug()<<FILE_FUN<< _application << "." << _serverName <<"|"<<_enabled<<"|"<<_loaded<<"|"<<_patched<<"|"<<toStringState(_state)<<endl;
if(toStringState(_state).find( "ing" ) != string::npos) //正处于中间态时不允许重启动
{
TLOGDEBUG("ServerObject::isAutoStart " << _application << "." << _serverName <<" not allow to restart in (ing) state"<<endl);
return false;
}
if(!_enabled||!_loaded || !_patched || _activatorPtr->isActivatingLimited())
{
if(_activatorPtr->isActivatingLimited())
{
TLOGDEBUG("ServerObject::isAutoStart " << _application << "." << _serverName <<" not allow to restart in limited state"<<endl);
}
return false;
}
return true;
}
ServerState ServerObject::getState()
{
Lock lock(*this);
TLOGINFO("ServerObject::getState "<<_application << "." << _serverName <<"'s state is "<<toStringState(_state)<<endl);
return toServerState( _state );
}
void ServerObject::setState(InternalServerState eState, bool bSynState)
{
Lock lock(*this);
if (_state == eState && _noticed == true)
{
return;
}
if ( _state != eState )
{
TLOGDEBUG(FILE_FUN << _application << "." << _serverName << " State changed! old State:" << toStringState( _state ) << " new State:" << toStringState( eState ) << endl);
_state = eState;
}
if(bSynState == true)
{
synState();
}
}
void ServerObject::setLastState(InternalServerState eState)
{
Lock lock(*this);
_lastState = eState;
}
bool ServerObject::isScriptFile(const string &sFileName)
{
if(TC_Common::lower(TC_File::extractFileExt(sFileName)) == "sh" ) //.sh文件为脚本
{
return true;
}
if(TC_File::extractFileName(_startScript) == sFileName )
{
return true;
}
if(TC_File::extractFileName(_stopScript) == sFileName )
{
return true;
}
if(TC_File::extractFileName(_monitorScript) == sFileName )
{
return true;
}
return false;
}
//同步更新 重启服务 需要准确通知主控状态时调用
void ServerObject::synState()
{
Lock lock(*this);
try
{
ServerStateInfo tServerStateInfo;
tServerStateInfo.serverState = (IsEnSynState()?toServerState(_state):tars::Inactive);
tServerStateInfo.processId = _pid;
//根据uNoticeFailTimes判断同步还是异步更新服务状态
//防止主控超时导致阻塞服务上报心跳
if(_noticeFailTimes < 3)
{
AdminProxy::getInstance()->getRegistryProxy()->updateServer( _nodeInfo.nodeName, _application, _serverName, tServerStateInfo);
}
else
{
AdminProxy::getInstance()->getRegistryProxy()->async_updateServer(NULL, _nodeInfo.nodeName, _application, _serverName, tServerStateInfo);
}
//日志
stringstream ss;
tServerStateInfo.displaySimple(ss);
NODE_LOG("synState")->debug()<<FILE_FUN << "synState" << "|"<< _nodeInfo.nodeName << "|" << _application << "|" << _serverName
<< "|" << std::boolalpha << _enSynState <<"|" << ss.str() << endl;
_noticed = true;
_noticeFailTimes = 0;
}
catch (exception &e)
{
_noticed = false;
_noticeFailTimes ++;
TLOGERROR("ServerObject::synState "<<_application<<"."<<_serverName<<" error times:"<<_noticeFailTimes<<" reason:"<< e.what() << endl);
}
}
//异步同步状态
void ServerObject::asyncSynState()
{
Lock lock(*this);
try
{
ServerStateInfo tServerStateInfo;
tServerStateInfo.serverState = (IsEnSynState()?toServerState(_state):tars::Inactive);
tServerStateInfo.processId = _pid;
AdminProxy::getInstance()->getRegistryProxy()->async_updateServer( NULL, _nodeInfo.nodeName, _application, _serverName, tServerStateInfo);
//日志
stringstream ss;
tServerStateInfo.displaySimple(ss);
NODE_LOG("synState")->debug()<<FILE_FUN<< _nodeInfo.nodeName << "|" << _application << "|" << _serverName
<< "|" << std::boolalpha << _enSynState <<"|" << ss.str() << endl;
}
catch (exception &e)
{
TLOGERROR("ServerObject::asyncSynState "<<_application<<"."<<_serverName<<" error:" << e.what() << endl);
}
}
ServerState ServerObject::toServerState(InternalServerState eState) const
{
switch (eState)
{
case Inactive:
{
return tars::Inactive;
}
case Activating:
{
return tars::Activating;
}
case Active:
{
return tars::Active;
}
case Deactivating:
{
return tars::Deactivating;
}
case Destroying:
{
return tars::Destroying;
}
case Destroyed:
{
return tars::Destroyed;
}
default:
{
return tars::Inactive;
}
}
}
string ServerObject::toStringState(InternalServerState eState) const
{
switch (eState)
{
case Inactive:
{
return "Inactive";
}
case Activating:
{
return "Activating";
}
case Active:
{
return "Active";
}
case Deactivating:
{
return "Deactivating";
}
case Destroying:
{
return "Destroying";
}
case Destroyed:
{
return "Destroyed";
}
case Loading:
{
return "Loading";
}
case Patching:
{
return "Patching";
}
case BatchPatching:
{
return "BatchPatching";
}
case AddFilesing:
{
return "AddFilesing";
}
default:
{
ostringstream os;
os << "state " << eState;
return os.str();
}
};
}
int ServerObject::checkPid()
{
Lock lock(*this);
if(_pid != 0)
{
int iRet = _activatorPtr->sendSignal(_pid, 0);
if (iRet == 0)
{
NODE_LOG("KeepAliveThread")->debug() <<FILE_FUN<< _serverId << "|" << _pid << "|" << iRet << endl;
return 0;
}
}
NODE_LOG("KeepAliveThread")->error() <<FILE_FUN<< _serverId << "|" << _pid << "|-1" << endl;
return -1;
}
void ServerObject::keepAlive(pid_t pid,const string &adapter)
{
Lock lock(*this);
if (pid <= 0)
{
TLOGERROR("ServerObject::keepAlive "<< _application << "." << _serverName << " pid "<<pid<<" error, pid <= 0"<<endl);
return;
}
else
{
TLOGDEBUG("ServerObject::keepAlive "<<_serverType<< "|pid|" << pid <<"|server|"<<_application << "." << _serverName <<"|"<<adapter<< endl);
}
time_t now = TNOW;
setLastKeepAliveTime(now,adapter);
//setLastKeepAliveTime(now);
setPid(pid);
//心跳不改变正在转换期状态(Activating除外)
if(toStringState(_state).find("ing") == string::npos || _state == ServerObject::Activating)
{
TLOGDEBUG("ServerObject::keepAlive "<< _desc.application << "|" << _desc.serverName << "|" << toStringState(_state) << "|" << _state << endl);
setState(ServerObject::Active);
}
else
{
TLOGDEBUG("ServerObject::keepAlive " << _application << "." << _serverName << " State no need changed to active! State:" << toStringState( _state ) << endl);
}
if(!_loaded)
{
_loaded = true;
}
if(!_patched)
{
_patched = true;
}
}
void ServerObject::setLastKeepAliveTime(int t,const string& adapter)
{
Lock lock(*this);
_keepAliveTime = t;
map<string, time_t>::iterator it1 = _adapterKeepAliveTime.begin();
if(adapter.empty())
{
while (it1 != _adapterKeepAliveTime.end() )
{
it1->second = t;
it1++;
}
return;
}
map<string, time_t>::iterator it2 = _adapterKeepAliveTime.find(adapter);
if( it2 != _adapterKeepAliveTime.end())
{
it2->second = t;
}
else
{
TLOGERROR("ServerObject::setLastKeepAliveTime "<<adapter<<" not registed "<< endl);
}
}
int ServerObject::getLastKeepAliveTime(const string &adapter)
{
if(adapter.empty())
{
return _keepAliveTime;
}
map<string, time_t>::const_iterator it = _adapterKeepAliveTime.find(adapter);
if( it != _adapterKeepAliveTime.end())
{
return it->second;
}
return -1;
}
bool ServerObject::isTimeOut(int iTimeout)
{
Lock lock(*this);
time_t now = TNOW;
if(now - _keepAliveTime > iTimeout)
{
TLOGERROR("ServerObject::isTimeOut server time out "<<now - _keepAliveTime<<"|>|"<<iTimeout<< endl);
return true;
}
map<string, time_t>::const_iterator it = _adapterKeepAliveTime.begin();
while (it != _adapterKeepAliveTime.end() )
{
if(now - it->second > iTimeout)
{
TLOGERROR("ServerObject::isTimeOut server "<< it->first<<" time out "<<now - it->second<<"|>|"<<iTimeout<<"|"<<TC_Common::tostr(_adapterKeepAliveTime)<< endl);
return true;
}
it++;
}
return false;
}
bool ServerObject::isStartTimeOut()
{
Lock lock(*this);
int64_t now = TNOWMS;
if (now - _startTime >= 100)//默认为100ms,_timeout
{
NODE_LOG("KeepAliveThread")->debug()<<FILE_FUN<<"server start time out "<<now - _startTime<<"|>|"<<100<<endl;
return true;
}
NODE_LOG("KeepAliveThread")->debug()<<"server start time out "<<now - _startTime<<"|<|"<<100<<endl;
return false;
}
void ServerObject::setVersion( const string & version )
{
Lock lock(*this);
try
{
_version = version;
AdminProxy::getInstance()->getRegistryProxy()->async_reportVersion(NULL,_application, _serverName, _nodeInfo.nodeName, version);
}catch(...)
{
_noticed = false;
}
}
void ServerObject::setPid(pid_t pid)
{
Lock lock(*this);
if (pid == _pid)
{
return;
}
NODE_LOG("startServer")->debug()<<FILE_FUN<< _application << "." << _serverName << " pid changed! old pid:" << _pid << " new pid:" << pid << endl;
_pid = pid;
}
void ServerObject::setPatchPercent(const int iPercent)
{
Lock lock(*this);
//下载结束仍需要等待本地copy 进度最多设置99% 本地copy结束后设置为100%
_patchInfo.iPercent = iPercent>99?99:iPercent;
_patchInfo.iModifyTime = TNOW;
}
void ServerObject::setPatchResult(const string &sPatchResult,const bool bSucc)
{
Lock lock(*this);
_patchInfo.sResult = sPatchResult;
_patchInfo.bSucc = bSucc;
}
void ServerObject::setPatchVersion(const string &sVersion)
{
Lock lock(*this);
_patchInfo.sVersion = sVersion;
}
string ServerObject::getPatchVersion()
{
Lock lock(*this);
return _patchInfo.sVersion;
}
int ServerObject::getPatchPercent(PatchInfo &tPatchInfo)
{
TLOGDEBUG("ServerObject::getPatchPercent"<< _application << "_" << _serverName << "|"<< _serverId<< endl);
Lock lock(*this);
TLOGDEBUG("ServerObject::getPatchPercent "<< _application << "_" << _serverName << "|"<< _serverId << "get lock" << endl);
tPatchInfo = _patchInfo;
//是否正在发布
tPatchInfo.bPatching = (_state == ServerObject::Patching ||_state==ServerObject::BatchPatching)?true:false;
if (tPatchInfo.bSucc == true || _state == ServerObject::Patching || _state == ServerObject::BatchPatching)
{
TLOGDEBUG("ServerObject::getPatchPercent "<< _desc.application
<< "|" << _desc.serverName << "|succ:" << (tPatchInfo.bSucc?"true":"false") << "|" << toStringState(_state) << "|" << _patchInfo.iPercent << "%|" << _patchInfo.sResult << endl);
return 0;
}
TLOGERROR("ServerObject::getPatchPercent "<< _desc.application
<< "|" << _desc.serverName << "|succ:" << (tPatchInfo.bSucc?"true":"false") << "|" << toStringState(_state) << "|" << _patchInfo.iPercent << "%|" << _patchInfo.sResult << endl);
return -1;
}
string ServerObject::decodeMacro(const string& value) const
{
string tmp = value;
map<string,string>::const_iterator it = _macro.begin();
while(it != _macro.end())
{
tmp = TC_Common::replace(tmp, "${" + it->first + "}", it->second);
++it;
}
return tmp;
}
void ServerObject::setMacro(const map<string,string>& mMacro)
{
Lock lock(*this);
map<string,string>::const_iterator it1 = mMacro.begin();
for(;it1!= mMacro.end();++it1)
{
map<string,string>::iterator it2 = _macro.find(it1->first);
if(it2 != _macro.end())
{
it2->second = it1->second;
}
else
{
_macro[it1->first] = it1->second;
}
}
}
void ServerObject::setScript(const string &sStartScript,const string &sStopScript,const string &sMonitorScript )
{
_startScript = TC_File::simplifyDirectory(TC_Common::trim(sStartScript));
_stopScript = TC_File::simplifyDirectory(TC_Common::trim(sStopScript));
_monitorScript = TC_File::simplifyDirectory(TC_Common::trim(sMonitorScript));
}
bool ServerObject::getRemoteScript(const string &sFileName)
{
string sFile = TC_File::simplifyDirectory(TC_Common::trim(sFileName));
if(!sFile.empty())
{
CommandAddFile commands(this,sFile);
commands.doProcess(); //拉取脚本
return true;
}
return false;
}
void ServerObject::doMonScript()
{
try
{
string sResult;
time_t tNow = TNOW;
if(TC_File::isAbsolute(_monitorScript) == true) //监控脚本
{
if(_state == ServerObject::Activating||tNow - _keepAliveTime > ServantHandle::HEART_BEAT_INTERVAL)
{
map<string,string> mResult;
_activatorPtr->doScript(_serverId,_monitorScript,sResult,mResult);
if(mResult.find("pid") != mResult.end() && TC_Common::isdigit(mResult["pid"]) == true)
{
TLOGDEBUG("ServerObject::doMonScript "<< _serverId << "|"<< mResult["pid"] << endl);
keepAlive(TC_Common::strto<int>(mResult["pid"]));
}
}
}
}
catch (exception &e)
{
TLOGERROR("ServerObject::doMonScript error:" << e.what() << endl);
}
}
void ServerObject::checkServer(int iTimeout)//checkServer时对服务所占用的内存上报到主控
{
try
{
string sResult;
NODE_LOG("KeepAliveThread")->debug() <<FILE_FUN<<_serverId <<"|"<<toStringState(_state)<< endl;
//pid不存在属于服务异常
if( _state != ServerObject::Inactive && _state != ServerObject::Deactivating && (checkPid() != 0))
{
bool bShouldStop = false;
if (_state == ServerObject::Activating)
{
if (_started && isStartTimeOut())
{
bShouldStop = true;
sResult="[alarm] activating,pid not exist";
NODE_LOG("KeepAliveThread")->debug()<<FILE_FUN<<"|sResult:"<<sResult<<endl;
}
NODE_LOG("KeepAliveThread")->debug()<<FILE_FUN<<"|is not bstarted"<<endl;
}
else
{
bShouldStop = true;
sResult = "[alarm] down,pid not exist";
NODE_LOG("KeepAliveThread")->debug()<<FILE_FUN<<"|sResult:"<<sResult<<endl;
}
if (bShouldStop)
{
NODE_LOG("KeepAliveThread")->debug()<<FILE_FUN<<_serverId<<" "<<sResult << "|pid|" << _pid << "|_state:" << toStringState(_state)<<"|_started:"<<_started<< endl;
CommandStop command(this, false);
command.doProcess();
}
}
else
{
NODE_LOG("KeepAliveThread")->debug() <<FILE_FUN<< _serverId<<"|" << toStringState(_state) << "|" << _pid << endl;
}
//正在运行程序心跳上报超时。
int iRealTimeout = _timeout > 0?_timeout:iTimeout;
if( _state != ServerObject::Inactive && isTimeOut(iRealTimeout))
{
sResult = "[alarm] zombie process,no keep alive msg for " + TC_Common::tostr(iRealTimeout) + " seconds";
NODE_LOG("KeepAliveThread")->debug()<<FILE_FUN<<_serverId<<" "<<sResult << endl;
CommandStop command(this, true);
command.doProcess();
}
//启动服务
if( _state == ServerObject::Inactive && isAutoStart() == true)
{
sResult = sResult == ""?"[alarm] down, server is inactive":sResult;
NODE_LOG("KeepAliveThread")->debug() <<FILE_FUN<<_serverId<<" "<<sResult << "|_state:" << toStringState(_state) << endl;
g_app.reportServer(_serverId,sResult);
CommandStart command(this);
int ret = command.doProcess();
NODE_LOG("KeepAliveThread")->debug() <<FILE_FUN<<"|start ret:" << ret << endl;
//配置了coredump检测才进行操作
if(_limitStateInfo.bEnableCoreLimit)
{
_serviceLimitResource->addExcStopRecord();
}
}
}
catch(exception &ex)
{
NODE_LOG("KeepAliveThread")->error()<<FILE_FUN << "ex:" << ex.what() << endl;
TLOGERROR("ServerObject::checkServer ex:" << ex.what() << endl);
}
catch(...)
{
NODE_LOG("KeepAliveThread")->error()<<FILE_FUN << "unknown ex." << endl;
TLOGERROR("ServerObject::checkServer unknown ex." << endl);
}
}
/**
* 属性上报单独出来
*/
void ServerObject::reportMemProperty()
{
#ifdef __APPLE__
//@see: http://stackoverflow.com/questions/1543157/how-can-i-find-out-how-much-memory-my-c-app-is-using-on-the-mac
struct rusage usage;
if(0 == getrusage(RUSAGE_SELF, &usage)) {
REPORT_MAX(_serverId, _serverId+".memsize", (int)usage.ru_maxrss);
NODE_LOG("ReportMemThread")->debug()<<FILE_FUN<<"report_max("<<_serverId<<".memsize,"<<usage.ru_maxrss<<")OK."<<endl;
return;
}
#else
try
{
char sTmp[64] ={0};
snprintf(sTmp,sizeof(sTmp), "%u", _pid);
string spid = string(sTmp);
string filename = "/proc/" + spid + "/statm";
string stream;
stream = TC_File::load2str(filename);
if(!stream.empty())
{
NODE_LOG("ReportMemThread")->debug()<<FILE_FUN<<"filename:"<<filename<<",stream:"<<stream<<endl;
//>>改成上报物理内存
vector<string> vtStatm = TC_Common::sepstr<string>(stream, " ");
if (vtStatm.size() < 2)
{
NODE_LOG("ReportMemThread")->error() <<FILE_FUN<< "cannot get server[" + _serverId + "] physical mem size|stream|" << stream << endl;
}
else
{
stream = vtStatm[1];
}
if(TC_Common::isdigit(stream))
{
REPORT_MAX(_serverId, _serverId+".memsize", TC_Common::strto<int>(stream) * 4);
NODE_LOG("ReportMemThread")->debug()<<FILE_FUN<<"report_max("<<_serverId<<".memsize,"<<TC_Common::strto<int>(stream)*4<<")OK."<<endl;
return;
}
else
{
NODE_LOG("ReportMemThread")->error()<<FILE_FUN<<"stream : "<<stream<<" ,is not a digit."<<endl;
}
}
else
{
NODE_LOG("ReportMemThread")->error()<<FILE_FUN<<"stream is empty: "<<stream<<endl;
}
}
catch(exception &ex)
{
NODE_LOG("ReportMemThread")->error() << FILE_FUN << " ex:" << ex.what() << endl;
TLOGERROR(FILE_FUN << " ex:" << ex.what() << endl);
}
catch(...)
{
NODE_LOG("ReportMemThread")->error() << FILE_FUN << " unknown error" << endl;
TLOGERROR(FILE_FUN << "unknown ex." << endl);
}
#endif
}
void ServerObject::checkCoredumpLimit()
{
if(_state != ServerObject::Active || !_limitStateInfo.bEnableCoreLimit)
{
TLOGINFO(FILE_FUN<<"checkCoredumpLimit:server is inactive or disable corelimit"<<endl);
return;
}
Lock lock(*this);
if(_limitStateInfo.eCoreType == EM_AUTO_LIMIT)
{
bool bNeedClose=false;
int iRet =_serviceLimitResource->IsCoreLimitNeedClose(bNeedClose);
bool bNeedUpdate = (iRet==2)?true:false;
if(_limitStateUpdated && bNeedClose)
{
_limitStateUpdated = setServerCoreLimit(true)?false:true;//设置成功后再屏蔽更新
_limitStateInfo.bCloseCore = bNeedClose;
}
else if(bNeedUpdate && !bNeedClose)
{
setServerCoreLimit(false);
_limitStateInfo.bCloseCore = bNeedClose;
}
}
else
{
if(_limitStateUpdated)
{
_limitStateUpdated = setServerCoreLimit(_limitStateInfo.bCloseCore)?false:true; //设置成功后再屏蔽更新
}
}
}
bool ServerObject::setServerCoreLimit(bool bCloseCore)
{
string sResult = "succ";
const string sCmd = (bCloseCore)?("tars.closecore yes"):("tars.closecore no");
CommandNotify command(this,sCmd);
int iRet = command.doProcess(sResult);
NODE_LOG("KeepAliveThread")->debug()<<FILE_FUN<<"setServerCoreLimit|"<<_serverId<<"|"<<sCmd<<"|"<<sResult<<endl;
return (iRet==0);
}
//服务重启时设置
void ServerObject::setLimitInfoUpdate(bool bUpdate)
{
Lock lock(*this);
_limitStateUpdated = true;
}
//手动配置有更新时调用
void ServerObject::setServerLimitInfo(const ServerLimitInfo& tInfo)
{
Lock lock(*this);
_limitStateInfo = tInfo;
NODE_LOG("KeepAliveThread")->debug() << FILE_FUN << _serverId << "|" << _limitStateInfo.str() << endl;
_serviceLimitResource->setLimitCheckInfo(tInfo.iMaxExcStopCount,tInfo.iCoreLimitTimeInterval,tInfo.iCoreLimitExpiredTime);
_activatorPtr->setLimitInfo(tInfo.iActivatorTimeInterval, tInfo.iActivatorMaxCount, tInfo.iActivatorPunishInterval);
_limitStateUpdated = true;
}
//重置core计数信息
void ServerObject::resetCoreInfo()
{
_serviceLimitResource->resetRunTimeData();
}
void ServerObject::setStarted(bool bStarted)
{
Lock lock(*this);
_started=bStarted;
}
void ServerObject::setStartTime(int64_t iStartTime)
{
Lock lock(*this);
_startTime = iStartTime;
}
Loading...
举报
举报成功
我们将于2个工作日内通过站内信反馈结果给你!
请认真填写举报原因,尽可能描述详细。
请选择举报类型
取消
发送
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

简介

腾讯Tars(TAF)框架OSX平台移植版
取消

发行版

暂无发行版

开源评估指数源自 OSS-Compass 评估体系,评估体系围绕以下三个维度对项目展开评估:

1. 开源生态

  • 生产力:来评估开源项目输出软件制品和开源价值的能力。
  • 创新力:用于评估开源软件及其生态系统的多样化程度。
  • 稳健性:用于评估开源项目面对多变的发展环境,抵御内外干扰并自我恢复的能力。

2. 协作、人、软件

  • 协作:代表了开源开发行为中协作的程度和深度。
  • 人:观察开源项目核心人员在开源项目中的影响力,并通过第三方视角考察用户和开发者对开源项目的评价。
  • 软件:从开源项目对外输出的制品评估其价值最终落脚点。也是开源评估最"古老"的主流方向之一"开源软件" 的具体表现。

3. 评估模型

    基于"开源生态"与"协作、人、软件"的维度,找到与该目标直接或间接相关的可量化指标,对开源项目健康与生态进行量化评估,最终形成开源评估指数。

贡献者

全部

近期动态

不能加载更多了
编辑仓库简介
简介内容
主页
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/cxxjava/Tars.git
git@gitee.com:cxxjava/Tars.git
cxxjava
Tars
Tars
master
点此查找更多帮助

搜索帮助

评论
仓库举报
回到顶部
登录提示
该操作需登录 Gitee 帐号,请先登录后再操作。
立即登录
没有帐号,去注册

AltStyle によって変換されたページ (->オリジナル) /