Microsoft MVP성태의 닷넷 이야기
디버깅 기술: 84. NopCommerce의 Autofac 부하(CPU, Memory) [링크 복사], [링크+제목 복사]
조회: 16471
글쓴 사람
정성태 (techsharer at outlook.com)
홈페이지
첨부 파일
 

NopCommerce의 Autofac 부하(CPU, Memory)

정확한 원인 분석은 아니지만, 하나의 현상이라고 기록해 둘 만한 것 같습니다.

언제부터인지는 모르겠지만 근래 NopCommerce는,

Open-source & FREE e-commerce solution: NopCommerce
; http://www.nopcommerce.com/

내부적으로 DI Container로 Autofac을 사용하고 있습니다.

Autofac - is an addictive Inversion of Control container for .NET Core, ASP.NET Core, .NET 4.5.1+, Universal Windows apps, and more.
; https://autofac.org/

그런데, 지인이 테스트하는 서버에서 CPU 사용량이 너무 높다면서 문의를 해왔습니다. 환경은, x64 .NET 4.0이었고 단지 테스트 서버이다 보니 메모리가 4GB로 낮았습니다. 2개의 테스트용 NopCommerce 사이트를 구동하면 각각 2GB 이상의 private 메모리를 차지하면서 CPU 100% 현상이 발생했습니다.

이때의 스레드 상황을 Process Explorer로 보면 다음과 같습니다.

high_mem_nopcomm_1.png

"clr.dll!InstallCustomModule" 항목이 눈에 띄는데요. 이런 항목이 있는 스레드 2개를 살펴보니 하나같이 "Autofac.dll"의 콜 스택이 보였습니다.

