Feign Client + Eureka POST请求正文(Feign Client + Eureka POST request body)

我正在尝试使用Feign和Eureka将服务器A的发布请求转发到服务器B.这两个服务器都被Eureka成功地取消了。

这有效:

@Feignclient
public interface MyFeignClient {
    @RequestMapping(value = "test", = RequestMethod.POST, consumes = "application/json")
    ResponseEntity<String> theActualMethod(
            HttpServletRequest request,
            @RequestHeader("firstHeader") String header1,
            @RequestHeader("secondHeader") byte[] header2);
}

但是,当我将第二个参数更改为@RequestBody以读取POST请求内容时,我得到一个异常:

java.lang.IllegalStateException: Method has too many Body parameters: public abstract org.springframework.http.ResponseEntity MyFeignClient.theActualMethod(javax.servlet.http.HttpServletRequest,java.lang.String,byte[])

I'm trying to use Feign and Eureka to forward a post request from server A to server B. Both servers are discrovered sucessfully by Eureka.

This works:

@Feignclient
public interface MyFeignClient {
    @RequestMapping(value = "test", = RequestMethod.POST, consumes = "application/json")
    ResponseEntity<String> theActualMethod(
            HttpServletRequest request,
            @RequestHeader("firstHeader") String header1,
            @RequestHeader("secondHeader") byte[] header2);
}

However, when I change the second argument to @RequestBody in order to read the POST request content, I get an exception:

java.lang.IllegalStateException: Method has too many Body parameters: public abstract org.springframework.http.ResponseEntity MyFeignClient.theActualMethod(javax.servlet.http.HttpServletRequest,java.lang.String,byte[])

原文:https://stackoverflow.com/questions/35264620
2024-05-07 19:05

满意答案

程序启动时,在main()中,使用任何系统计时器记录时间。 当程序在main()的底部结束时,使用相同的系统计时器记录时间。 取时间2和时间1之间的差异。 你去!

您可以使用不同的系统计时器,其中一些计时器的分辨率高于其他计时器。 我建议您在SO网站上搜索“系统计时器”,而不是在这里讨论。 如果您只想要任何系统计时器,gettimeofday()可以在Linux系统上运行,但它已被更新,更高精度的功能所取代。 实际上,gettimeofday()只测量以微秒为单位的时间,这应该足以满足您的需求。

如果您无法获得具有足够好分辨率的计时器,请考虑多次循环运行程序,计算循环执行时间,并将测量时间除以循环迭代次数。

编辑:

系统计时器可用于测量总应用程序性能,包括GPU计算期间使用的时间。 请注意,以这种方式使用系统计时器仅适用于实时或挂钟时间,而不是处理时间。 基于挂钟时间的测量必须包括等待GPU操作完成所花费的时间。

如果要测量GPU内核所用的时间,可以选择几个选项。 首先,您可以使用Compute Visual Profiler收集各种分析信息,虽然我不确定它是否报告时间,但它必须能够(这是一个基本的分析功能)。 其他分析器 - 脑海中浮现 - 提供对CUDA内核的支持。

另一种选择是使用CUDA事件来记录时间。 请参阅CUDA 4.0编程指南,其中讨论了使用CUDA事件来测量时间。

另一种选择是使用围绕GPU内核调用的系统计时器。 请注意,鉴于内核调用返回的异步性质,您还需要使用主机端GPU同步调用(例如cudaThreadSynchronize())来跟随内核调用,以使此方法适用。 如果你选择这个选项,我强烈建议在循环中调用内核,在结束时定时循环+一次同步(因为在不在不同流中执行的内核调用之间发生同步,循环内部不需要cudaThreadSynchronize()),并除以迭代次数。


When your program starts, in main(), use any system timer to record the time. When your program ends at the bottom of main(), use the same system timer to record the time. Take the difference between time2 and time1. There you go!

There are different system timers you can use, some with higher resolution than others. Rather than discuss those here, I'd suggest you search for "system timer" on the SO site. If you just want any system timer, gettimeofday() works on Linux systems, but it has been superseded by newer, higher-precision functions. As it is, gettimeofday() only measures time in microseconds, which should be sufficient for your needs.

