使用cgo实现高性能WebSocket服务

Go 语言的便捷,协程的高效,GC以及自身的安全性,使得它成为后端业务开发的利器. 之前看过来自 Mail.Ru 工程师分享 Go的百万连接数的WebSocket服务优化 ,*中文翻译版.描述通过使用优化 Go 协程和零拷贝Http Header 实现了对内存的高效利用. 但其中自定义的 epoll 结构中依旧用了锁,个人觉得还是有优化的空间. 可以用高效的 uWebSockets 库配合,使得接入层用高效的 C++ 语言,而后端业务处理则用 Go 语言.这样的好处就是 C++ 可以最高效精准的把控接入层的逻辑处理和内存的使用,而后端的业务开发则是以高效安全为主,使用 Go 正好合适. 这里使用的 uWebSockets 为 0.14.8 tag 的版本,配合 libuv作为事件驱动,zlib 作为压缩算法库,openssl 作为加密库,四个编译为 .a类型的静态库,方便一同编译到程序中,避免运行时动态库缺失的问题. … “使用cgo实现高性能WebSocket服务”

Read More

QT下无法执行C++编译

安装QT完成后,无法执行c++项目的构建: Could not determine which “make” command to run. Check the “make” step in the build configuration. Error while building/deploying project xxx (kit: Desktop Qt 5.10.1 GCC 64bit) When executing step “qmake” 一般以为是qmake或make问题,但其实是C++的编译工具没指定:

Read More

C++ 17的variant和auto的尝试

std::variant 强类型语言的一个特定就是当要使用一个变量时,必须要确定该变量的类型,并且一旦声明后,就不可更改. 但是 C++17 中收录来自 Boost 库的 variant,它通过一系列复杂的模板,绕过了这个规则.当然,如果使用这个类型,性能会存在些微的损失: variant v, w; v = 12; int i = get(v); w = get(v); w = get(v); // same effect as the previous line w = v; // … “C++ 17的variant和auto的尝试”

Read More

C# .net core XmlDocument 使用Load和Save方法

代码: string path =”C://xxx/file” XmlDocument xmlDoc = new XmlDocument(); #if NET462 xmlDoc.Load(path); #else string content = File.ReadAllText(path); xmlDoc.LoadXml(content.Trim()); #endif …… …… #if NET462 xmlDoc.Save(path); #else FileStream fs = new FileStream(path, FileMode.Create); XmlWriterSettings settings = new … “C# .net core XmlDocument 使用Load和Save方法”

Read More

asp.net core设置默认起始页Default Page和重定向

用Asp.Net Core的网站Deploy至IIS,因此找了下,发现两种方法: 添加引用 using System.Threading.Tasks; using Microsoft.AspNetCore.Builder; using Microsoft.Extensions.Logging; 1.设置默认起始页 2.重定向到起始页 1.设置默认起始页 在 startup.cs中的Configure(IApplicationBuilder app, IHostingEnvironment env,ILoggerFactory logger)方法中加入: DefaultFilesOptions options = new DefaultFilesOptions(); options.DefaultFileNames.Add(“index.html”); //将index.html改为需要默认起始页的文件名. app.UseDefaultFiles(options); app.UseStaticFiles(); 2.重定向到起始页 同样在startup.cs中的Configure(IApplicationBuilder app, IHostingEnvironment env,ILoggerFactory logger)方法中加入: app.UseStaticFiles(); app.Run(ctx … “asp.net core设置默认起始页Default Page和重定向”

Read More

C#关闭MSBuild Warning警告信息

通常一个大项目,无论使用那种语言,总会有warning警告信息。有些语言比如C/C++的警告最好别忽略,因为C语言一不小心就能让你进坑里,但是有些语言的警告却并不是那么要紧,比如C#。 使用C#的大项目很多,本地调试编译可以在VS中设置,但是用CI的时候那就只能调用MSBuild命令行进行编译,这时候输出会有一大堆警告。 其实MSBuild可以加参数来屏蔽警告,有两种方式: 1.使用/p:nowarn=1591可以屏蔽CS1591警告信息.如果要同时指定屏蔽多个,可以这样/p:nowarn=”105,1591,1572,1573″ 2.使用/p:WarningLevel=0可以屏蔽所有警告.WarningLevel的分级信息如下: 0 Turns off emission of all warning messages. 1 Displays severe warning messages 2 Displays level 1 warnings plus certain, less-severe warnings, such as warnings about hiding class members 3 … “C#关闭MSBuild Warning警告信息”

Read More

C# .net core 解决ToLower中缺少CultureInfo格式重载

使用AppendFormat即可. 代码: var builder = new StringBuilder(); //.net framework下ToLower方法存在CultureInfo的重载方法. //builder.Append(entry.Key.ToLower(CultureInfo.InvariantCulture)); //.net core 下没有实现该重载,使用AppendFormat方法或者string.Format builder.AppendFormat(CultureInfo.InvariantCulture, “{0}”, entry.Key.ToLower());

Read More

C# .net core 使用DataContractJsonSerializer

.net core1.1,去掉了对该方法的支持只需添加依赖包, 不过在github的issue中说是2.0将会支持。 添加依赖包System.Runtime.Serialization.Json即可。 参考: – REST client – DataContractJsonSerializer failing in Microsoft.NetCore.UniversalWindowsPlatform – which nuget package I should add in my json file to use System.Serializable attribute?

Read More