clr.dll+0x1f30
[Managed to Unmanaged Transition]
Nop.Services.dll!Nop.Services.Configuration.SettingService.LoadSetting+0x144
Autofac.dll!<>c__DisplayClass1`1.<ForDelegate>b__0+0x10
Autofac.dll!Autofac.Core.Activators.Delegate.DelegateActivator.ActivateInstance+0x20
Autofac.dll!Autofac.Core.Resolving.InstanceLookup.Activate+0x56
Autofac.dll!Autofac.Core.Lifetime.LifetimeScope.GetOrCreateAndShare+0x80
Autofac.dll!Autofac.Core.Resolving.InstanceLookup.Execute+0xb6
Autofac.dll!Autofac.Core.Resolving.ResolveOperation.GetOrCreateInstance+0xaa
Autofac.dll!Autofac.Core.Activators.Reflection.ConstructorParameterBinding.Instantiate+0x7d
Autofac.dll!Autofac.Core.Activators.Reflection.ReflectionActivator.ActivateInstance+0x106
Autofac.dll!Autofac.Core.Resolving.InstanceLookup.Activate+0x56
Autofac.dll!Autofac.Core.Lifetime.LifetimeScope.GetOrCreateAndShare+0x80
Autofac.dll!Autofac.Core.Resolving.InstanceLookup.Execute+0xb6
Autofac.dll!Autofac.Core.Resolving.ResolveOperation.GetOrCreateInstance+0xaa
Autofac.dll!Autofac.Core.Activators.Reflection.ConstructorParameterBinding.Instantiate+0x7d
Autofac.dll!Autofac.Core.Activators.Reflection.ReflectionActivator.ActivateInstance+0x106
Autofac.dll!Autofac.Core.Resolving.InstanceLookup.Activate+0x56
Autofac.dll!Autofac.Core.Lifetime.LifetimeScope.GetOrCreateAndShare+0x80
Autofac.dll!Autofac.Core.Resolving.InstanceLookup.Execute+0xb6
Autofac.dll!Autofac.Core.Resolving.ResolveOperation.GetOrCreateInstance+0xaa
Autofac.dll!Autofac.Core.Activators.Reflection.ConstructorParameterBinding.Instantiate+0x7d
Autofac.dll!Autofac.Core.Activators.Reflection.ReflectionActivator.ActivateInstance+0x106
Autofac.dll!Autofac.Core.Resolving.InstanceLookup.Activate+0x56
Autofac.dll!Autofac.Core.Lifetime.LifetimeScope.GetOrCreateAndShare+0x80
Autofac.dll!Autofac.Core.Resolving.InstanceLookup.Execute+0xb6
Autofac.dll!Autofac.Core.Resolving.ResolveOperation.GetOrCreateInstance+0xaa
Autofac.dll!Autofac.Core.Resolving.ResolveOperation.Execute+0x1e
Autofac.dll!Autofac.ResolutionExtensions.TryResolveService+0x7a
Autofac.dll!Autofac.ResolutionExtensions.ResolveService+0x46
Autofac.dll!Autofac.ResolutionExtensions.Resolve+0x3d
Nop.Web.dll!Nop.Web.MvcApplication.SetWorkingCulture+0x171
System.Web.dll!SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute+0x95
System.Web.dll!System.Web.HttpApplication.ExecuteStep+0x62
System.Web.dll!PipelineStepManager.ResumeSteps+0x4fd
System.Web.dll!System.Web.HttpApplication.BeginProcessRequestNotification+0x70
System.Web.dll!System.Web.HttpRuntime.ProcessRequestNotificationPrivate+0x17b
System.Web.dll!System.Web.Hosting.PipelineRuntime.ProcessRequestNotificationHelper+0x380
System.Web.dll!System.Web.Hosting.PipelineRuntime.ProcessRequestNotification+0x14
[Unmanaged to Managed Transition]
[Native Frame: IL Method without Metadata]
clr.dll+0x21fe
webengine4.dll!MgdGetCurrentNotificationInfo+0x13f
webengine4.dll!RegisterModule+0x3f72
webengine4.dll!PerfIncrementGlobalCounter+0x113
webengine4.dll!MgdWebSocketWriteFragment+0x3df
iiscore.dll+0xd3a9
iiscore.dll+0xcd4c
iiscore.dll+0xcb96
iiscore.dll+0xdeeb
iiscore.dll+0x7926
webengine4.dll!STRU::Unescape+0x501
webengine4.dll!MgdIndicateCompletion+0x22
[Native Frame: IL Method without Metadata]
[Managed to Unmanaged Transition]
System.Web.dll!System.Web.Hosting.PipelineRuntime.ProcessRequestNotificationHelper+0x45c
System.Web.dll!System.Web.Hosting.PipelineRuntime.ProcessRequestNotification+0x14
[Unmanaged to Managed Transition]
[Native Frame: IL Method without Metadata]
clr.dll+0x2453
clr.dll!GetMetaDataPublicInterfaceFromInternal+0x5001a
[Managed to Unmanaged Transition]
[AppDomain Transition]
[Unmanaged to Managed Transition]
clr.dll!DllCanUnloadNowInternal+0x5004
clr.dll!GetMetaDataPublicInterfaceFromInternal+0x500c5
clr.dll+0x23fd
webengine4.dll!MgdGetCurrentNotificationInfo+0x13f
webengine4.dll!MgdGetCurrentNotificationInfo+0x92
clr.dll!DllCanUnloadNowInternal+0x43db
clr.dll!DllCanUnloadNowInternal+0x1e9c
clr.dll!DllCanUnloadNowInternal+0x1bc5
clr.dll!InstallCustomModule+0x1c7f
KERNEL32.DLL!BaseThreadInitThunk+0x14
ntdll.dll!RtlUserThreadStart+0x21

clr.dll+0x1f30
[Managed to Unmanaged Transition]
Nop.Services.dll!Nop.Services.Configuration.SettingService.LoadSetting+0x144
Autofac.dll!<>c__DisplayClass1`1.<ForDelegate>b__0+0x10
Autofac.dll!Autofac.Core.Activators.Delegate.DelegateActivator.ActivateInstance+0x20
Autofac.dll!Autofac.Core.Resolving.InstanceLookup.Activate+0x56
Autofac.dll!Autofac.Core.Lifetime.LifetimeScope.GetOrCreateAndShare+0x80
Autofac.dll!Autofac.Core.Resolving.InstanceLookup.Execute+0xb6
Autofac.dll!Autofac.Core.Resolving.ResolveOperation.GetOrCreateInstance+0xaa
Autofac.dll!Autofac.Core.Activators.Reflection.ConstructorParameterBinding.Instantiate+0x7d
Autofac.dll!Autofac.Core.Activators.Reflection.ReflectionActivator.ActivateInstance+0x106
Autofac.dll!Autofac.Core.Resolving.InstanceLookup.Activate+0x56
Autofac.dll!Autofac.Core.Lifetime.LifetimeScope.GetOrCreateAndShare+0x80
Autofac.dll!Autofac.Core.Resolving.InstanceLookup.Execute+0xb6
Autofac.dll!Autofac.Core.Resolving.ResolveOperation.GetOrCreateInstance+0xaa
Autofac.dll!Autofac.Core.Activators.Reflection.ConstructorParameterBinding.Instantiate+0x7d
Autofac.dll!Autofac.Core.Activators.Reflection.ReflectionActivator.ActivateInstance+0x106
Autofac.dll!Autofac.Core.Resolving.InstanceLookup.Activate+0x56
Autofac.dll!Autofac.Core.Lifetime.LifetimeScope.GetOrCreateAndShare+0x80
Autofac.dll!Autofac.Core.Resolving.InstanceLookup.Execute+0xb6
Autofac.dll!Autofac.Core.Resolving.ResolveOperation.GetOrCreateInstance+0xaa
Autofac.dll!Autofac.Core.Activators.Reflection.ConstructorParameterBinding.Instantiate+0x7d
Autofac.dll!Autofac.Core.Activators.Reflection.ReflectionActivator.ActivateInstance+0x106
Autofac.dll!Autofac.Core.Resolving.InstanceLookup.Activate+0x56
Autofac.dll!Autofac.Core.Lifetime.LifetimeScope.GetOrCreateAndShare+0x80
Autofac.dll!Autofac.Core.Resolving.InstanceLookup.Execute+0xb6
Autofac.dll!Autofac.Core.Resolving.ResolveOperation.GetOrCreateInstance+0xaa
Autofac.dll!Autofac.Core.Resolving.ResolveOperation.Execute+0x1e
Autofac.dll!Autofac.ResolutionExtensions.TryResolveService+0x7a
Autofac.dll!Autofac.ResolutionExtensions.ResolveService+0x46
Autofac.dll!Autofac.ResolutionExtensions.Resolve+0x3d
Nop.Web.dll!Nop.Web.MvcApplication.SetWorkingCulture+0x171
System.Web.dll!SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute+0x95
System.Web.dll!System.Web.HttpApplication.ExecuteStep+0x62
System.Web.dll!PipelineStepManager.ResumeSteps+0x4fd
System.Web.dll!System.Web.HttpApplication.BeginProcessRequestNotification+0x70
System.Web.dll!System.Web.HttpRuntime.ProcessRequestNotificationPrivate+0x17b
System.Web.dll!System.Web.Hosting.PipelineRuntime.ProcessRequestNotificationHelper+0x380
System.Web.dll!System.Web.Hosting.PipelineRuntime.ProcessRequestNotification+0x14
[Unmanaged to Managed Transition]
[Native Frame: IL Method without Metadata]
clr.dll+0x21fe
webengine4.dll!MgdGetCurrentNotificationInfo+0x13f
webengine4.dll!RegisterModule+0x3f72
webengine4.dll!PerfIncrementGlobalCounter+0x113
webengine4.dll!MgdWebSocketWriteFragment+0x3df
iiscore.dll+0xd3a9
iiscore.dll+0xcd4c
iiscore.dll+0xcb96
iiscore.dll+0xdeeb
iiscore.dll+0x7926
webengine4.dll!STRU::Unescape+0x501
webengine4.dll!MgdIndicateCompletion+0x22
[Native Frame: IL Method without Metadata]
[Managed to Unmanaged Transition]
System.Web.dll!System.Web.Hosting.PipelineRuntime.ProcessRequestNotificationHelper+0x45c
System.Web.dll!System.Web.Hosting.PipelineRuntime.ProcessRequestNotification+0x14
[Unmanaged to Managed Transition]
[Native Frame: IL Method without Metadata]
clr.dll+0x2453
clr.dll!GetMetaDataPublicInterfaceFromInternal+0x5001a
[Managed to Unmanaged Transition]
[AppDomain Transition]
[Unmanaged to Managed Transition]
clr.dll!DllCanUnloadNowInternal+0x5004
clr.dll!GetMetaDataPublicInterfaceFromInternal+0x500c5
clr.dll+0x23fd
webengine4.dll!MgdGetCurrentNotificationInfo+0x13f
webengine4.dll!MgdGetCurrentNotificationInfo+0x92
clr.dll!DllCanUnloadNowInternal+0x43db
clr.dll!DllCanUnloadNowInternal+0x1e9c
clr.dll!DllCanUnloadNowInternal+0x1bc5
clr.dll!InstallCustomModule+0x1c7f
KERNEL32.DLL!BaseThreadInitThunk+0x14
ntdll.dll!RtlUserThreadStart+0x21

