当前位置:首页 » 文件管理 » udp缓存设置

udp缓存设置

发布时间: 2023-07-14 13:04:41

Ⅰ UDP中将struct skb_buff作为缓存区 具体如何使用

一. SKB_BUFF的基本概念
1. 一个完整的skb buff组成
(1) struct sk_buff--用于维护socket buffer状态和描述信息
(2) header data--独立于sk_buff结构体的数据缓冲区,用来存放报文分组,使各层协议的header存储在连续的空间中,以方便协议栈对其操作
(3) struct skb_shared_info --作为header data的补充,用于存储ip分片,其中sk_buff *frag_list是一系列子skbuff链表,而frag[]是由一组单独的page组成的数据缓冲区

Ⅱ 请教linux关于UDP最大缓冲区设置

1. tcp 收发缓冲区默认值 [root@ ]# cat /proc/sys/net/ipv4/tcp_rmem 4096 87380 4161536 87380 :tcp接收缓冲区的默认值 [root@ ]# cat /proc/sys/net/ipv4/tcp_wmem 4096 16384 4161536 16384 : tcp 发送缓冲区的默认值 2. tcp 或udp收发缓冲区最大值 [root@ ]# cat /proc/sys/net/core/rmem_max 131071 131071:tcp 或 udp 接收缓冲区最大可设置值的一半。 也就是说调用 setsockopt(s, SOL_SOCKET, SO_RCVBUF, &rcv_size, &optlen); 时rcv_size 如果超过 131071,那么 getsockopt(s, SOL_SOCKET, SO_RCVBUF, &rcv_size, &optlen); 去到的值就等于 131071 * 2 = 262142 [root@ ]# cat /proc/sys/net/core/wmem_max 131071 131071:tcp 或 udp 发送缓冲区最大可设置值得一半。 跟上面同一个道理 3. udp收发缓冲区默认值 [root@ ]# cat /proc/sys/net/core/rmem_default 111616:udp接收缓冲区的默认值 [root@ ]# cat /proc/sys/net/core/wmem_default 111616 111616:udp发送缓冲区的默认值 4. tcp 或udp收发缓冲区最小值 tcp 或udp接收缓冲区的最小值为 256 bytes,由内核的宏决定; tcp 或udp发送缓冲区的最小值为 2048 bytes,由内核的宏决定

Ⅲ windows下怎么修改UDP缓存

要不然你就用win32api重写一遍

