cim

一致性 Hash 算法的实际应用

五迷三道 提交于 2020-04-06 21:50:50
前言 记得一年前分享过一篇 《一致性 Hash 算法分析》 ,当时只是分析了这个算法的实现原理、解决了什么问题等。 但没有实际实现一个这样的算法,毕竟要加深印象还得自己撸一遍,于是本次就当前的一个路由需求来着手实现一次。 背景 看过 《为自己搭建一个分布式 IM(即时通讯) 系统》 的朋友应该对其中的登录逻辑有所印象。 先给新来的朋友简单介绍下 cim 是干啥的: 其中有一个场景是在客户端登录成功后需要从可用的服务端列表中选择一台服务节点返回给客户端使用。 而这个选择的过程就是一个负载策略的过程;第一版本做的比较简单,默认只支持轮询的方式。 虽然够用,但不够优雅😏。 因此我的规划是内置多种路由策略供使用者根据自己的场景选择,同时提供简单的 API 供用户自定义自己的路由策略。 先来看看一致性 Hash 算法的一些特点: 构造一个 0 ~ 2^32-1 大小的环。 服务节点经过 hash 之后将自身存放到环中的下标中。 客户端根据自身的某些数据 hash 之后也定位到这个环中。 通过顺时针找到离他最近的一个节点,也就是这次路由的服务节点。 考虑到服务节点的个数以及 hash 算法的问题导致环中的数据分布不均匀时引入了虚拟节点。 自定义有序 Map 根据这些客观条件我们很容易想到通过自定义一个 有序 数组来模拟这个环。 这样我们的流程如下: 初始化一个长度为 N 的数组。

Convert WMI call to CIM call

六月ゝ 毕业季﹏ 提交于 2019-12-11 10:45:50
问题 The code I am writing is suppose to kick off any patches currently available to a server using CIM. And I have to use CIM due to the required DCOM protocol for my network. I'm using ` for easier viewing The following wmi code works: $ComputerName = 'Foo' [System.Management.ManagementObject[]] $CMMissingUpdates = @(` Get-WmiObject -ComputerName $ComputerName ` -Query "SELECT * FROM CCM_SoftwareUpdate WHERE ComplianceState = '0'" ` -Namespace "ROOT\ccm\ClientSDK" ` -ErrorAction Stop) $null =

What Library for Powershell 6 contains the get-wmiobject command?

穿精又带淫゛_ 提交于 2019-12-03 22:06:38
问题 I am getting the following error upon attempting to use the get-WmiObject command in PowerShell (version 6): PS C:\Users\zsofi> Get-WmiObject Win32_product | select name, packagecache Get-WmiObject : The term 'Get-WmiObject' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At line:1 char:1 + Get-WmiObject Win32_product | select name, packagecache + ~~

What Library for Powershell 6 contains the get-wmiobject command?

末鹿安然 提交于 2019-12-01 00:27:36
I am getting the following error upon attempting to use the get-WmiObject command in PowerShell (version 6): PS C:\Users\zsofi> Get-WmiObject Win32_product | select name, packagecache Get-WmiObject : The term 'Get-WmiObject' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At line:1 char:1 + Get-WmiObject Win32_product | select name, packagecache + ~~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (Get-WmiObject:String) [], CommandNotFoundException +

延迟实现

﹥>﹥吖頭↗ 提交于 2019-11-30 18:07:19
前言 近期在维护公司的调度平台,其中有个关键功能那就是定时任务;定时任务大家平时肯定接触的不少,比如 JDK 中的 Timer 、 ScheduledExecutorService 、调度框架 Quartz 等。 通常用于实现 XX 时间后的延时任务,或周期性任务; 比如一个常见的业务场景:用户下单 N 分钟未能支付便自动取消订单。 实现这类需求通常有两种方式: 轮询定时任务:给定周期内扫描所有未支付的订单,查看时间是否到期。 延时消息:订单创建的时候发送一条 N 分钟到期的信息,一旦消息消费后便可判断订单是否可以取消。 先看第一种,这类方式实现较为简单,只需要启动一个定时任务即可;但缺点同样也很明显,这个间隔扫描的时间不好控制。 给短了会造成很多无意义的扫描,增大数据库压力,给长了又会使得误差较大。 当然最大的问题还是效率较低,随着订单增多耗时会呈线性增长,最差的情况甚至会出现上一波轮询还没有扫描完,下一波调度又来了。 这时第二种方案就要显得靠谱多了,通过延时消息可以去掉不必要的订单扫描,实时性也比较高。 延时消息 这里我们不过多讨论这类需求如何实现;重点聊聊这个延时消息,看它是如何实现的,基于实现延时消息的数据结构还能实现定时任务。 我在之前的开源 IM 项目中也加入了此类功能,可以很直观的发送一条延时消息,效果如下: 使用 :delay hahah 2

Objects with no '.Count' Property - use of @() (array subexpression operator) vs. [Array] cast

送分小仙女□ 提交于 2019-11-29 07:21:12
I am trying to perform some simple if statements, but all of the newer cmdlets that are based upon [Microsoft.Management.Infrastructure.CimInstance] don't seem to expose a .count method? $Disks = Get-Disk $Disks.Count Doesn't return anything. I found that I can cast this as an [array], which makes it returns a .NET .count method as expected. [Array]$Disks = Get-Disk $Disks.Count This works without directly casting it as an array for previous cmdlets: (Get-Services).Count What is the recommended way to get around this? An example that doesn't work: $PageDisk = Get-Disk | Where {($_.IsBoot -eq

Dealing with CimObjects with PowerShell inside C#

為{幸葍}努か 提交于 2019-11-28 14:23:25
I have a snippet that executes a PowerShell script using (var ps = PowerShell.Create()) { ps.AddScript("function Test() { return Get-Disk -Number 0 } "); ps.Invoke(); ps.AddCommand("Test"); var results = ps.Invoke(); var disk = results.First(); MyDisk myDisk = // do something to convert disk to myDisk } Debuggin, it get his inside disk : How I'm supposed to deal with this object ( CimObject )? I would like to get the values from the "Name" and "Number" properties. Just to clarify, the object I'm trying to deal is the same type as this (run into PowerShell as admin) PS C:\windows\system32>

Objects with no '.Count' Property - use of @() (array subexpression operator) vs. [Array] cast

十年热恋 提交于 2019-11-28 00:58:58
问题 I am trying to perform some simple if statements, but all of the newer cmdlets that are based upon [Microsoft.Management.Infrastructure.CimInstance] don't seem to expose a .count method? $Disks = Get-Disk $Disks.Count Doesn't return anything. I found that I can cast this as an [array], which makes it returns a .NET .count method as expected. [Array]$Disks = Get-Disk $Disks.Count This works without directly casting it as an array for previous cmdlets: (Get-Services).Count What is the

Dealing with CimObjects with PowerShell inside C#

北战南征 提交于 2019-11-27 08:47:25
问题 I have a snippet that executes a PowerShell script using (var ps = PowerShell.Create()) { ps.AddScript("function Test() { return Get-Disk -Number 0 } "); ps.Invoke(); ps.AddCommand("Test"); var results = ps.Invoke(); var disk = results.First(); MyDisk myDisk = // do something to convert disk to myDisk } Debuggin, it get his inside disk : How I'm supposed to deal with this object ( CimObject )? I would like to get the values from the "Name" and "Number" properties. Just to clarify, the object