當前位置:首頁 » 文件管理 » 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 瀏覽:856
國產存儲科技進步二等獎 發布:2025-02-04 09:13:00 瀏覽:693
編程課v 發布:2025-02-04 08:45:00 瀏覽:108
模擬器能有手機腳本么 發布:2025-02-04 08:39:50 瀏覽:761
android顯示html圖片 發布:2025-02-04 08:35:31 瀏覽:793
如何查學信網賬號及密碼 發布: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