要不然你就去装一个cygwin来编译(比较推荐这个选择

否则这一类的代码你只能在linux环境下使用了(考虑下用虚拟机吧……

Ⅳ winsocket udp和tcp编程,缓冲区应该设置多大

设置为1024,分包接收。

Ⅳ 如何修改TCP接收缓存大小

我写了个TCP,和UDP类
发现TCP默认接收的最大缓冲 一次性好象最多只能接收 12000左右个字节
而UDP默认接收的最大缓冲 一次性好象最多只能接收 28000左右个字节
据说一般最好。65535个以下 ,否则路由器容易丢包
------解决方案--------------------------------------------------------private int _buf=8000;//标记一次传输文件数据块的大小,不能超过MTU限制,否则在因特网上的数据发送将不成功00
[Category( "全局设置 ")]
[Description( "设置UDP每一次传输数据包的大小 ")]
[DefaultValue(8000)]
public int buf{set{_buf=value;}
get{return _buf;}}然后使用 byte[] 发送数据,发送的时候限制每一次包大小。
至于接收:如果你发送的包已经限制好,接收就不会出问题。
byte[] buffer = new byte[buf];

Ⅵ 我怎么可以设置下的Socket UDP的缓冲区大小

有3点值得说明:
1. 上面我们仅仅写了接收的内核缓冲区, 关键字是SO_RCVBUF, 如果是发送的内核缓冲区, 那就用SO_SNDBUF, 有兴趣的童鞋可以稍微修改一下上面程序即可。
2. 从程序的结果我们可以看到, sockClient1和sockClient2两者的发送内核缓冲区没有任何关系。
3. 听一网友说过, tcp才有所谓的内核缓冲区, udp没有。

Ⅶ ehcache rmi 的udp方式同步缓存,他的广播地址怎么确认

Ehcache缓存同步有几种方式:(1)RMI (2)Terrocotta (3)JMS (4)JGroups
先介绍下,利用RMI进行缓存同步。

测试类1:在sampleDistributedCache2缓存中查找是否存在ehcache键,如果没找到,则打印NotFound;如果找到了,则打印相应值

[java] view plain
package my.test.ehcache1;

import java.io.InputStream;
import java.lang.management.ManagementFactory;

import javax.management.MBeanServer;

import net.sf.ehcache.Cache;
import net.sf.ehcache.CacheManager;
import net.sf.ehcache.Element;
import net.sf.ehcache.management.ManagementService;

public class EHCacheTest {

public static void main(String[] args) {
InputStream is = EHCacheTest.class
.getResourceAsStream("/my/test/ehcache1/ehcache.xml");
//读入配置
CacheManager cacheManager = new CacheManager(is);
//打印初始缓存
String[] cacheNames = cacheManager.getCacheNames();
printNames(cacheNames);
//移除缓存
cacheManager.removeCache("sampleDistributedCache1");
cacheNames = cacheManager.getCacheNames();
printNames(cacheNames);

//新建缓存
Cache cache = new Cache("Test1", 100, true, false, 10, 10);
cacheManager.addCache(cache);
cacheNames = cacheManager.getCacheNames();
printNames(cacheNames);
cache.put(new Element("test1", "value1"));

//得到缓存并插入值(这里监听器被调用)
cache = cacheManager.getCache("sampleCache3");
for (int i = 0; i < 20; i++) {
cache.put(new Element("key" + i, "value" + i));
}
cache.get("key10");

// distributed -- rmi同步
cache = cacheManager.getCache("sampleDistributedCache2");
for (int i = 0; i < 100; i++) {
cache.put(new Element("key" + i , "value" + i));
}

//注册被管理的Bean
// JMX -- jconsole(MBeanServer)
MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
ManagementService.registerMBeans(cacheManager, mBeanServer, true, true,
true, true);

for (int i = 0; i < 10; i++) {
Element temp = cache.get("ehcache");
if (temp != null) {
System.out.println(temp.getValue());
} else {
System.out.println("NotFound");
}
try {
Thread.sleep(10000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}

// distributed cache using RMI
// 1.Peer Discovery --
// 2.CacheManager --
// 3.cache replication -- cacheEventListenerFactory
// 4.Bootstrap -- 启动后同步
}

private static void printNames(String[] names) {
System.out.println("=======================");
for (int i = 0; i < names.length; i++) {
System.out.println(names[i]);
}
}

}

配置文件1:将官方样例文件中相应位置替换即可
(1)其他JVM提供缓存的rmiUrl地址

[java] view plain
<
class="net.sf.ehcache.distribution."
properties="peerDiscovery=manual,
rmiUrls=//localhost:40002/sampleDistributedCache2"
propertySeparator=","
/>

(2)监听来自于其他复制节点消息的本JVM的host,port

[xhtml] view plain
<
class="net.sf.ehcache.distribution."
properties="hostName=localhost, port=40001, socketTimeoutMillis=2000"
/>

(3)配置复制选项,启动时同步等

[xhtml] view plain
<cache name="sampleDistributedCache2"
maxElementsInMemory="10"
eternal="false"
timeToIdleSeconds="100"
timeToLiveSeconds="100"
overflowToDisk="false">
<cacheEventListenerFactory
class="net.sf.ehcache.distribution.RMICacheReplicatorFactory"
properties="replicateAsynchronously=true, replicatePuts=true,
replicatePutsViaCopy=true, replicateUpdates=true,
replicateUpdatesViaCopy=true, replicateRemovals=true,
=200"/>
<bootstrapCacheLoaderFactory
class="net.sf.ehcache.distribution."/>
</cache>

测试类2:向sampleDistributedCache2缓存中添加ehcache键

[java] view plain
package my.test.ehcache2;

import java.io.InputStream;
import java.lang.management.ManagementFactory;

import javax.management.MBeanServer;

import net.sf.ehcache.Cache;
import net.sf.ehcache.CacheManager;
import net.sf.ehcache.Element;
import net.sf.ehcache.Statistics;
import net.sf.ehcache.management.ManagementService;
import net.sf.ehcache.statistics.LiveCacheStatistics;

public class EHCacheTest {

public static void main(String[] args) {
try {
Thread.sleep(3 * 1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
//读入配置
InputStream is = EHCacheTest.class.getResourceAsStream("/my/test/ehcache2/ehcache.xml");
CacheManager cacheManager = new CacheManager(is);
//打印初始缓存
String[] cacheNames = cacheManager.getCacheNames();
printNames(cacheNames);
//注册管理Bean
MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
ManagementService.registerMBeans(cacheManager, mBeanServer, true, true, true, true);

//distributed
Cache cache = cacheManager.getCache("sampleDistributedCache2");
printCache(cache);
//添加值后另一个虚拟机的缓存通过RMI会同步缓存,并读到这个值
cache.put(new Element("ehcache", "newaddvalue"));
}

private static void printNames(String[] names) {
System.out.println("=======================");
for (int i = 0; i < names.length; i++) {
System.out.println(names[i]);
}
}

private static void printCache(Cache cache) {
int size = cache.getSize();
long memSize = cache.getMemoryStoreSize();
long diskSize = cache.getDiskStoreSize();
Statistics stat = cache.getStatistics();
LiveCacheStatistics liveStat = cache.getLiveCacheStatistics();
long hits = stat.getCacheHits();
long missed = stat.getCacheMisses();
long hitsOnDisk = stat.getOnDiskHits();
long liveHits = liveStat.getCacheHitCount();
long liveMissed = liveStat.getCacheMissCount();

StringBuilder sb = new StringBuilder();
sb.append("size=" + size + ";memsize=" + memSize);
sb.append(";diskSize=" + diskSize + ";hits=" + hits);
sb.append(";missed=" + missed + ";liveHits=" + liveHits);
sb.append(";liveMissed=" + liveMissed + ";hitsOnDisk=" + hitsOnDisk);
System.out.println(sb.toString());
}
}

配置文件:将官方样例文件中相应位置替换即可

[xhtml] view plain
<
class="net.sf.ehcache.distribution."
properties="peerDiscovery=manual,
rmiUrls=//localhost:40001/sampleDistributedCache2"
propertySeparator=","
/>

[xhtml] view plain
<
class="net.sf.ehcache.distribution."
properties="hostName=localhost, port=40002, socketTimeoutMillis=2000"
/>

[xhtml] view plain
<cache name="sampleDistributedCache2"
maxElementsInMemory="10"
eternal="false"
timeToIdleSeconds="100"
timeToLiveSeconds="100"
overflowToDisk="false">
<cacheEventListenerFactory
class="net.sf.ehcache.distribution.RMICacheReplicatorFactory"
properties="replicateAsynchronously=true, replicatePuts=true,
replicatePutsViaCopy=true, replicateUpdates=true,
replicateUpdatesViaCopy=true, replicateRemovals=true,
=200"/>
<bootstrapCacheLoaderFactory
class="net.sf.ehcache.distribution."/>
</cache>

热点内容
硬盘存储服务器怎么连接 发布:2025-02-04 10:00:55 浏览:27
javaip端口 发布:2025-02-04 09:27:09 浏览:857
国产存储科技进步二等奖 发布:2025-02-04 09:13:00 浏览:693
编程课v 发布:2025-02-04 08:45:00 浏览:108
模拟器能有手机脚本么 发布:2025-02-04 08:39:50 浏览:762
android显示html图片 发布:2025-02-04 08:35:31 浏览:795
如何查学信网账号及密码 发布:2025-02-04 08:33:55 浏览:506
linux32位jdk 发布:2025-02-04 08:33:55 浏览:250
康佳服务器连接失败是怎么回事 发布:2025-02-04 08:18:51 浏览:919
编译编译有什么 发布:2025-02-04 08:05:52 浏览:739