timeit

实时监控服务器某个端口状态TCPing

北城余情 提交于 2021-01-09 12:19:00
在给客户做运维服务期间,发现了一个奇怪的现象:备份系统(第三方国产)告警日志显示,每天晚上备份服务器的客户端在3点左右离线然后上线,再离线再上线,每晚两次,很是诡异。 联系了厂家技术支持,前后花了两天时间也没给出个答案,一会让我测试网络是否连接正常,一会让我重启客户端服务试试,最终不了了之,很不专业,体验极差。 我通过长ping生成日志,发现在3点左右网络是正常的,没有出现丢包现象。 思索着既然网络没有问题,查看系统日志在3点左右没任何异常日志,就猜测是不是端口异常,如何实时监听要做备份的客户端跟备份服务器制定端口连接情况?网上搜索了很久找到了TCPing这个工具,很好用。做个记录,也分享给大家。 Windows版本下载地址:https://elifulkerson.com/projects/tcping.php 参数如下: NAME tcping - simulate "ping" over tcp by establishing a connection to network hosts. Measures the time for your system to [SYN], receive the target's [SYN][ACK] and send [ACK]. Note that the travel time for the last ACK is not

Codeforces 1099F

孤人 提交于 2020-12-28 08:04:56
题目链接: https://codeforces.com/problemset/problem/1099/F Mitya and Vasya are playing an interesting game. They have a rooted tree with $n$ vertices, and the vertices are indexed from $1$ to $n$. The root has index $1$. Every other vertex $i≥2$ has its parent $p_i$, and vertex $i$ is called a child of vertex $p_i$. There are some cookies in every vertex of the tree: there are $x_i$ cookies in vertex $i$. It takes exactly $t_i$ time for Mitya to eat one cookie in vertex $i$. There is also a chip, which is initially located in the root of the tree, and it takes $l_i$ time to move the chip along the

Decorator for timeit.timeit method?

China☆狼群 提交于 2020-12-01 07:45:25
问题 I'm trying to write a simple time decorator to measure time taken by functions. However the code below is giving our recursion error. What's wrong with it? import timeit def measure(func): def wrapper(): func_name = func.__name__ setup="from __main__ import {}".format(func_name) op_time = timeit.timeit('{}()'.format(func_name), number = 2, setup=setup) print(ot) return wrapper @measure def sample(): return 10 sample() Output RecursionError Traceback (most recent call last) <ipython-input-61

Decorator for timeit.timeit method?

谁都会走 提交于 2020-12-01 07:45:06
问题 I'm trying to write a simple time decorator to measure time taken by functions. However the code below is giving our recursion error. What's wrong with it? import timeit def measure(func): def wrapper(): func_name = func.__name__ setup="from __main__ import {}".format(func_name) op_time = timeit.timeit('{}()'.format(func_name), number = 2, setup=setup) print(ot) return wrapper @measure def sample(): return 10 sample() Output RecursionError Traceback (most recent call last) <ipython-input-61

The Type Qualifier: Volatile

徘徊边缘 提交于 2020-11-02 17:08:37
Declare global variables with volatile Consider a handler and main routine that share a global variable g. The handler updates g, and main periodically reads g. To an optimizing compiler, it would appear that the value of g never changes in main , and thus it would be safe to use a copy of g that is cached in a register to satisfy every reference to g. In this case, the main function would never see the updated values from the handler. You can tell the compiler not to cache a variable by declaring it with the volatile type qualifier. For example: volatile int g; The volatile qualifier forces

python3 第三十二章

浪尽此生 提交于 2020-10-28 14:02:54
1. 操作系统接口 os 模块提供很多函数与操作系统进行交互︰ >>> import os >>> os.getcwd() # 返回当前的工作目录 ' C:\\Python35 ' >>> os.chdir( ' /server/accesslogs ' ) # 修改当前的工作目录 >>> os.system( ' mkdir today ' ) # 执行系统命令 mkdir 0 确保使用import os而不是from os import *。这样可以防止函数os.open()覆盖内建函数open(),两者之间的操作是很不同的。 内建函数 dir() 和 help() 对os这样的大型模块提供交互式的帮助是很有用的: >>> import os >>> dir(os) <returns a list of all module functions> >>> help(os) <returns an extensive manual page created from the module ' s docstrings> 对于日常的文件和目录管理任务, 这 shutil 模块提供了一个简单好用的高级接口: >>> import shutil >>> shutil.copyfile( ' data.db ' , ' archive.db ' ) ' archive.db ' >>>

