https://youtu.be/dLOJ_-JUpho
visitor pattern 으로 짠 sql parser
sql css 에서 가져왔는데....어디인지 링크를 잊어버림....잘 찾아보면 있을겁니다.
using Microsoft.SqlServer.TransactSql.ScriptDom;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
class TSqlNormalizerSingle
{
static string hashValue;
//public static string Normalize(MemoryStream input, int compatLevel, bool caseSensitive)
public static string Normalize(string input, int compatLevel, bool caseSensitive)
{
TextReader rdr = new StringReader(input);
TSqlParser parser;
SqlScriptGenerator scrgen = null;
#region a
switch (compatLevel)
{
case 80:
{
scrgen = new Sql80ScriptGenerator();
parser = new TSql80Parser(true);
break;
}
case 90:
{
scrgen = new Sql90ScriptGenerator();
parser = new TSql90Parser(true);
break;
}
case 100:
{
scrgen = new Sql100ScriptGenerator();
parser = new TSql100Parser(true);
break;
}
case 110:
{
scrgen = new Sql110ScriptGenerator();
parser = new TSql110Parser(true);
break;
}
default:
{
return "Invalid compatibility level specified; exiting.";
}
}
#endregion a
IList<ParseError> errs;
TSqlFragment frag = parser.Parse(rdr, out errs);
foreach (ParseError err in errs)
{
//Console.WriteLine(err.Message);
if (err.Message.Length > 1)
return "query_hash_error";
}
foreach (var batch in (frag as TSqlScript).Batches)
{
myvisitor visit = new myvisitor();
StringBuilder origscript = new StringBuilder();
for (int tokIdx = batch.FirstTokenIndex; tokIdx <= batch.LastTokenIndex; tokIdx++)
{
origscript.Append(batch.ScriptTokenStream[tokIdx].Text);
}
batch.Accept(visit);
string script;
scrgen.GenerateScript(batch, out script);
using (var hashProvider = new SHA1CryptoServiceProvider())
{
if (caseSensitive)
{
hashValue = Convert.ToBase64String(hashProvider.ComputeHash(Encoding.Unicode.GetBytes(script)));
}
else
{
hashValue = Convert.ToBase64String(hashProvider.ComputeHash(Encoding.Unicode.GetBytes(script.ToLowerInvariant())));
}
}
}
return hashValue;
}
}
NUMA Group Size Optimization
[문제]
ProLiant DL360 Gen9 에서 OS에서는 24 Core 를 인식하는데,
SQL Server 2008 에서 12개의 Core만 사용해 원인 분석이 필요함
[분석결과]
sql server 2008 의 경우 processor group 을 인식하지 못한다.
windows server 의 경우 processer group 을 인식할 경우, 64개 이하는 1개의 그룹에 할당한다. (group 0)
sysinternals 의 coreinfo를 이용해 셋팅 상태를 확인해 보니
group이 2개 생성되어 있으며, group 0번에 12개 할당되고 group 1 에 12개가 할당되어 있음
결과적으로 sql server 2008 은 processor group 0번만 인식해 12개의 core만 인식하는 경우임
[문제의 해결]
HP Server bios 에서 NUMA Group Size Optimization 을 clustered -> flat 으로 변경한다.
NUMA Group Size Optimization
Use this option to configure how the system ROM reports the number of logical processors in a NUMA (Non-Uniform Memory Access) node. The resulting information helps the operating system group processors for application use. To set NUMA Group Size Optimization:
3.Press F10 to save your selection. |
[삽질]
sql server error log
2015-10-06 20:10:55.040 서버 Detected 12 CPUs. This is an informational message; no user action is required.
2015-10-06 20:10:55.180 서버 Node configuration: node 0: CPU mask: 0x0000000000000fff Active CPU mask: 0x0000000000000fff. This message provides a description of the NUMA configuration for this computer. This is an informational message only. No user action is required.
env
windows 2008 r2 ee <-- (processor group 인식 windows 20008 은 processor group 인식 못함)
sql server 2008 se <-- (processor group 인식 못함)
sql 2008 se spec
Maximum number of processors supported by the editon
processor 4개 까지 지원 (sql 2008 r2 의 경우 메모리를 64GB 까지만 지원하게 됨)
https://msdn.microsoft.com/en-us/library/ms143760(v=sql.100).aspx
think....
전체 24개의 코어가 있는데 전체의 반만 인식하는 현상이 있음..기본적으로 processor group 은 윈도우에서 64개 이하의 코어가 있을때 그룹을 나주지 않는다 (Group 0 로 할당함) 24개 미만의 코어만 있으므로 processor group 에 영향이 없을것이라 처음에 생각함.... 그래도 반만 인식하는것이 이상해 core인식 정보를 확인할 필요가 있었음 (coreinfo sysinternals.com -> core 정보를 아주 자세히 나타내 준다. numa node 간 latency 나 processor group 이나 HT, level 별 cache 사이즈 등을 알 수 있음)
coreinfo 조사결과
Logical Processor to Group Map:
Group 0:
************------------
Group 1:
------------************
ref
sql 버전별 한계 검색
https://msdn.microsoft.com/en-us/library/ms143685(v=sql.100).aspx
processor group 개념
https://msdn.microsoft.com/en-us/library/dd405503(VS.85).aspx
processor group test
https://msdn.microsoft.com/en-us/library/windows/hardware/jj123528.aspx
haswell core 정보
http://ark.intel.com/ko/products/81709/Intel-Xeon-Processor-E5-2670-v3-30M-Cache-2_30-GHz
haswell core datasheet
http://www.intel.com/content/www/us/en/processors/xeon/xeon-e5-v3-datasheet-vol-1.html
sql 2008 uses half the cpu's
http://blog.calvett.co.uk/2012/07/06/sql-server-2008-uses-half-the-cpu-s/
why can't i sett the correct number of physical processors when i query sys.dm_os_sys_info in sql server 2008
hp server proliant DL360 Gen8 vs IBM x3850 X5 ==> numa processor group usage
processor 라이선스와, 메모리 제약이 없는 sql 이 필요하다면 sql 2008을 쓰면서 좋은 core 가 있는 서버를 선택하면 좋을겁니다. sql 2008 r2 se 는 processor group 을 인식하나 64GB 메모리 제약이 있음
http://h20564.www2.hpe.com/hpsc/doc/public/display?docId=emr_na-c04650594&sp4ts.oid=7500985
- end -