V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX  ›  checgg  ›  全部回复第 1 页 / 共 3 页
回复总数  50
1  2  3  
2019-06-03 10:26:00 +08:00
回复了 checgg 创建的主题 程序员 当我们在谈论高并发的时候究竟在谈什么?
@Aruforce @zhuyichen1017

https://github.com/netty/netty/tree/4.1/example/src/main/java/io/netty/example/http/helloworld

65-69 行:

```
/*
* Copyright 2013 The Netty Project
*
* The Netty Project licenses this file to you under the Apache License,
* version 2.0 (the "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
package io.netty.example.http.helloworld;

import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.handler.codec.http.DefaultFullHttpResponse;
import io.netty.handler.codec.http.FullHttpResponse;
import io.netty.handler.codec.http.HttpObject;
import io.netty.handler.codec.http.HttpRequest;
import io.netty.handler.codec.http.HttpUtil;

import static io.netty.handler.codec.http.HttpHeaderNames.CONNECTION;
import static io.netty.handler.codec.http.HttpHeaderNames.CONTENT_LENGTH;
import static io.netty.handler.codec.http.HttpHeaderNames.CONTENT_TYPE;
import static io.netty.handler.codec.http.HttpHeaderValues.CLOSE;
import static io.netty.handler.codec.http.HttpHeaderValues.KEEP_ALIVE;
import static io.netty.handler.codec.http.HttpHeaderValues.TEXT_PLAIN;
import static io.netty.handler.codec.http.HttpResponseStatus.OK;

public class HttpHelloWorldServerHandler extends SimpleChannelInboundHandler<HttpObject> {
private static final byte[] CONTENT = { 'H', 'e', 'l', 'l', 'o', ' ', 'W', 'o', 'r', 'l', 'd' };

@Override
public void channelReadComplete(ChannelHandlerContext ctx) {
ctx.flush();
}

@Override
public void channelRead0(ChannelHandlerContext ctx, HttpObject msg) {
if (msg instanceof HttpRequest) {
HttpRequest req = (HttpRequest) msg;

boolean keepAlive = HttpUtil.isKeepAlive(req);
FullHttpResponse response = new DefaultFullHttpResponse(req.protocolVersion(), OK,
Unpooled.wrappedBuffer(CONTENT));
response.headers()
.set(CONTENT_TYPE, TEXT_PLAIN)
.setInt(CONTENT_LENGTH, response.content().readableBytes());

if (keepAlive) {
if (!req.protocolVersion().isKeepAliveDefault()) {
response.headers().set(CONNECTION, KEEP_ALIVE);
}
} else {
// Tell the client we're going to close the connection.
response.headers().set(CONNECTION, CLOSE);
}
try {
Thread.sleep(10);
} catch (InterruptedException e) {
e.printStackTrace();
}
ChannelFuture f = ctx.write(response);

if (!keepAlive) {
f.addListener(ChannelFutureListener.CLOSE);
}
}
}

@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
cause.printStackTrace();
ctx.close();
}
}

```
2019-06-01 20:57:04 +08:00
回复了 checgg 创建的主题 程序员 当我们在谈论高并发的时候究竟在谈什么?
一位常年潜水的个人开发者,没有任何广告哈~~
写了一些本人的一点沉淀和思考。
2018-11-25 13:06:28 +08:00
回复了 wleexi 创建的主题 程序员 服务端防止重复提交
这个问题的实际需求是什么?
1 防止提交两次?
这只能客户端去解决。

