- 博客(174)
- 收藏
- 关注
原创 多缓冲提高日志系统性能
前言:无论什么项目肯定都少不了日志系统,所以一个高性能的日志系统是不可避免的。 本文介绍的是自己用c++11实现的一个简单的多缓冲区日志系统,比较水,仅供参考^_^主题:日志系统及重要性单缓冲日志系统模型及缺陷多缓冲buffer介绍及优势多缓冲区缺陷Buffer类设计及分析Logger类设计及分析日志系统及重要性: 日志信息对于一个优秀项目来说是非常重要的,因为无论再优秀的
2015-08-11 07:18:50 5116 11
原创 Thinking in Java -- 类型信息RTTI
Thinking in Java – 类型信息RTTI 个人感觉 java 中的比较难的部分了,在看了些netty源码发现其实这块非常有用。
2015-08-07 10:41:45 1659
转载 SAR 命令详解
sar 命令行的常用格式: sar [options] [-A] [-o file] t [n] 在命令行中,n 和t 两个参数组合起来定义采样间隔和次数,t为采样间隔,是必须有 的参数,n为采样次数,是可选的,默认值是1,-o file表示将命令结果以二进制格式 存放在文件中,file 在此处不是关键字,是文件名。options 为命令行选项,sar命令 的 选项很多,下面只列出常
2015-08-05 15:24:14 1728
原创 线程的那些事
线程的那些事 前言:这篇文章主要小结下linux下多线程的知识点,并且有一些多线程编程中的拓展概念。以及c语言编写线程池的思路linux线程简介线程的私有数据和公有数据线程的上下文切换创建线程线程终止互斥量条件变量多线程概念简单拓展 竟态条件 并发与并行同步与互斥volatileCAS(compare and swap)指令重排和内存屏障c语言实现线程池思想 lin
2015-08-04 09:17:54 1092
原创 java 设计模式 -- 责任链模式
设计模式 – 责任链模式介绍: 责任链模式是一种动态行为模式,有多个对象,每个对象分别拥有其下家的引用,连起来形成一条链,待处理对象则传到此链上,在此链进行传递,且待处理对象并不知道此会被链上的哪个对象处理,这使得我们可以动态的增加链上的对象并且分配责任。纯责任链和非纯责任链 责任链分为两种,纯责任链和非纯责任链。 纯责任链是待处理对象request在处理对象handler链上传递,
2015-07-30 15:28:02 1408 1
原创 学习 java netty (三) -- Channel
学习 java netty (三) – Channel 前言:netty封装的channel,看一下官网的定义 A nexus to a network socket or a component which is capable of I/O operations such as read, write, connect, and bind. 可以I/O操作(如读,写,连接和绑定)
2015-07-30 00:04:33 5519 1
原创 学习 java netty (二) -- ServerBootstrap
前言:我们自己使用java nio开发网络程序是非常繁琐的,netty为我们做好了一切,其中ServerBootstrap是一个启动辅助类,了解它我们就能开发出简单的nio 服务端程序。 不理解Nio中channel和handler等可参考上一篇文章 学习 java netty (一) – java nioServerBootstrap()://创建一个ServerBootstrap对象
2015-07-28 08:23:47 4867
原创 学习 java netty (一) -- java nio
前言:最近在研究java netty这个网络框架,第一篇先介绍java的nio。 java nio在jdk1.4引入,其实也算比较早的了,主要引入非阻塞io和io多路复用。内部基于reactor模式。nio核心: - buffer - channel - selector buffer: 类似网络编程中的缓冲区,有 ByteBuffer 字节 CharBuf
2015-07-26 20:51:56 2138
原创 c++ 实现数据库连接池
c++ 实现数据库连接池 自己尝试用c++ 新标准实现了数据库连接池,代码简化了很多。 思路: 将数据库的连接当作一个对象添加进list队列中,在连接池创建的时候就建立好队列,并添加自定义大小的连接对象,连接对象用智能指针来管理(现代c++中不应该出现delete语句),避免类似内存泄漏等内存问题,智能指针上用lambda表达式注册了delete删除函数来释放连接资源,及时归还,(其中用
2015-07-23 22:09:42 21461 7
原创 linux 下同步异步,阻塞非阻塞的一些想法
同步异步 阻塞非阻塞 今天和小伙伴讨论了这个问题,网上的说法有很多种,我按照自己的思路总结一边。 一句话总结区别: 同步异步关注的是事件发生时你的行为。 阻塞非阻塞关注的是的等待事件的状态。 下面看具体的分析同步异步 同步: 在事件发生前,你的状态是时刻关注此事件,等待此事件给你返回结果。 例子: 烧水,同步就是你时刻关注着它,一段时间后,烧水壶冒
2015-07-21 14:04:34 1755
原创 c++11 实现半同步半异步线程池
感受: 随着深入学习,现代c++给我带来越来越多的惊喜… c++真的变强大了。半同步半异步线程池: 其实很好理解,分为三层 同步层:通过IO复用或者其他多线程多进程等不断的将待处理事件添加到队列中,这个过程是同步进行的。 队列层:所有待处理事件都会放到这里。上一层事件放到这里,下一层从这里获取事件 异步层:事先创建好线程,让线程的去处理队列层的任务,上层不
2015-07-19 06:37:28 4006 3
原创 c++11 多线程 -- 基本使用
c++11 多线程 – 基本使用 前言:这篇文章仅针对没有使用过c++11线程库的童鞋来快速入门,也是自己的一个简单记录,内容比较基础。-1.线程的基本使用 -2.互斥量 -3.条件变量 -4.原子变量1.线程的基本使用代码:#include <stdio.h>#include <stdlib.h>#include <assert.h>#include <thread>#incl
2015-07-17 00:14:17 15013
原创 初探sendfile
很早就知道sendfile这个专门用来传输大文件的函数,也称为零拷贝,但一直没测试过,今天用了宿舍的网和小组内的网测试了下,发现结果和我预想的不一样。 为什么效率高,网上说的也很多了,看下man手册中的内容 sendfile() copies data between one file descriptor and another. Because this copying is do
2015-07-05 23:55:44 2101 1
原创 udp 调用connect函数
结论: udp可以调用connect函数。 udp可以多次调用connect函数。 udp调用connect作用: 发送端:我们不需要再次指定也不能指定端口和ip地址 接收端:不必使用类似recvfrom的函数来获得数据报的发送者,一个已连接的udp套接字只与一个ip地址交换数据 已连接的udp如果错误会返回给发送端 udp多次调用connect作用: 指
2015-07-03 02:25:54 2351
原创 linux下修改内核参数进行Tcp性能调优 -- 高并发
前言: Tcp/ip协议对网络编程的重要性,进行过网络开发的人员都知道,我们所编写的网络程序除了硬件,结构等限制,通过修改Tcp/ip内核参数也能得到很大的性能提升, 下面就列举一些Tcp/ip内核参数,解释它们的含义并通过修改来它们来优化我们的网络程序。 这里网络程序主要指的是服务器1. fs.file-max 最大可以打开的文件描述符数量,注意是整个系统。 在服务器
2015-07-01 10:30:03 21194
转载 展望未来,总结过去10年的程序员生涯,给程序员小弟弟小妹妹们的一些总结性忠告
走过的路,回忆起来是那么曲折,把自己的一些心得体会分享给程序员兄弟姐妹们,虽然时代在变化,但是很可能你也会走我已经做过的10年的路程,有些心得体会你可以借鉴一下,觉得说得有道理的你就接纳,觉得说得没道理的,你就抛弃,以下是我发自内心的,给大家的忠告,特别是针对那些小弟弟妹妹们。01. 自己的户口档案、养老保险、医疗保险、住房公积金一定要保管好。由于程序员行业每年跳槽一次,我不隐瞒大家,
2015-06-28 14:39:23 1147 3
原创 关于tcp中time_wait状态的4个问题
面试中time_wait是个常考的问题,tcp网络编程中最不容易理解的也是它的time_wait状态,这也说明了tcp/ip四次挥手中time_wait状态的重要性。 下面通过4个问题来描述它问题1.time_wait状态是什么2.为什么会有time_wait状态3.哪一方会有time_wait状态4.如何避免time_wait状态占用资源1.time_wait状态是什么 简单来说:ti
2015-06-24 18:12:05 6204 3
原创 leetcode 35 -- Search Insert Position
Search Insert Position 题目: Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order. You may as
2015-06-24 00:44:46 1603
原创 leetcode 34 -- Search for a Range
Search for a Range 题目: Given a sorted array of integers, find the starting and ending position of a given target value. Your algorithm’s runtime complexity must be in the order of O(log n).
2015-06-23 00:36:45 1526
原创 leetcode 33 -- Search in Rotated Sorted Array
Search in Rotated Sorted Array 题目: Suppose a sorted array is rotated at some pivot unknown to you beforehand. (i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2). You are given a target value
2015-06-22 13:04:46 2529 2
原创 leetcode 32 -- Longest Valid Parentheses
Longest Valid Parentheses 题目: Given a string containing just the characters ‘(’ and ‘)’, find the length of the longest valid (well-formed) parentheses substring. For “(()”, the longest valid p
2015-06-18 13:23:58 982
原创 leetcode 31 -- Next Permutation
Next Permutation 题目: Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers. If such arrangement is not possible, it must rearran
2015-06-15 18:52:33 1007
原创 leetcode 30 -- Substring with Concatenation of All Words
Substring with Concatenation of All Words 题目: You are given a string, s, and a list of words, words, that are all of the same length. Find all starting indices of substring(s) in s that is a conc
2015-06-14 00:57:56 927
原创 leetcode 29 -- Divide Two Integers
Divide Two Integers 感想: >这道题因为有一点小问题一直导致AC不过,一会我会先贴上自己的正确代码,之前错误的贴到后面。>在一直解决不了遇到的问题时,我去网上搜了下别人做这道题的思路,感觉自己的思路也算比较简单吧,就一直坚持自己的思路,依然不知道哪里错了,调试于是查了查abs函数,发现了还有其他的类abs函数,自己没用过,labs和llabs,于是发现了自己边界的问题,改正加上了一个
2015-06-12 17:23:05 2838
原创 浅析数据库连接池(二)
上一篇博客,主要是简单的介绍了普通数据库连接的过程以及耗费的资源,并且简单的谈了下连接池,这篇我们主要来看看数据库连接池的使用以及它最优的配置。总目录: -1.数据库连接过程是怎样的? -2.连接所占用的资源有哪些? -3.连接池简介 -4.连接池的使用 -5.最优连接池配置选择今天主要看看4和5。4.连接池的使用这里我使用的是c3p0数据库连接池 简单的介绍一下c3p0:C3P0
2015-06-11 17:21:53 3834
原创 leetcode 28 -- Implement strStr()
Implement strStr() 题目: mplement strStr(). Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack. Update (2014-11-02): The signature of
2015-06-11 12:23:14 902
原创 leetcode 27 -- Remove Element
Remove Element 题目: Given an array and a value, remove all instances of that value in place and return the new length. The order of elements can be changed. It doesn’t matter what you leave beyo
2015-06-11 12:17:56 1135
原创 浅析数据库连接池(一)
由于最近项目要用到数据库连接池,所以今天简单的聊聊~, 这个话题的引起是因为我在写mysql数据库部分时产生了一个疑问,一般后台处理数据部分,服务端是创建一个connection连接到数据库,然后所有的请求通过这一个connection来访问数据库,还是每个连接创建一个connction?这个连接需要维持多久?...接下来一起看看 首先目录1,2是为了引出下面的连接池,因为一般我们仅仅是
2015-06-11 02:37:08 11592 3
原创 leetcode 26 -- Remove Duplicates from Sorted Array
Remove Duplicates from Sorted Array 题目: Given a sorted array, remove the duplicates in place such that each element appear only once and return the new length. Do not allocate extra space for
2015-06-10 17:32:59 1005
原创 leetcode 25 -- Reverse Nodes in k-Group
Reverse Nodes in k-Group 题目: Given a linked list, reverse the nodes of a linked list k at a time and return its modified list. If the number of nodes is not a multiple of k then left-out nodes
2015-06-10 17:06:51 1151
原创 leetcode 24 -- Swap Nodes in Pairs
Swap Nodes in Pairs 题目: Given a linked list, swap every two adjacent nodes and return its head. For example, Given 1->2->3->4, you should return the list as 2->1->4->3. Your algorithm sh
2015-06-08 10:29:19 964
原创 leetcode23 -- Merge k Sorted Lists
Merge k Sorted Lists 题目: Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists. 题意: 合并k个已经排序过的链表。 思路:
2015-06-07 12:13:54 805
原创 leetcode 22 -- Generate Parentheses
Generate Parentheses 题目: Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses. For example, given n = 3, a solution set is: “((()))”, “(()(
2015-06-06 23:23:08 1551
原创 leetcode 21 -- Merge Two Sorted Lists
Merge Two Sorted Lists 题目: Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists. 题意: 合并两个排序过的链表 思路:
2015-06-05 12:25:18 811
原创 leetcode 20 -- Valid Parentheses
Valid Parentheses 题目: Given a string containing just the characters ‘(‘, ‘)’, ‘{‘, ‘}’, ‘[’ and ‘]’, determine if the input string is valid. The brackets must close in the correct order, “()”
2015-06-05 12:20:10 873
原创 leetcode 19 -- Remove Nth Node From End of List
Remove Nth Node From End of List 题目: Given a linked list, remove the nth node from the end of list and return its head. For example, Given linked list: 1->2->3->4->5, and n = 2. After r
2015-06-05 12:14:37 982
原创 leetcode 18 -- 4Sum
4Sum 题目:Given an array S of n integers, are there elements a, b, c, and d in S such that a + b + c + d = target? Find all unique quadruplets in the array which gives the sum of target. Note: El
2015-06-04 15:12:14 1407 2
原创 leetcode 17 -- Letter Combinations of a Phone Number
Letter Combinations of a Phone Number 题目: Given a digit string, return all possible letter combinations that the number could represent. A mapping of digit to letters (just like on the telepho
2015-06-03 10:52:00 906
原创 leetcode 16 -- 3Sum Closest
3Sum Closest 题目: Given an array S of n integers, find three integers in S such that the sum is closest to a given number, target. Return the sum of the three integers. You may assume that each in
2015-06-02 18:48:20 881
原创 leetcode 15 -- 3Sum
3Sum 题目: Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero. For example, given array S
2015-06-01 14:06:32 856
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人