이걸 보니, Ninject DI 프레임워크의 성능 분석 사례가 떠오르더군요. ^^

제니퍼 닷넷 - Ninject DI 프레임워크의 성능 분석
; https://www.sysnet.pe.kr/2/0/1299

Autofac을 어떻게 적용했는지는 구체적으로 살펴보지는 않았지만, 암튼 nopCommerce 측의 적용에 문제가 있는 것이 아닌가 생각됩니다.




[이 글에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]







[최초 등록일: ]
[최종 수정일: 7/10/2021]

Creative Commons License
이 저작물은 크리에이티브 커먼즈 코리아 저작자표시-비영리-변경금지 2.0 대한민국 라이센스에 따라 이용하실 수 있습니다.
by SeongTae Jeong, mailto:techsharer at outlook.com

비밀번호

댓글 작성자
 



2016-12-28 02시38분
[ryujh] 안녕하세요.

내용 중에 '내부적으로 DI Container로 Autofac을 사용하고 있습니다' 이렇다면 NopCommerce 에 포함되었다는 것인데
NopCommerce 에서 Autofac 을 분리 가능한지 문의합니다. 소스 수정이 필요하다면 DI Container 를 사용하기 위해 소스 수정 작업이 더해지는 결과인데 DI 의 이점이 충분히 큰지요?