2 防止数据入库两次?
那么重复提交的定义是什么?
两个客户端,提交同一份数据,算重复提交吗?
如果算,设置数据库唯一索引就好,写入相同数据会失败。
如果不算,服务端没法验证。因为客户端请求都可以伪造。
这是啥问题?
并行和并发的定义是啥,不理解,能否补充一下英文关键词或者具体业务场景?
大量 IO 是指的磁盘 IO 还是网络 IO ?
@oldbai
哈哈哈哈
2018-08-29 09:48:10 +08:00
回复了 checgg 创建的主题 问与答 请问某些字符撑大 table 的 td 怎么处理?
@azh7138m 👍
2018-08-28 17:00:03 +08:00
回复了 checgg 创建的主题 问与答 请问某些字符撑大 table 的 td 怎么处理?
@gzf6
@Sparetire
fixed '。。。。' 会到表格外面去。
2018-08-28 10:54:23 +08:00
回复了 checgg 创建的主题 问与答 请问某些字符撑大 table 的 td 怎么处理?
@TomatoYuyuko 不能 hidden。
如果业务需要这个东西打印出来呢。。。。
k8s +1
2018-08-22 09:28:09 +08:00
回复了 PHPer233 创建的主题 PHP 如何实现在 Web 页面中点一下按钮就能启动一个 PHP 进程?
简单点的丢数据库跑 cron。
优雅点的丢 MQ 或者 swoole 常驻内存实现。
2018-07-18 10:34:30 +08:00
回复了 qqqppp9998 创建的主题 Node.js 在 Node.js 里尝鲜玩深度学习之画风变换
高级调参工程师
docker 直接跑 docker 里面满足你的要求吗
2018-05-15 10:20:41 +08:00
回复了 Aluhao 创建的主题 MySQL SELECT COUNT(*)超级慢,讨论一下解决方案
目前怀疑是 myisam 表锁的问题。
建议把数据库 copy 到本地,在没有写和更新的情况下查询一下。
2018-05-13 12:40:58 +08:00
回复了 checgg 创建的主题 问与答 请教 Python 如何调用 arm 编译的 so 文件?
@Xiaobaixiao 是在同目录.
2018-05-13 12:02:36 +08:00
回复了 checgg 创建的主题 问与答 请教 Python 如何调用 arm 编译的 so 文件?
顺便一提,用 java 写也是报同样的错
```
public class test {
public static void main(String[] args) {
System.out.print("Hello world");
String so = "./libencrypt.so";
System.load(so);
}
}

```
2018-04-23 21:28:31 +08:00
回复了 checgg 创建的主题 问与答 请教 wordpress 的一个问题
不在 v2 上面贴问题是因为这上面贴图片很反人类。
打扰了各位。
2018-04-22 22:50:32 +08:00
回复了 huaxing0211 创建的主题 程序员 PHP 如何判断 ajax 发起请求的来源地址?
从 http header 里面哪 refer 去判断就行.
不过,为什么要判断呢?
客户端所有的参数都是可以伪造的,是不可信的.
判断的意义不大,自己骗自己而已.
CSRF 一般是用 token 去解决,详情请搜索 JWT.
2018-04-01 10:37:52 +08:00
回复了 zhangfeiwudi 创建的主题 PHP 为什么 PHP 要编译那么多模块
@Luckyray 你奇怪是因为你对这门语言不了解。只是单纯用所以一脸懵逼,其实很多 phper 都这样。

cli cgi(fpm) apache_model 是 php 运行的三种模式。
php 线程安全和非安全区别是 windows 下才有的东西。

为什么有这么多模式是语言发展的过程中为了适应不同需求从而出现的东西。
典型的:
cli 可以用来编写常驻内存程序。
cgi 模块与 nginx 配合使用
apache_model 模块与 apache 配合使用。
2018-03-31 22:16:34 +08:00
回复了 X140Yu 创建的主题 macOS 发现一个 Mac 多屏幕设置主屏幕的小技巧
太感谢了~
2018-03-30 21:55:04 +08:00
回复了 zhangfeiwudi 创建的主题 PHP 为什么 PHP 要编译那么多模块
这个本来就是非常棒的一个功能。

原生是提供的只是基础功能。

扩展让 PHP 可以调用 C 编写模块的功能。
1  2  3  
关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5302 人在线   最高记录 6543   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 40ms · UTC 06:02 · PVG 14:02 · LAX 23:02 · JFK 02:02
Developed with CodeLauncher
♥ Do have faith in what you're doing.