If you can't get a timer with good enough resolution, consider running your program in a loop many times, timing the execution of the loop, and dividing the measured time by the number of loop iterations.

EDIT:

System timers can be used to measure total application performance, including time used during the GPU calculation. Note that using system timers in this way applies only to real, or wall-clock, time, rather than process time. Measurements based on the wall-clock time must include time spent waiting for GPU operations to complete.

If you want to measure the time taken by a GPU kernel, you have a few options. First, you can use the Compute Visual Profiler to collect a variety of profiling information, and although I'm not sure that it reports time, it must be able to (that's a basic profiling function). Other profilers - PAPI comes to mind - offer support for CUDA kernels.

Another option is to use CUDA events to record times. Please refer to the CUDA 4.0 Programming Guide where it discusses using CUDA events to measure time.

Yet another option is to use system timers wrapped around GPU kernel invocations. Note that, given the asynchronous nature of kernel invocation returns, you will also need to follow the kernel invocation with a host-side GPU synchronization call such as cudaThreadSynchronize() for this method to be applicable. If you go with this option, I highly recommend calling the kernel in a loop, timing the loop + one synchronization at the end (since synchronization occurs between kernel calls not executing in different streams, cudaThreadSynchronize() is not needed inside the loop), and dividing by the number of iterations.

相关问答

更多

我应该在GPU上还是在CPU上计算矩阵?(Should I calculate matrices on the GPU or on the CPU?)

一般规则:如果可以以统一形式将其传递给着色器,则始终在CPU上进行预先计算; 没有例外。 着色器侧的计算仅适用于在顶点和片段之间变化的值。 在整个批次顶点中的所有内容在CPU上处理得最为有效。 GPU不是魔术“可以做更快的一切”的机器。 有一些CPU可以轻松胜过GPU的任务,即使是非常大的数据集。 所以一个非常简单的指导方针是:如果您可以将其移动到CPU而无需花费更多的CPU时间进行计算,而不是花费在总体开销上的GPU来处理它,那么请在CPU上执行。 单个矩阵的计算在这些任务之中。 General...

从GPU复制到CPU比将CPU复制到GPU要慢(copy from GPU to CPU is slower than copying CPU to GPU)

而不是使用clock()来测量时间,你应该事件: 使用事件你会有这样的事情: cudaEvent_t start, stop; // variables that holds 2 events float time; // Variable that will hold the time cudaEventCreate(&start); // creating the event 1 cudaEventCreate(&stop); //...

将PyTorch代码从CPU移植到GPU(Porting PyTorch code from CPU to GPU)

你也可以尝试: net = YouNetworkClass() device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu") net.to(device) 之后,您还必须将word_inputs , encoder_hidden和decoder_context发送到GPU: word_inputs, encoder_hidden, decoder_context = word_inputs.to(device), ...

为什么Opencv GPU代码比CPU慢?(Why Opencv GPU code is slower than CPU?)

cvtColor并没有做太多的工作,为了让所有你需要的是平均三个数字。 CPU上的cvColor代码使用SSE2指令一次处理多达8个像素,如果您有使用所有内核/超线程的TBB,则CPU以10倍于GPU的时钟速度运行,最后您不必将数据复制到GPU并返回。 cvtColor isn't doing very much work, to make grey all you have to is average three numbers. The cvColor code on the CPU is u...

mxnet(gluon):选择gpu(0)上下文时使用的cpu(mxnet (gluon): cpu used when gpu(0) context selected)

有几件事会影响你的表现。 DataLoader限制您的培训。 使用num_workers增加获取和预处理数据到NDArray中的进程数量,以确保您的GPU不会挨饿。 例如train_data = mx.gluon.data.DataLoader(mx.gluon.data.vision.MNIST(train=True, transform=transform), batch_size, shuffle=True, num_workers=4) MXNet中的内置指标目前效率很低,特别是当批量很小...

关于CPU的GPU性能(GPU performance with respect to CPU)