写一手漂亮的代码,走向极致的编程 二、代码运行时内存分析

谁说我不能喝 提交于 2020-10-25 17:52:23
前言 上篇 文章 中介绍了如何对代码性能进行分析优化,这篇文章将介绍如何对代码运行时内存进行分析。 说到内存,就想起之前在搞数据挖掘竞赛的时候,往往要跑很大的数据集,经常就是炸内存。当时的解决办法就是对着任务管理器用 jupyter notebook 分 cell 的跑代码,将需要耗费大量内存的代码块找出来,然后考虑各种方式进行优化。 这篇文章将会介绍些更好的方法,来对代码运行时内存进行分析,通过这些方法了解了代码的内存使用情况之后,我们可以思考: 能不能重写这个函数让它使用更少的 RAM 来工作得更有效率 我们能不能使用更多的 RAM 缓存来节省 CPU 时间 开始分析 代码仍采用上篇文章中的 memory_profiler 通过 pip install memory_profiler 来安装这个库。在需要进行分析的函数前加上修饰器 @profile from memory_profiler import profile ... ... @profile def calculate_z_serial_purepython(maxiter, zs, cs): ... @profile def calc_pure_python(desired_width, max_itertions): ... ... 然后命令行输入 python -m memory_profiler code

二分查找会更快吗?Python中的二分查找与线性查找性能测试

大兔子大兔子 提交于 2020-10-22 06:14:35
当您要检查某个元素是否在列表中时,有很多方法可以解决相同的问题。可以通过线性查找和二分查找来完成,但是要猜测哪个更快。 为什么? 如果你最近参加过面试,你就会知道二分查找是面试官的最爱。 您为什么要花时间学习二分查找?C ++编程朋友可能已经告诉过您。Python很慢。您想确保自己的程序不会比所需的速度慢。 学习Python时,您将学习进行线性查找以检查元素是否在列表中。当您学习编码时很好,但是如果列表中有60.000.000个元素会发生什么呢? 如果在包含11个元素的列表中进行线性查找,则必须遍历所有11个元素。如果您使用二分查找,最终可能要进行2次迭代,具体取决于您要查找的内容。请参见下面的图形。 显而易见,哪种方法更快。 开始学习Python时,您很可能已经使用了一百次列表。检查列表中是否有一个值是一项正常的任务,您之前已经看到过: my_list = [1,2,3,3,5,11,12] if 11 in my_list: return Truereturn False 或者 my_list = [1,2,3,3,5,11,12] for each in list: if each==11: return Truereturn False 让我们开始看看如何实现二分查找。 怎么做? 让我们看看二分查找是如何工作的。 首先,我们需要确保列表是有序的。您可以使用.sort(

Entity Framework中的SqlException-不允许新事务,因为会话中正在运行其他线程

拜拜、爱过 提交于 2020-08-17 16:04:54
问题: I am currently getting this error: 我目前收到此错误: System.Data.SqlClient.SqlException: New transaction is not allowed because there are other threads running in the session. System.Data.SqlClient.SqlException:不允许新事务,因为会话中正在运行其他线程。 while running this code: 在运行此代码时: public class ProductManager : IProductManager { #region Declare Models private RivWorks.Model.Negotiation.RIV_Entities _dbRiv = RivWorks.Model.Stores.RivEntities(AppSettings.RivWorkEntities_connString); private RivWorks.Model.NegotiationAutos.RivFeedsEntities _dbFeed = RivWorks.Model.Stores.FeedEntities(AppSettings.FeedAutosEntities

2020杭电多校第四场 Equal Sentences

我的梦境 提交于 2020-08-13 06:09:01
第四题:Equal Sentences 题目: Sometimes, changing the order of the words in a sentence doesn’t influence understanding. For example, if we change “what time is it”, into “what time it is”; or change “orz zhang three ak world final”, into “zhang orz three world ak final”, the meaning of the whole sentence doesn’t change a lot, and most people can also understand the changed sentences well. Formally, we define a sentence as a sequence of words. Two sentences S and T are almost-equal if the two conditions holds: The multiset of the words in S is the same as the multiset of the words in T. For a word α,