DI 사용해본 적없고 소스 수정 작업만 걱정하다보니 이런 질문하는군요. 감사합니다.
[guest]
2016-12-30 01시31분
글쎄요. 그 질문은 NopCommerce 측에 하시는 것이 더 좋지 않을까요? ^^
정성태

... 46  47  48  49  50  51  52  53  54  55  56  57  [58]  59  60  ...
NoWriterDateCnt.TitleFile(s)
12166정성태3/4/202011017개발 환경 구성: 470. Windows Server 컨테이너 - DockerMsftProvider 모듈을 이용한 docker 설치
12165정성태3/2/202010677.NET Framework: 900. 실행 시에 메서드 가로채기 - CLR Injection: Runtime Method Replacer 개선 - 네 번째 이야기(Monitor.Enter 후킹)파일 다운로드1
12164정성태2/29/202011525오류 유형: 598. Surface Pro 6 - Windows Hello Face Software Device가 인식이 안 되는 문제
12163정성태2/27/20209932.NET Framework: 899. 익명 함수를 가리키는 delegate 필드에 대한 직렬화 문제
12162정성태2/26/202012707디버깅 기술: 166. C#에서 만든 COM 객체를 C/C++로 P/Invoke Interop 시 메모리 누수(Memory Leak) 발생 [6]파일 다운로드2
12161정성태2/26/20209393오류 유형: 597. manifest - The value "x64" of attribute "processorArchitecture" in element "assemblyIdentity" is invalid.
12160정성태2/26/202010094개발 환경 구성: 469. Reg-free COM 개체 사용을 위한 manifest 파일 생성 도구 - COMRegFreeManifest
12159정성태2/26/20208305오류 유형: 596. Visual Studio - The project needs to include ATL support
12158정성태2/25/202010093디버깅 기술: 165. C# - Marshal.GetIUnknownForObject/GetIDispatchForObject 사용 시 메모리 누수(Memory Leak) 발생파일 다운로드1
12157정성태2/25/20209927디버깅 기술: 164. C# - Marshal.GetNativeVariantForObject 사용 시 메모리 누수(Memory Leak) 발생 및 해결 방법파일 다운로드1
12156정성태2/25/20209303오류 유형: 595. LINK : warning LNK4098: defaultlib 'nafxcw.lib' conflicts with use of other libs; use /NODEFAULTLIB:library
12155정성태2/25/20208626오류 유형: 594. Warning NU1701 - This package may not be fully compatible with your project
12154정성태2/25/20208504오류 유형: 593. warning LNK4070: /OUT:... directive in .EXP differs from output filename
12153정성태2/23/202011135.NET Framework: 898. Trampoline을 이용한 후킹의 한계파일 다운로드1
12152정성태2/23/202010847.NET Framework: 897. 실행 시에 메서드 가로채기 - CLR Injection: Runtime Method Replacer 개선 - 세 번째 이야기(Trampoline 후킹)파일 다운로드1
12151정성태2/22/202011422.NET Framework: 896. C# - Win32 API를 Trampoline 기법을 이용해 C# 메서드로 가로채는 방법 - 두 번째 이야기 (원본 함수 호출)파일 다운로드1
12150정성태2/21/202011261.NET Framework: 895. C# - Win32 API를 Trampoline 기법을 이용해 C# 메서드로 가로채는 방법 [1]파일 다운로드1
12149정성태2/20/202011009.NET Framework: 894. eBEST C# XingAPI 래퍼 - 연속 조회 처리 방법 [1]
12148정성태2/19/202012163디버깅 기술: 163. x64 환경에서 구현하는 다양한 Trampoline 기법 [1]
12147정성태2/19/202010818디버깅 기술: 162. x86/x64의 기계어 코드 최대 길이
12146정성태2/18/202011126.NET Framework: 893. eBEST C# XingAPI 래퍼 - 로그인 처리파일 다운로드1
12145정성태2/18/202010349.NET Framework: 892. eBEST C# XingAPI 래퍼 - Sqlite 지원 추가파일 다운로드1
12144정성태2/13/202010339.NET Framework: 891. 실행 시에 메서드 가로채기 - CLR Injection: Runtime Method Replacer 개선 - 두 번째 이야기파일 다운로드1
12143정성태2/13/20208493.NET Framework: 890. 상황별 GetFunctionPointer 반환값 정리 - x64파일 다운로드1
12142정성태2/12/202010193.NET Framework: 889. C# 코드로 접근하는 MethodDesc, MethodTable파일 다운로드1
12141정성태2/10/20209856.NET Framework: 888. C# - ASP.NET Core 웹 응용 프로그램의 출력 가로채기 [2]파일 다운로드1
... 46  47  48  49  50  51  52  53  54  55  56  57  [58]  59  60  ...