GPU中的每个SM是SIMD处理器,其在SIMD的每个通道上执行经线的不同线程。 一旦应用程序受到更多计算限制(少量内存访问),并且没有分支应用程序实现GPU的峰值FLOPS。 这是因为在分支时,GPU掩盖了发散的一侧并首先执行另一侧。 两条路径都是串行执行的,这使得某些SIMD通道无效,从而降低了性能。 我已经在Fung的论文中加入了一个有用的图,该图可以在上述参考文献中公开获得,以显示性能如何实际下降: 图(a)显示了在warp内发生的GPU中的典型分支发散(此样本中为4个线程)。 假设您有以...

如何计算CPU + GPU的总时间(How to calculate total time for CPU + GPU)

程序启动时,在main()中,使用任何系统计时器记录时间。 当程序在main()的底部结束时,使用相同的系统计时器记录时间。 取时间2和时间1之间的差异。 你去! 您可以使用不同的系统计时器,其中一些计时器的分辨率高于其他计时器。 我建议您在SO网站上搜索“系统计时器”,而不是在这里讨论。 如果您只想要任何系统计时器,gettimeofday()可以在Linux系统上运行,但它已被更新,更高精度的功能所取代。 实际上,gettimeofday()只测量以微秒为单位的时间,这应该足以满足您的需求。 ...

CPU何时在GPU上等待?(When does the CPU wait on the GPU?)

快速摘要是您可能会在Present()中看到等待,但它实际上取决于Present()调用的内容。 一般情况下,除非您明确表示想要知道GPU何时完成,否则您可能最终会在(随机到您)点等待驱动程序的输入缓冲区填满。 将GPU驱动程序和卡视为一个非常长的管道。 你可以在一端投入工作,最后一段时间它就会出现在显示器上。 在填满之前,您可以在管道中放入几帧命令。 该卡可能需要花费大量时间绘制基元,但您可能会看到CPU在几个帧后等待。 如果您的Present()调用包含等效的glFinish(),那么整个管道...

将数据从GPU复制到CPU(Copy data from GPU to CPU)

您的代码(按原样)不编译,下面是一个固定版本,我认为具有相同的意图如果您想要从计算时间中分离复制的时间,那么最简单的方法是使用数组<>和明确的副本。 int _height, _width; _height = _width = 3000; std::vector<int> _main(_height * _width); // host data. concurrency::extent<2> ext(_height, _width...

异步CPU读取和GPU + CPU计算(Asynchronous CPU reading and GPU+CPU calculations)

我非常偏爱pthreads并在读取器上实现异步包装器,当您请求下一组数据时,它会同步。 这是我能想到的最容易实现的方法。 我已经包含了一些应该易于编译并完全演示实现的内容。 祝你好运。 main.cpp演示了如何使用。 #include "Reader.h" #include "Reader_Async_Wrapper.h" using namespace std; int main() { Reader *reader = new Reader("test"); Reader...

相关文章

更多

httpclient post 请求

httpclient post请求与get请求的区别主要是httpclient.execute对象 ...

httpclient post 表单参数请求

httpclient post带参数请求的步骤: 1、声明NameValuePair列表对象,把相 ...

HDFS Client如何从Datanode读取block

Datanode中包含DataXceiverServer。DataXceiverServer是一个so ...

HDFS源码分析——RPC Client实现

通俗来讲RPC(RemoteProcedureCall)就是调用远程的过程或者方法,既然涉及到远程,必 ...

Riak, haproxy, and client side applications

转载:http://blog.dloh.org/Riak,-haproxy,-and-client-s ...

HDFS1.0源代码解析—Hadoop的RPC机制之Client解析

好久没有更新Hadoop相关的博客了,实在是各种压力缠身,各种东西都没准备好,面对即将找工作有点没有了 ...

HDFS Datanode与Client之间的数据传输

在HDFS之中,Datanode与Namenode之间是通过RPC进行通信的;在Datanode和Cl ...

solr python client

i found two python wrap of solr, http://github.com ...

storm client command

最近在研究实时日志分析,storm确实不错,以下是命令参数: storm help Syntax: ...

solr实例代码 import org.apache.solr.client.solrj.SolrServer

Hi all, I used the sample code given below and trie ...

最新问答

更多

获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)

我用Google搜索了一个解决方案。 “EnumDisplayModeProvider”是我自己设置网站的各种模式的枚举。 public EnumDisplayModeProvider GetDisplayModeId() { foreach (var mode in DisplayModeProvider.Instance.Modes) if (mode.CanHandleContext(HttpContext)) {

如何通过引用返回对象?(How is returning an object by reference possible?)

这相对简单:在类的构造函数中,您可以分配内存,例如使用new 。 如果你制作一个对象的副本,你不是每次都分配新的内存,而是只复制指向原始内存块的指针,同时递增一个也存储在内存中的引用计数器,使得每个副本都是对象可以访问它。 如果引用计数降至零,则销毁对象将减少引用计数并仅释放分配的内存。 您只需要一个自定义复制构造函数和赋值运算符。 这基本上是共享指针的工作方式。 This is relatively easy: In the class' constructor, you allocate m

矩阵如何存储在内存中?(How are matrices stored in memory?)

正如它在“熵编码”中所说的那样,使用Z字形图案,与RLE一起使用,在许多情况下,RLE已经减小了尺寸。 但是,据我所知,DCT本身并没有给出稀疏矩阵。 但它通常会增强矩阵的熵。 这是compressen变得有损的点:输入矩阵用DCT传输,然后量化量化然后使用霍夫曼编码。 As it says in "Entropy coding" a zig-zag pattern is used, together with RLE which will already reduce size for man

每个请求的Java新会话?(Java New Session For Each Request?)

你是如何进行重定向的? 您是否事先调用了HttpServletResponse.encodeRedirectURL()? 在这里阅读javadoc 您可以使用它像response.sendRedirect(response.encodeRedirectURL(path)); The issue was with the path in the JSESSIONID cookie. I still can't figure out why it was being set to the tomca

css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)

我认为word-break ,如果你想在一个单词中打破行,你可以指定它,这样做可以解决问题: .column { word-break:break-all; } jsFiddle演示。 您可以在此处阅读有关word-break属性的更多信息。 I think word-break, with which you can specify if you want to break line within a word, will do the trick: .column { word-break

无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)

我认为您忘记在分类时间内缩放输入图像,如train_test.prototxt文件的第11行所示。 您可能应该在C ++代码中的某个位置乘以该因子,或者使用Caffe图层来缩放输入(请查看ELTWISE或POWER图层)。 编辑: 在评论中进行了一次对话之后,结果发现在classification.cpp文件中错误地删除了图像均值,而在原始训练/测试管道中没有减去图像均值。 I think you have forgotten to scale the input image during cl

xcode语法颜色编码解释?(xcode syntax color coding explained?)

转到: Xcode => Preferences => Fonts & Colors 您将看到每个语法高亮颜色旁边都有一个简短的解释。 Go to: Xcode => Preferences => Fonts & Colors You'll see that each syntax highlighting colour has a brief explanation next to it.

在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)

你考虑过第三方拼写检查吗? 您可以将在C#中开发的自定义WinForms控件插入访问数据库吗? VB6控件怎么样? 如果你能找到一个使用第三方库进行拼写检查的控件,那可能会有效。 Have you considered a third party spell checker? Can you insert a custom WinForms controls developed in C# into an access database? What about a VB6 control? If

从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)

我有同样的问题,因为我在远程服务器上有两个图像,我需要在每天的预定义时间复制到我的本地服务器,这是我能够提出的代码... try { if(@copy('url/to/source/image.ext', 'local/absolute/path/on/server/' . date("d-m-Y") . ".gif")) { } else { $errors = error_get_last(); throw new Exception($err

从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))

我不确定我完全明白你在说什么。 你能编辑你的帖子并包含你正在做的Subversion命令/操作的特定顺序吗? 最好使用命令行svn客户端,以便容易为其他人重现问题。 如果您只是想获取文件的旧副本(即使该文件不再存在),您可以使用如下命令: svn copy ${repo}/trunk/moduleA/file1@${rev} ${repo}/trunk/moduleB/file1 其中${repo}是您的存储库的URL, ${rev}是您想要的文件的版本。 这将恢复该文件的旧版本,包括最高版本